Skip to main content

observe. — Python SDK

The Python SDK for observe. Track server-side events, capture exceptions, and monitor API performance from any Python application.

Features

  • Custom event tracking
  • Exception capture with full stack traces
  • User identification
  • Fire and forget — sends in background threads, never blocks your app
  • Works with FastAPI, Django, Flask, or plain Python

Installation

pip install observe-sdk

Until published to PyPI, copy src/tracker.py into your project directly.

Quick start

from tracker import Tracker

tracker = Tracker(
    api_key="obs_your_secret_key",
    server_url="https://api.observe.dev",
)

# track an event
tracker.track(
    event_name="order_placed",
    anonymous_id="anon_abc123",
    properties={"plan": "pro"},
)

# capture an exception
try:
    process_payment()
except Exception as e:
    tracker.capture_exception(e, extra={"user_id": "user_123"})

Framework guides

FastAPI

Add the middleware to automatically track all requests:

# main.py
from fastapi import FastAPI, Request
from tracker import Tracker
import time

app = FastAPI()

tracker = Tracker(
    api_key="obs_your_secret_key",
    server_url="https://api.observe.dev",
)

@app.middleware("http")
async def track_requests(request: Request, call_next):
    start = time.time()
    try:
        response = await call_next(request)
        duration_ms = round((time.time() - start) * 1000)
        tracker.track(
            event_name="api_request",
            anonymous_id="server",
            properties={
                "method": request.method,
                "path": request.url.path,
                "status_code": response.status_code,
                "duration_ms": duration_ms,
            },
        )
        return response
    except Exception as e:
        tracker.capture_exception(e, extra={"path": request.url.path})
        raise

Django

Create a middleware file and add it to settings.py:

# observe_middleware.py
import time
from tracker import Tracker

tracker = Tracker(
    api_key="obs_your_secret_key",
    server_url="https://api.observe.dev",
)

class ObserveMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        start = time.time()
        response = self.get_response(request)
        duration_ms = round((time.time() - start) * 1000)

        tracker.track(
            event_name="api_request",
            anonymous_id=str(request.user.id) if request.user.is_authenticated else "anon",
            properties={
                "method": request.method,
                "path": request.path,
                "status_code": response.status_code,
                "duration_ms": duration_ms,
            },
        )
        return response

    def process_exception(self, request, exception):
        tracker.capture_exception(exception, extra={
            "path": request.path,
            "method": request.method,
        })
# settings.py
MIDDLEWARE = [
    # ... existing middleware
    "yourapp.observe_middleware.ObserveMiddleware",
]

API reference

Tracker(api_key, server_url)

Parameter Type Required Description
api_key str Yes Your project secret key
server_url str Yes Your observe. server URL

tracker.track(event_name, anonymous_id, properties?)

Parameter Type Required Description
event_name str Yes Name of the event
anonymous_id str Yes Session or visitor ID
properties dict No Any additional data

tracker.identify(anonymous_id, user_id)

Parameter Type Required Description
anonymous_id str Yes Current session ID
user_id str Yes Your user's ID

tracker.capture_exception(exception, anonymous_id?, extra?)

Parameter Type Required Description
exception Exception Yes The caught exception
anonymous_id str No Defaults to "server"
extra dict No Any additional context

Development

git clone https://github.com/yourname/observability-python-sdk.git
cd observability-python-sdk
pip install httpx

# run the example
python examples/basic.py

License

MIT

Metadata

Release files for observe-sdk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for observe-sdk 0.1.0
File Size Uploaded Provenance Actions
observe_sdk-0.1.0.tar.gz 3.6 kB Without provenance Details for observe_sdk-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for observe-sdk 0.1.0
File Interpreter ABI Platform Actions
observe_sdk-0.1.0-py3-none-any.whl Python 3 none any Details for observe_sdk-0.1.0-py3-none-any.whl

Total release size: 7.2 kB

Release files / observe_sdk-0.1.0.tar.gz

Download URL observe_sdk-0.1.0.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
17cf681a8396090a7c15926d88beb590829f1ecd5eb17f96d99b01b7f8d58195
BLAKE2b-256 checksum
How to use checksums
2aabe7230ad234b9262d3c67189e32ef449dd30d4e20a54657c29ee79acd377b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / observe_sdk-0.1.0-py3-none-any.whl

Download URL observe_sdk-0.1.0-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
faaf9a3cf8231d331ab7bce984e92a34acb6a8b66e546e144194f5f2b38ebb8c
BLAKE2b-256 checksum
How to use checksums
18680aab085bb37e8d0bf86a562888f3641578202199536ba0f472bc0cc21919
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for observe-sdk 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page