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

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", env="dev")

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:

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 initialize Apitally for your application:

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 initialize Apitally for your application:

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 the Apitally plugin to your application:

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 initialize Apitally for your application:

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

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

By default, Apitally captures response headers but not request headers or request and response bodies. You can opt in with parameters:

apitally.init(
    app,
    write_token="your-write-token",
    env="dev",
    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 logs and traces 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. Use mask_log_record to transform or drop Apitally's captured copy, 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:

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.

Existing OpenTelemetry setup

If your app already uses an OpenTelemetry SDK tracer provider, configure it before initializing Apitally. Apitally automatically adds its span processor to your provider, keeping your existing exporters.

Your provider's sampling settings also affect Apitally. Requests dropped by the sampler will not have request logs or traces in Apitally. Metrics still include all requests, regardless of sampling.

Trusted proxies

If your application runs behind a reverse proxy or load balancer, configure trusted proxies in your framework so Apitally can record the real client IP for GeoIP. Apitally uses the client IP reported by your framework. It does not read forwarding headers itself to determine the client IP.

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.

Release files for apitally 1.0.0b3

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.0b3
File Size Uploaded
apitally-1.0.0b3.tar.gz 54.8 kB Details

Built distribution (wheel)

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

Total release size: 126.2 kB

Release files / apitally-1.0.0b3.tar.gz

Download URL apitally-1.0.0b3.tar.gz
Size 54.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9d8a035a6db63847e29cb24663b9e6e8cc14d364ee559f6296dfc5dc93779544
BLAKE2b-256 checksum
How to use checksums
d1c7809a5286dc006311fb791c3320671aa041871c0d6174ddd3c7af2dacff4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","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.0b3-py3-none-any.whl

Download URL apitally-1.0.0b3-py3-none-any.whl
Size 71.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31322ec8665531af5aa6f38242a1a4b1570f35dcb58290d74437c515db6e8bfa
BLAKE2b-256 checksum
How to use checksums
199f0876337d1f7c7a8565a79ef7bb0dd80878502a445dd04991fb7a26fd6583
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","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 history Release notifications | RSS feed

This release

1.0.0b3 This release

2 release files

0.25.1

2 release files

0.24.4

2 release files

0.24.3

2 release files

0.24.1

2 release files

0.24.0

2 release files

0.23.0

2 release files

0.22.3

2 release files

0.22.0

2 release files

0.21.4

2 release files

0.21.2

2 release files

0.21.1

2 release files

0.21.0

2 release files

0.20.3

2 release files

0.20.2

2 release files

0.20.0

2 release files

0.19.1

2 release files

0.19.0

2 release files

0.18.2

2 release files

0.18.1

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.16.1

2 release files

0.16.0

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.5

2 release files

0.14.2

2 release files

0.14.1

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.11.3

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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