Documentation
Docs/Integrations/Python / FastAPI

Python / FastAPI Integration

Observe FastAPI services and any standard Python ASGI/WSGI app.

The NxtOne Python SDK integrates with web servers (FastAPI, Flask, Django) and background queues (Celery) to trace requests and code executions.

1. Install Package

Install the NxtOne SDK using pip:

bash
pip install nxtone

2. Workspace Configuration

Configure the SDK by placing a nxtone.toml file in your project's root folder:

toml
[nxtone] api_key = "nxt_live_abc123" project_id = "user-service"

3. Decorate Main Entry Point

Decorate your main execution function or startup hook with the @nxtone.NxtOneAgent decorator:

python
import nxtone from fastapi import FastAPI app = FastAPI() @app.get("/users") def get_users(): return [{"id": 1, "name": "Alice"}] # Wrap your server startup or application runner @nxtone.NxtOneAgent(session_name="user-service-session") def start_server(): import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000) if __name__ == "__main__": start_server()

4. Running the Agent

Run your script normally, or use the nxtone module execution flag to run it:

bash
python3 -m nxtone main.py
Automatic Middleware Detection: When running inside a FastAPI application, the NxtOne agent automatically registers an ASGI middleware wrapper to intercept incoming HTTP headers and map active execution spans.
On This Page
What is NxtOne?Key FeaturesQuick StartInstall the agentAnnotate your applicationConfigure API keyConfiguration ReferenceAPI ExampleSupported StackLanguages & FrameworksNext Steps