Skip to main content

A debugging & profiling toolkit for production Python microservices

Project description

Hawk Debug Toolkit For Python

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

[!NOTE] This project is under development at this moment.

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, name
  • limit - number of functions to show (default: 30)

CPU Profiling (pyinstrument)

  • duration - profile duration in seconds (default: 5)
  • format - output: html, json, speedscope
  • interval - 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) or wall (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, pickle
  • frames - stack frames to capture (default: 30)
  • count - top N allocations (default: 10)
  • gc - run GC before profiling (default: true)

Integrations

FastAPI Starlette Flask

Inspiration

Inspired by Go's net/http/pprof, expvars, and OpenTelemetry Collector's ZPages.

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

hawk_debug-0.0.3.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

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

hawk_debug-0.0.3-py3-none-any.whl (59.6 kB view details)

Uploaded Python 3

File details

Details for the file hawk_debug-0.0.3.tar.gz.

File metadata

  • Download URL: hawk_debug-0.0.3.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for hawk_debug-0.0.3.tar.gz
Algorithm Hash digest
SHA256 d4d2e124806c5b38d54ea9d58283910c4326b66dc537a5cbf1f6d7612a4211e0
MD5 e726630e83f783e13766a02401c61afc
BLAKE2b-256 8d1bf4954a16c7c69125d624afd1fc91748061d544c6f7c7c75f424e476caa11

See more details on using hashes here.

File details

Details for the file hawk_debug-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: hawk_debug-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 59.6 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for hawk_debug-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 78923cbe63927bf8d3666cb2b348d604e83339c69ab8f9b0858c8a2b8bd6bc4d
MD5 b432c2b97af6a38a20224eed06fd59b3
BLAKE2b-256 fe85bfdcf357381f681b2b5772ea4cb653fade3085ddd47dd6bd4eebb033082c

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