Python SDK
Python SDK
The Python SDK calls the WatchTower15 API, counts what your application does as custom metrics and ships its logs to
log ingest, from one Client (or one AsyncClient). It builds, retries and batches the calls for you, and turns every failure into a
typed exception. It is typed (py.typed), checked with pyright in strict mode, and its one dependency is httpx2. It needs Python 3.11 or later.
What it covers
Section titled “What it covers”- The REST API. Every
/v1operation is a method on a resource:client.servers.list(),client.scans.view(uuid). See the REST API. - Custom metrics. Push points, or count in the request path with the aggregator and let a thread send them once a minute. See custom metrics.
- Logs. A
logginghandler, which also serves structlog and loguru, that sends lines to log ingest. See logs. - Frameworks. Django, FastAPI, Flask and Celery integrations, and the recipes for gunicorn, uWSGI and AWS Lambda. See servers, workers and serverless.
What to install
Section titled “What to install”| You use | Install | Page |
|---|---|---|
| Anything | pip install watchtower15 |
this page |
| Django 5.2 or 6 | pip install "watchtower15[django]" |
Django |
| FastAPI | pip install "watchtower15[fastapi]" |
FastAPI |
| Flask 3 | pip install "watchtower15[flask]" |
Flask |
| Celery 5 | pip install "watchtower15[celery]" |
Celery |
An extra only makes pip check the framework’s version range; the integration is part of the one distribution, which is released at one version. Gunicorn, uWSGI, structlog, loguru and AWS Lambda need no extra: see servers, workers and serverless and logs.
from watchtower15 import Client
client = Client.from_environment(app_info="billing/2.4.1")me = client.me()for server in client.servers.list(limit=100): print(server.name, server.health_status)from watchtower15 import AsyncClient
async with AsyncClient.from_environment() as client: async for server in client.servers.list(limit=100): print(server.name)The three credentials
Section titled “The three credentials”| Credential | Variable | Used for | Created |
|---|---|---|---|
API key (wt15ak_…) |
WT15_API_KEY |
the REST API | in the console, under your account’s API keys |
Metric source token (wt15ms_…) |
WT15_METRICS_TOKEN |
custom metrics | when you create a metric source |
Log source token (wt15ls_…) |
WT15_LOGS_TOKEN |
logs | when you create a log source |
The SDK checks each credential’s shape locally and refuses one in the wrong slot, naming what it is. On a host that runs the WatchTower15 agent, tailing the log file with the agent is the better log path: the agent reads the file with no code in your application.
To check what a machine is configured with, run python -m watchtower15 test (or watchtower15 test): it calls me() with the API key, lists the metric source with the metrics token, checks the
logs token’s format, and compares the clock with the server’s. --reachability needs no credential and --json prints the verdicts as JSON. It exits 0 when every check passed, 1 when one failed
and 2 when nothing is configured.
Support
Section titled “Support”- Python. Every Python minor from 3.11 is supported until its own end of life (3.11’s is October 2027). Dropping one is a minor release, announced in the release before it. A new minor joins the tested matrix by its general availability. The free-threaded build is tested from 3.14.
- Frameworks. Django 5.2 LTS and 6.x; FastAPI 0.133 and later on Starlette 1.0; Flask 3; Celery 5 from 5.3.1. A version is dropped in the first minor release after its own support ends; a new major joins in a minor release.
- Versions. Semantic Versioning, independent of the API’s
v1: a new API operation is a minor release, a change to the SDK’s own signatures or types a major one, and a generated name never changes. - Typing.
py.typed, checked in pyright’s strict mode, the integrations included. - Security fixes ship in the newest minor as a patch release at once.
| Cell | Python | Line |
|---|---|---|
| core | 3.11 (httpx2 at its floor) and 3.15 | the unit suite and the conformance suite |
| core, free-threaded | 3.14t | the free-threaded recipe |
[django] |
3.11 and 3.15 | Django 5.2 and Django 6 |
[fastapi] |
3.11 and 3.15 | FastAPI 0.133 with Starlette 1.0.0, and the newest |
[flask] |
3.11 and 3.15 | Flask 3.0.0 and the newest |
[celery] |
3.11 and 3.15 | Celery 5.3.1 and the newest |
| recipes | 3.15 | structlog, loguru, gunicorn |