Python SDK
Flask, FastAPI, Django, and Starlette-compatible ASGI apps.
Add Nolax to a Flask, FastAPI or Django app with a few lines. Install only the extras you need.
Package: nolax-sdk 1.1
Ingest contract: v1.1
Supported frameworks
| Framework | Status |
|---|---|
| Flask | Supported |
| FastAPI | Supported |
| Django | Supported |
| Starlette (bare) | Supported |
Install
pip install "nolax-sdk[flask]"Flask example
import os
from flask import Flask
from nolax import NolaxFlask
app = Flask(__name__)
nolax = NolaxFlask(api_key=os.environ['NOLAX_API_KEY'], environment='production')
nolax.init_app(app)
FastAPI example
from fastapi import FastAPI
from nolax import NolaxFastAPI
app = FastAPI()
app.add_middleware(NolaxFastAPI, api_key=os.environ['NOLAX_API_KEY'], environment='production')
app.add_middleware(...). Do not instantiate the class yourself.Django example
Add the middleware to settings.py and set the key and environment. Every other option is a setting named NOLAX_ plus the option name in capitals.
# settings.py
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
# ... other middleware ...
"nolax.middleware.NolaxDjango",
]
NOLAX_API_KEY = os.environ.get("NOLAX_API_KEY")
NOLAX_ENVIRONMENT = "production"
# Optional
NOLAX_BATCH_SIZE = 100
NOLAX_FLUSH_INTERVAL_MS = 2000
The Django middleware works from SDK 1.1. Earlier versions could not start it.
Config options
Flask and FastAPI take these as keyword arguments. Django reads them from settings.
| Option | Type | Default | Notes |
|---|---|---|---|
| api_key | str | required | Project API key |
| environment | str | required | development, staging or production |
| endpoint | str | https://server.nolax.net/ingest | Ingest URL, for local testing |
| batch_size | int | 100 | Events that trigger a flush |
| flush_interval_ms | int | 2000 | Milliseconds between timed flushes |
| max_queue_size | int | 10000 | Events held in memory. The oldest are dropped first |
| max_in_flight | int | 4 | Accepted for parity with the other SDKs. Python sends from one thread |
| release | str | None | Release identifier, up to 64 characters |
| service | str | None | Service name, up to 64 characters |
| consumer | callable | None | Takes the request, returns a consumer identifier |
| capture_ip | bool | True | Send the client IP address |
| capture_user_agent | bool | True | Send the User-Agent header |
| ip_header | str | None | Header that holds the client IP behind a proxy, for example x-forwarded-for |
| ignore_paths | list | [] | Strings or compiled patterns. Matching requests are never recorded |
| ignore_methods | list | [] | Methods that are never recorded |
| before_send | callable | None | Change an event, or return None to drop it |
| dry_run | bool | False | Log each batch with the key masked and send nothing. Also NOLAX_DRY_RUN=1 |
| debug | bool | False | Verbose logging through the nolax logger |
| on_error | callable | None | Called when a batch is dropped |
Flushing on shutdown
Call flush() on the Flask or FastAPI integration object to send queued events before the process exits. The SDK also flushes when the interpreter shuts down. It restarts its timer in worker processes created by fork, so Gunicorn and uWSGI workers keep sending.
Troubleshooting
- No events in FastAPI: call
app.add_middleware(...)before the first request arrives. - No events in Django: check that
NOLAX_API_KEY,NOLAX_ENVIRONMENTand the middleware are insettings.py. payloadSizeis 0 when the response has noContent-Lengthheader.ipshows your proxy: setip_headertox-forwarded-for, and make sure only your proxy can set that header.
See also Batching and Retries and What the SDK Sends.

