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.7.tar.gz (11.9 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.7-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: api_profiler-0.1.7.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

Hashes for api_profiler-0.1.7.tar.gz
Algorithm Hash digest
SHA256 a6536f6bae99929409f8e855ce3567d49908cb75bc0d020ac5364dac12a3b4c9
MD5 864e08338e8467e8675ff647aeb2bdea
BLAKE2b-256 bb133e311e33d79ac76cdd0ceb091e847f3ba8623224ee5d97a210d9d32cb8bb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: api_profiler-0.1.7-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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 21225f38383880814443c247f3ce113d64650dfc971094910da264962a4ddfd5
MD5 153b8ff4b28f2f312d4313e33f905c44
BLAKE2b-256 62781a24f1dfa4f812d82881f1bd452f2c76caba330d4c39228c55df2e8d4f29

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