Simple API monitoring & analytics for REST APIs built with FastAPI, Flask, Django, Starlette, Litestar and BlackSheep.
Project description
API monitoring & analytics made simple
Metrics, logs, traces, and alerts for your APIs, with just one line of code.
Apitally SDK for Python
Apitally is a simple API monitoring and analytics tool that makes it easy to understand API usage, monitor performance, and troubleshoot issues. Get started in minutes by just adding a line of code. No infrastructure changes required, no dashboards to build.
The SDK is an OpenTelemetry distribution: it builds on the community OTel instrumentations for each framework and works alongside an existing OpenTelemetry setup if you have one.
Learn more about Apitally on our 🌎 website or check out the 📚 documentation.
[!IMPORTANT] Upgrading from 0.x? Version 1.0 is a full rewrite with a new setup API. See the migration guide for a full 0.x to 1.x mapping.
Key features
API analytics
Track traffic, error and performance metrics for your API, each endpoint and individual API consumers, allowing you to make informed, data-driven engineering and product decisions.
Request logs
Drill down from insights to individual API requests or use powerful search and filters to find specific requests. View correlated application logs and traces for a complete picture of each request, making troubleshooting faster and easier.
Error tracking
Understand which validation rules in your endpoints cause client errors. Capture error details and stack traces for 500 error responses, and have them linked to Sentry issues automatically.
API monitoring & alerts
Get notified immediately if something isn't right using custom alerts, synthetic uptime checks and heartbeat monitoring. Alert notifications can be delivered via email, Slack and Microsoft Teams.
Supported frameworks
| Framework | Supported versions | Setup guide |
|---|---|---|
| FastAPI * | >=0.108.0 |
Link |
| Flask | >=2.0.0 |
Link |
| Django | >=3.2 |
Link |
| Django REST Framework | >=3.12.0 |
Link |
| Django Ninja | >=1.0.0 |
Link |
| Starlette | >=0.29.0 |
Link |
| Litestar | >=2.24.0 |
Link |
| BlackSheep | >=2.6.1 |
Link |
* For FastAPI on Cloudflare Workers use our Python Serverless SDK instead.
Apitally also supports many other web frameworks in JavaScript, Go, .NET and Java via our other SDKs.
Getting started
If you don't have an Apitally account yet, first sign up here. Then create an app in the Apitally dashboard. You'll see detailed setup instructions with code snippets you can copy and paste. These also include your write token.
Setup is a single call to apitally.init, which detects your framework from the app instance:
import apitally
apitally.init(app, write_token="your-write-token")
Django apps call apitally.init() without an app argument at the end of settings.py, and Litestar apps use ApitallyPlugin instead. See the framework sections below for details.
See the SDK reference for all available configuration options, including how to mask sensitive data, capture request and response payloads, and more.
FastAPI
Install the SDK with the fastapi extra, which also pulls in the OpenTelemetry instrumentation for FastAPI:
pip install "apitally[fastapi]"
Then initialize Apitally for your application:
import apitally
from fastapi import FastAPI
app = FastAPI()
apitally.init(app, write_token="your-write-token")
For further instructions, see our setup guide for FastAPI.
Django
Install the SDK with the django extra, which also pulls in the OpenTelemetry instrumentation for Django. The same extra covers plain Django, Django REST Framework and Django Ninja:
pip install "apitally[django]"
Then call apitally.init() at the end of your settings.py module. The placement matters: it must run after MIDDLEWARE is defined, as Apitally inserts its own middleware automatically.
# settings.py
import apitally
MIDDLEWARE = [
# Your middleware ...
]
# ... at the very end of the file:
apitally.init(write_token="your-write-token")
For further instructions, see our setup guide for Django.
Flask
Install the SDK with the flask extra:
pip install "apitally[flask]"
Then initialize Apitally for your application:
import apitally
from flask import Flask
app = Flask(__name__)
apitally.init(app, write_token="your-write-token")
For further instructions, see our setup guide for Flask.
Starlette
Install the SDK with the starlette extra:
pip install "apitally[starlette]"
Then initialize Apitally for your application:
import apitally
from starlette.applications import Starlette
app = Starlette(routes=[...])
apitally.init(app, write_token="your-write-token")
For further instructions, see our setup guide for Starlette.
Litestar
Install the SDK with the litestar extra:
pip install "apitally[litestar]"
Litestar plugins must be passed at construction, so setup uses ApitallyPlugin instead of apitally.init:
from litestar import Litestar
from apitally.litestar import ApitallyPlugin
app = Litestar(
route_handlers=[...],
plugins=[ApitallyPlugin(write_token="your-write-token")],
)
For further instructions, see our setup guide for Litestar.
BlackSheep
Install the SDK with the blacksheep extra:
pip install "apitally[blacksheep]"
Then initialize Apitally for your application:
import apitally
from blacksheep import Application
app = Application()
apitally.init(app, write_token="your-write-token")
For further instructions, see our setup guide for BlackSheep.
Configuration
The write token and environment can also be provided via the APITALLY_WRITE_TOKEN and APITALLY_ENV environment variables instead of the write_token and env arguments. The environment defaults to prod.
Out of the box, Apitally captures metrics, request logs, traces, exceptions, application logs, and response headers. Request headers and request and response bodies are not captured by default. You can opt in with parameters:
apitally.init(
app,
write_token="your-write-token",
capture_request_headers=True,
capture_request_body=True,
capture_response_body=True,
)
Sensitive values in query parameters, headers, and body fields are masked automatically based on built-in patterns, and you can add your own via the mask_query_params, mask_headers, and mask_body_fields arguments.
On high-traffic applications you can capture traces and logs for only a fraction of requests by setting sample_rate (e.g. 0.1 for 10%), or decide per request with the sample_on_request and sample_on_response callbacks. Metrics always count every request, regardless of sampling.
Application logs written via the standard logging module are captured and correlated with requests by default. Log messages are exported as-is, so if your application logs sensitive data, sanitize it at the source or opt out with capture_logs=False.
See the SDK reference for all configuration options.
Identifying consumers and more
The top-level apitally package provides functions you can call from anywhere in your request handling code, for example from your authentication middleware or dependencies:
import apitally
# Associate the current request with an API consumer
apitally.set_consumer(user.identifier, name=user.name, group=user.group)
# Attach a custom attribute to the current request
apitally.set_request_attribute("tenant", tenant_id)
# Capture a handled exception for the current request
apitally.capture_exception(exc)
For further details, check out our documentation.
Getting help
If you need help please create a new discussion on GitHub or email us at support@apitally.io. We'll get back to you as soon as possible.
License
This library is licensed under the terms of the MIT license.
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 apitally-1.0.0a1.tar.gz.
File metadata
- Download URL: apitally-1.0.0a1.tar.gz
- Upload date:
- Size: 46.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a635bc17983693b87acd21a672c20fd594514397c35b92a69ffbe19f4a9d3099
|
|
| MD5 |
088ff29ecd656ed944db072e6c9c13e1
|
|
| BLAKE2b-256 |
3f7fb40f4216cfe9384afea0b6697b4eabcd4915f0c8b7be4a887479ba2770d2
|
File details
Details for the file apitally-1.0.0a1-py3-none-any.whl.
File metadata
- Download URL: apitally-1.0.0a1-py3-none-any.whl
- Upload date:
- Size: 62.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b44b72f2039079e8f5356312d56abd328ef922b31b20fb0f0b9b50636801cb6
|
|
| MD5 |
6cb477475e29f9463b8d23e6310fee53
|
|
| BLAKE2b-256 |
b741f657214a808c6a8a702d5526ee680fae83d2e20757ca5c05dc69252d793c
|