Skip to main content

ApiDeck Python SDK

Lightweight API Usage, Performance & Latency Tracking SDK for Python (FastAPI & Flask)

PyPI version Python versions License

Track API requests, monitor response times, and analyze endpoint performance — effortlessly in Python.


✨ Features

  • ⚡ Zero Blocking Overhead: Dispatches tracking payloads asynchronously in a background daemon thread.
  • 📊 Automatic Latency & Status Tracking: Accurately measures response durations in milliseconds.
  • 🚀 Dual Framework Support: Native integration for FastAPI / Starlette (ASGI) and Flask (WSGI).
  • 🛡️ Fail-Safe: Tracker network drops or timeouts never interrupt or crash your user-facing API routes.
  • 📦 Zero Required Dependencies: Built entirely on top of Python's standard library.

🚀 Installation

Install from PyPI:

pip install apideck-tracker

Or for local development:

pip install -e .

🔑 Get Your API Key

  1. Go to https://apideck.site/ and sign in or create an account.
  2. Go to your dashboard to view your unique apikey.
  3. Use your apikey in your application middleware configuration.

🔧 Quick Start

1. FastAPI / Starlette

from fastapi import FastAPI
from apideck import ApiDeckMiddleware

app = FastAPI()

app.add_middleware(
    ApiDeckMiddleware,
    apikey="YOUR_API_KEY",
    tracker_url="https://apideck.site"  # Optional, defaults to https://apideck.site
)

@app.get("/")
def read_root():
    return {"message": "Hello from FastAPI!"}

2. Flask

from flask import Flask
from apideck import ApiDeck

app = Flask(__name__)

# Basic Initialization
ApiDeck(
    app,
    apikey="YOUR_API_KEY",
    tracker_url="https://apideck.site"  # Optional, defaults to https://apideck.site
)

@app.route("/")
def read_root():
    return {"message": "Hello from Flask!"}

Alternative: Flask Application Factory Pattern

from flask import Flask
from apideck import ApiDeck

tracker = ApiDeck()

def create_app():
    app = Flask(__name__)
    app.config["APIDECK_API_KEY"] = "YOUR_API_KEY"
    app.config["APIDECK_TRACKER_URL"] = "https://apideck.site"

    tracker.init_app(app)
    return app

📖 Configuration Reference

Parameter Type Required Default Description
apikey str Yes — Your unique ApiDeck API key.
tracker_url str No "https://apideck.site" The base URL of your ApiDeck backend.

📊 Tracked Data Payload

Every request processed by the middleware sends the following JSON payload to /api/usage/log:

{
  "apikey": "your_api_key",
  "endpoint": "/api/users",
  "method": "GET",
  "status_code": 200,
  "is_success": true,
  "response_time_ms": 34,
  "ip": "127.0.0.1"
}

🧪 Testing Locally

Check out the included examples in the examples/ directory:

# FastAPI Example
python examples/fastapi_demo.py

# Flask Example
python examples/flask_demo.py

🚢 Publishing to PyPI

When you're ready to publish the SDK to the official Python Package Index:

  1. Install build and twine:

    pip install build twine
    
  2. Build distribution packages:

    python -m build
    
  3. Upload to PyPI:

    python -m twine upload dist/*
    

📄 License

MIT © Aman Kishor

Metadata

Release files for apideck-tracker 1.0.0

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

Source distribution (sdist)

Source distribution for apideck-tracker 1.0.0
File Size Uploaded
apideck_tracker-1.0.0.tar.gz 5.8 kB Details

Built distribution (wheel)

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

Total release size: 12.2 kB

Release files / apideck_tracker-1.0.0.tar.gz

Download URL apideck_tracker-1.0.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
feb8a9dcc5c170895018a9f9357fec35486cd6a711c38d6ed6ab8e7529830a0e
BLAKE2b-256 checksum
How to use checksums
7aa4756dfc04386795c398da23be7f8f7296df29c89aba4e3260f3199970763e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release files / apideck_tracker-1.0.0-py3-none-any.whl

Download URL apideck_tracker-1.0.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46ad8f1b4338df754b20266a487539396afb9e447620d200cdca7bfb5c21d094
BLAKE2b-256 checksum
How to use checksums
a0419fe9a3a969de8288584a268870294f2384b007dde4b709f195cf28c9d617
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

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