Hawk
Lightweight debugging & profiling toolkit
for production 🐍Python services
Features
- Memory Profiling - tracemalloc-based allocation tracking
- CPU Profiling - cProfile (built-in), pyinstrument (async-aware), yappi (multi-threaded)
- Debug Vars - expose internal service state
- ZPages - custom debug dashboard
- On-demand activation - profile only when needed, download profiles for further investigation or render them in the browser
- No elevated permissions required (like
CAP_PTRACE) - Enable/disable via environment variables without code changes
Installation
pip install hawk-debug
Optional dependencies for CPU profiling:
pip install hawk-debug[pyinstrument] # async-aware sampling profiler
pip install hawk-debug[yappi] # multi-threaded CPU/wall time profiler
Quick Start
FastAPI
from fastapi import FastAPI
from hawk.contrib.fastapi import get_router
app = FastAPI()
app.include_router(get_router())
Starlette
from starlette.applications import Starlette
from starlette.routing import Mount
from hawk.contrib.starlette import get_router
app = Starlette(routes=[
Mount("/debug", app=get_router()),
])
Flask
from flask import Flask
from hawk.contrib.flask import create_debug_blueprint
app = Flask(__name__)
app.register_blueprint(create_debug_blueprint(), url_prefix="/debug")
Endpoints
| Endpoint | Description |
|---|---|
/debug/prof/cpu/cprofile/ |
CPU profile with cProfile (fixed duration) |
/debug/prof/cpu/cprofile/start/ |
Start cProfile CPU profiling |
/debug/prof/cpu/cprofile/stop/ |
Stop and get cProfile CPU profile |
/debug/prof/cpu/pyinstrument/ |
CPU profile with pyinstrument (fixed duration) |
/debug/prof/cpu/pyinstrument/start/ |
Start pyinstrument CPU profiling |
/debug/prof/cpu/pyinstrument/stop/ |
Stop and get pyinstrument CPU profile |
/debug/prof/cpu/yappi/ |
CPU profile with yappi (fixed duration) |
/debug/prof/cpu/yappi/start/ |
Start yappi CPU profiling |
/debug/prof/cpu/yappi/stop/ |
Stop and get yappi CPU profile |
/debug/prof/mem/tracemalloc/ |
Memory profile (fixed duration) |
/debug/prof/mem/tracemalloc/start/ |
Start memory profiling |
/debug/prof/mem/tracemalloc/snapshot/ |
Take memory snapshot |
/debug/prof/mem/tracemalloc/stop/ |
Stop memory profiling |
/debug/vars/ |
Debug variables |
/debug/ |
ZPages dashboard |
Query Parameters
CPU Profiling (cProfile)
duration- profile duration in seconds (default: 5)format- output:text,json,pstat(binary)sort- sort by:cumulative,time,calls,namelimit- number of functions to show (default: 30)
CPU Profiling (pyinstrument)
duration- profile duration in seconds (default: 5)format- output:html,json,speedscopeinterval- sampling interval (default: 0.001)async_mode-enabled,disabled,strict
CPU Profiling (yappi)
duration- profile duration in seconds (default: 5)format- output:funcstats(JSON),pstat(binary),callgrind(for KCachegrind)clock_type-cpu(CPU time) orwall(wall clock time)builtins- profile built-in functions (default: false)multithreaded- profile all threads (default: true)
Memory Profiling
duration- profile duration in seconds (default: 5)format- output:lineno,traceback,pickleframes- stack frames to capture (default: 30)count- top N allocations (default: 10)gc- run GC before profiling (default: true)
Integrations
Inspiration
Inspired by Go's net/http/pprof, expvars, and OpenTelemetry Collector's ZPages.
Metadata
Release files for hawk-debug 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hawk_debug-0.0.3.tar.gz | 2.0 MB | Without provenance | Details for hawk_debug-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hawk_debug-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for hawk_debug-0.0.3-py3-none-any.whl |
Total release size: 2.0 MB
Release files / hawk_debug-0.0.3.tar.gz
| Download URL | hawk_debug-0.0.3.tar.gz |
|---|---|
| Size | 2.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d4d2e124806c5b38d54ea9d58283910c4326b66dc537a5cbf1f6d7612a4211e0
|
|
BLAKE2b-256 checksum How to use checksums |
8d1bf4954a16c7c69125d624afd1fc91748061d544c6f7c7c75f424e476caa11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / hawk_debug-0.0.3-py3-none-any.whl
| Download URL | hawk_debug-0.0.3-py3-none-any.whl |
|---|---|
| Size | 59.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
78923cbe63927bf8d3666cb2b348d604e83339c69ab8f9b0858c8a2b8bd6bc4d
|
|
BLAKE2b-256 checksum How to use checksums |
fe85bfdcf357381f681b2b5772ea4cb653fade3085ddd47dd6bd4eebb033082c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for hawk-debug 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.