Lightweight observability SDK for Python
Project description
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.pyinto 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file observe_sdk-0.1.0.tar.gz.
File metadata
- Download URL: observe_sdk-0.1.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17cf681a8396090a7c15926d88beb590829f1ecd5eb17f96d99b01b7f8d58195
|
|
| MD5 |
36f5737d36cc40d15608b58b0484448b
|
|
| BLAKE2b-256 |
2aabe7230ad234b9262d3c67189e32ef449dd30d4e20a54657c29ee79acd377b
|
File details
Details for the file observe_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: observe_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
faaf9a3cf8231d331ab7bce984e92a34acb6a8b66e546e144194f5f2b38ebb8c
|
|
| MD5 |
588240f2e0cedacc4b7778e1db50f61c
|
|
| BLAKE2b-256 |
18680aab085bb37e8d0bf86a562888f3641578202199536ba0f472bc0cc21919
|