๐Ÿš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more โ†’
Socket
Book a DemoInstallSign in
Socket

api-profiler

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-profiler

Django profiling middleware CLI tool

0.1.7
Source
PyPI
Maintainers
1

๐ŸŒ€ 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

MetricDescription
sqlQuery count, total time, repeated queries
headersRequest and response headers
params / bodyURL params and request body
responseResponse content and size
response-headersResponse headers
allEnables 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.

Keywords

django profiler middleware cli development

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts