Metadata-Version: 2.4
Name: apideck-tracker
Version: 1.0.0
Summary: Lightweight API usage, performance, and latency tracking middleware for Python (FastAPI, Flask).
Author-email: Aman Kishor <kishoraman2121@gmail.com>
License: MIT
Project-URL: Homepage, https://apideck.site
Project-URL: Repository, https://github.com/kishoraman21/ApiDeck
Keywords: apideck,api-tracker,analytics,middleware,fastapi,flask,starlette,monitoring,performance
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Provides-Extra: fastapi
Requires-Dist: fastapi; extra == "fastapi"
Requires-Dist: starlette; extra == "fastapi"
Provides-Extra: flask
Requires-Dist: flask; extra == "flask"
Provides-Extra: all
Requires-Dist: fastapi; extra == "all"
Requires-Dist: starlette; extra == "all"
Requires-Dist: flask; extra == "all"

<div align="center">

# ApiDeck Python SDK

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

<p align="center">
  <a href="https://pypi.org/project/apideck-tracker/">
    <img src="https://img.shields.io/pypi/v/apideck-tracker?style=flat-square&color=00BFFF" alt="PyPI version"/>
  </a>
  <a href="https://pypi.org/project/apideck-tracker/">
    <img src="https://img.shields.io/pypi/pyversions/apideck-tracker?style=flat-square&color=1E90FF" alt="Python versions"/>
  </a>
  <a href="./LICENSE">
    <img src="https://img.shields.io/badge/License-MIT-32CD32?style=flat-square" alt="License"/>
  </a>
</p>

<p align="center">
  Track API requests, monitor response times, and analyze endpoint performance — effortlessly in Python.
</p>

</div>

---

## ✨ 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:

```bash
pip install apideck-tracker
```

Or for local development:

```bash
pip install -e .
```

---

## 🔑 Get Your API Key

1. Go to [https://apideck.site/](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

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

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

```python
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`:

```json
{
  "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/](file:///c:/Users/pk266/OneDrive/Desktop/web%20projects/ApiDeck-main/apiDeck-sdk-python/examples) directory:

```bash
# 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:**
   ```bash
   pip install build twine
   ```

2. **Build distribution packages:**
   ```bash
   python -m build
   ```

3. **Upload to PyPI:**
   ```bash
   python -m twine upload dist/*
   ```

---

## 📄 License

MIT © [Aman Kishor](https://github.com/kishoraman21)
