Python Installation [BETA]
Integrate Hud Python SDK for enhanced observability in your application in a few simple steps
Python support is currently in betaWhile the core functionality is stable, some features may evolve. We welcome your feedback during this phase.
Prerequisites for Hud IntegrationBefore integrating Hud, please make sure your application meets the requirements.
1. Install SDK package
Run the installation command according to your package manager.
pip install hud-sdk
poetry add hud-sdk
uv add hud-sdk
2. Set environment variables
Configure the following environment variables to enable Hud's SDK:
HUD_ENABLE=true //Hud’s SDK will not be loaded without this being set to true
HUD_KEY=xxx //The API key provided to you, treat it as a secret
HUD_SERVICE=xxx //The service name which will identify this service
HUD_INCLUDE_MODULES=xxx //The modules hud will trace, recommended when using running like gunicorn or celery; comma seprated string; wildcards (*) are supported.
Note: The environment variables need to be set before Hud's import
3. Initialize Hud in Your Application
Hud's SDK need to be imported and initialized as early as possible in your code, to make sure it maps any forthcoming modules' functions.
Option A - preferred: preload with --require
--require
hud-run python [YOUR_ENTRY_POINT].py
hud-run gunicorn main:app
hud-run hypercorn main:app
hud-run uvcorn main:app
Option B - simple import
Add the import at the very top of your entrypoint:
# 1. Import Hud first
from hud_sdk.auto_hook import init
# 2. Add your imports
## from acme.api import server
# 3. Initialize Hud magic
init()
# 4. Run your code
## server.run()
Note: Functions in the same file won't be instrumented. Use option A for full coverage (
hud-run
).
4. Run your service and trigger it!
Start your service and trigger the functions you want to measure - metrics collection will begin automatically.
Then, head over to the web app to explore your data live, or install the IDE extension to view it directly alongside your code.
Updated 9 days ago