Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Apitally logo

API monitoring & analytics made simple

Metrics, logs, traces, and alerts for your APIs — with just a few lines of code.


Apitally dashboard


Apitally SDK for Python

Tests Codecov PyPI

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 few lines of code. No infrastructure changes required, no dashboards to build.

The SDK is an OpenTelemetry distribution and works alongside an existing OpenTelemetry setup.

Learn more about Apitally on our 🌎 website or check out the 📚 documentation.

Key features

  • API analytics: Traffic, error and performance metrics for your API, each endpoint, and per API consumer. Drill down from metrics to individual API requests.
  • Request logs and traces: Every request as a searchable log entry, with optional capture of headers and request/response bodies. Requests are exported as OpenTelemetry spans, including spans from any other instrumentations you have.
  • Application logs: Logs written via the standard logging module and Loguru are captured automatically and correlated with the requests they belong to.
  • Error tracking: Validation errors and exceptions with stack traces for server errors, automatically linked to Sentry events if you use Sentry.
  • Server metrics: CPU and memory usage of your app's processes.
  • API monitoring & alerts: Get notified 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

The SDK supports Python >= 3.10.

Framework Supported versions Setup guide
FastAPI * >=0.108.0 Link
Django REST Framework >=3.12.0 Link
Django Ninja >=1.0.0 Link
Flask >=2.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 and .NET 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.

FastAPI

Install the SDK with the fastapi extra:

pip install "apitally[fastapi]"

Then call apitally.init() right after creating the app:

import apitally
from fastapi import FastAPI

app = FastAPI()
apitally.init(app, write_token="your-write-token", env="dev")

For further instructions, see our setup guide for FastAPI.

Django

Install the SDK with the django extra:

pip install "apitally[django]"

Then call apitally.init() at the end of your settings.py module, after MIDDLEWARE is defined:

# settings.py
import apitally

MIDDLEWARE = [
    # Your middleware ...
]

# ... at the very end of the file:
apitally.init(write_token="your-write-token", env="dev")

For further instructions, see our setup guide for Django.

Flask

Install the SDK with the flask extra:

pip install "apitally[flask]"

Then call apitally.init() after creating the app and after wrapping app.wsgi_app with any WSGI middleware:

import apitally
from flask import Flask

app = Flask(__name__)
apitally.init(app, write_token="your-write-token", env="dev")

For further instructions, see our setup guide for Flask.

Starlette

Install the SDK with the starlette extra:

pip install "apitally[starlette]"

Then call apitally.init() right after creating the app:

import apitally
from starlette.applications import Starlette

app = Starlette(routes=[...])
apitally.init(app, write_token="your-write-token", env="dev")

For further instructions, see our setup guide for Starlette.

Litestar

Install the SDK with the litestar extra:

pip install "apitally[litestar]"

Then add ApitallyPlugin to your app's plugins:

from litestar import Litestar
from apitally.litestar import ApitallyPlugin

app = Litestar(
    route_handlers=[...],
    plugins=[ApitallyPlugin(write_token="your-write-token", env="dev")],
)

For further instructions, see our setup guide for Litestar.

BlackSheep

Install the SDK with the blacksheep extra:

pip install "apitally[blacksheep]"

Then call apitally.init() right after creating the app:

import apitally
from blacksheep import Application

app = Application()
apitally.init(app, write_token="your-write-token", env="dev")

For further instructions, see our setup guide for BlackSheep.

Configuration

Pass configuration options as keyword arguments to apitally.init(), or to ApitallyPlugin for Litestar. See the SDK reference for all available options.

Environment variables

To keep configuration out of your code, set these environment variables instead of passing the matching arguments:

  • APITALLY_WRITE_TOKEN: the write token (write_token)
  • APITALLY_ENV: the environment name (env), defaults to dev
  • APITALLY_DISABLED: set to true to disable Apitally (disabled)

Request and response data

Apitally captures response headers by default. To also capture request headers and request and response bodies, pass these arguments:

apitally.init(
    app,
    write_token="your-write-token",
    env="dev",
    capture_request_headers=True,
    capture_request_body=True,
    capture_response_body=True,
)

Apitally automatically masks common sensitive values, such as password fields and the Authorization header. To mask additional values, pass regular expressions to mask_query_params, mask_headers, and mask_body_fields. See our documentation on masking for details.

Exclusions and sampling

Apitally automatically excludes common health checks and static assets, such as /healthz and /robots.txt, from logs and traces. To exclude additional paths, pass regular expressions to exclude_paths.

To capture logs and traces for only a fraction of the remaining requests, set sample_rate, for example to 0.1 for 10%. To decide for each request individually, pass a callback to sample_on_request or sample_on_response.

Metrics always include all requests. See our documentation on sampling for details.

Application logs

Apitally captures logs written with the standard logging module and Loguru, and correlates them with the requests they belong to. To mask or drop individual log records, pass a callback to mask_log_record. To turn off log capture, set capture_logs=False.

See our documentation on masking for details.

Adding context to requests

The following functions add context to the current request. Call them while handling a request, for example in an endpoint, middleware, or authentication code.

Consumers

To associate the request with the API consumer making it, call set_consumer. Only the identifier is required.

apitally.set_consumer(
    user.identifier,
    name=user.name,
    group=user.group,
    attributes={"plan": user.plan},
)

Custom attributes

To attach custom data to the request's trace, call set_request_attribute. The sample_on_response, mask_request_body, and mask_response_body callbacks can also read these attributes.

apitally.set_request_attribute("tenant.id", tenant_id)

See our documentation on attributes for details.

Handled exceptions

To capture an exception that your code handles itself, call capture_exception. Unhandled exceptions are captured automatically.

try:
    process_order()
except Exception as exc:
    apitally.capture_exception(exc)

Existing OpenTelemetry setup

If your app already uses OpenTelemetry, set up your tracer provider and any framework instrumentation, such as FastAPIInstrumentor, before initializing Apitally. Apitally adds its span processor to your tracer provider and keeps your existing exporters.

Your tracer provider's sampler also applies to Apitally. Requests it drops have no request logs or traces in Apitally, but still count in metrics.

Trusted proxies

If your app runs behind a reverse proxy or load balancer, configure trusted proxies in your server or framework, for example with Uvicorn's --forwarded-allow-ips option or Werkzeug's ProxyFix middleware. Apitally records the client IP your framework reports and uses it for GeoIP.

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.

Metadata

Release files for apitally 1.0.0b9

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

Source distribution (sdist)

Source distribution for apitally 1.0.0b9
File Size Uploaded Provenance
apitally-1.0.0b9.tar.gz 61.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for apitally 1.0.0b9
File Interpreter ABI Platform
apitally-1.0.0b9-py3-none-any.whl Python 3 none any Details

Total release size: 140.6 kB

Release files / apitally-1.0.0b9.tar.gz

Download URL apitally-1.0.0b9.tar.gz
Size 61.4 kB
Tags Source
SHA-256 checksum
How to use checksums
03b27d3db92ed41964f75bfde472d458160ab5f4d716f23ea41510613a62ff08
BLAKE2b-256 checksum
How to use checksums
a870fb967cbde8570c0be559047b97123ead0c464e201e8499d5134c9085b772
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}

Release files / apitally-1.0.0b9-py3-none-any.whl

Download URL apitally-1.0.0b9-py3-none-any.whl
Size 79.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3018aa04dcaf9e59a9c1465df512ad37f92b24b1071d0dcfe642d950ceede11
BLAKE2b-256 checksum
How to use checksums
528d2a2a89a8bd55c32498c8eb9eec36bbbb90e1b186816efd41786e58df2d74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}

Security for apitally 1.0.0b9

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
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