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.pymodification) - 📡 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file api_profiler-0.1.6.tar.gz.
File metadata
- Download URL: api_profiler-0.1.6.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df8122581c7836d4d94231ca9f9b7673f859ab5f075a224feec1618083770169
|
|
| MD5 |
b59a2722e85f3a75bfc243aac30e86ad
|
|
| BLAKE2b-256 |
06e0e8e72e2a31e39e8fe9cde6bbf0cbb2763b732848560cc11a94ef38bc2187
|
File details
Details for the file api_profiler-0.1.6-py3-none-any.whl.
File metadata
- Download URL: api_profiler-0.1.6-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11fd9d8fed2cc39c9573e7a5bbbfce9059ad8af4ce058140cc12741784428aa2
|
|
| MD5 |
3b4242103c0cea854e06a4c2402c5fb3
|
|
| BLAKE2b-256 |
69b73e531b0d9eb68f84ff13ee83ed01cbe0f3b7a4cee6f5f45842b7bf43dc95
|