Skip to main content

Django profiling middleware CLI tool

Project description


🌀 API Profiler

A plug-and-play Django middleware profiler that tracks API performance, SQL query behavior, and more — all without code changes or server restarts.

Perfect for developers who want real-time insight into their API behavior during development.


✨ Features

  • ✅ Profiles total request execution time
  • ✅ Logs detailed SQL queries per request
  • Detects N+1 issues with repeated query tracking
  • ✅ Beautiful, structured console logs (headers, body, SQL, etc.)
  • No code changes — injects middleware at runtime
  • ✅ Global CLI-based usage via profile run

📦 Installation

Once published:

pip install api-profiler

For local development (from repo root):

pip install dist/api_profiler-0.1.0-py3-none-any.whl

Or install in editable mode:

pip install -e .

🚀 Usage

From your Django project folder, use the CLI to control profiling:

Step 1: Start Django with profiling

profile run

Step 2: In another terminal, toggle profiling live

# Activate all metrics
profile --set all

# Deactivate all
profile --unset all

# Enable specific profiling
profile --set sql response-headers

# Disable specific profiling
profile --unset sql response-body

⚡ This works on the live running server — no restart required.


🧠 What It Profiles

Metric Description
sql Query count, total time, repeated queries
headers Request and response headers
params / body URL params and request body
response Response content and size
response-headers Response headers
all Enables or disables all of the above

📊 Sample Output

[INFO] METHOD: GET     PATH: /users/
[INFO] Headers:
    Content-Type: text/plain
    Host: 127.0.0.1:8000
    ...
[INFO] Body: Size: 0 bytes
--------------------------------------------------------------------------------
SQL Queries Summary
Path     : /users/
Total    : 10 queries
[001]
SELECT ... FROM auth_user
       Repeated: 10x | Total Time: 0.000 sec

Total Execution Time: 0.000 sec
--------------------------------------------------------------------------------
[INFO] Response: [] Size: 2 bytes
[INFO] Status: 200 Total time taken: 0.005 seconds

🛠️ How It Works

  • 🧩 Middleware Injection: Runtime patching (no settings.py modification)
  • 📡 Live Toggle: CLI commands modify profiling behavior in real time
  • ⚙️ Auto Project Detection: Automatically detects Django apps in the current directory
  • 📋 Clean Logging: Powered by logging.config.dictConfig

🔧 Developer Setup

git clone https://github.com/Av-sek/api-profiler.git
cd api_profiler
pip install -e .

# OR build and install from source
pip install --upgrade build
python -m build
pip install dist/api_profiler-0.1.0-py3-none-any.whl

To use on your Django app:

profile run

👤 Author

Abhishek Ghorashainee 🔗 GitHub · 🔗 LinkedIn


📄 License

MIT License — open to all contributions.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

api_profiler-0.1.5.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

api_profiler-0.1.5-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file api_profiler-0.1.5.tar.gz.

File metadata

  • Download URL: api_profiler-0.1.5.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for api_profiler-0.1.5.tar.gz
Algorithm Hash digest
SHA256 def80f120dd54c3b44d9e4bfac5a4e2958aebe6909763faca62d4357871edb68
MD5 203bd1138f7469fa33ea2d0424babe18
BLAKE2b-256 1439d8637effa5f6e7f69945aa28145f252567f241c69b99556a123a472e0f42

See more details on using hashes here.

File details

Details for the file api_profiler-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: api_profiler-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for api_profiler-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8a2d293968511b6ec9df6522ebdbec8e0f2454d769f21833aa02b2d86c6468c6
MD5 4368c2661dfc12f14a5258697f3ad5f4
BLAKE2b-256 c79cbe88659c375edcb923a00944e0da3bf15ae2d67c2f98fdf857c9b1cccdab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page