Python Installation
Integrate Hud Python SDK for enhanced observability in your application in a few simple steps
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-sdkpoetry add hud-sdkuv add hud-sdk2. Create hud_config.py
Create the following file:
import hud_sdk
config = hud_sdk.RegisterConfig() # the var name must be config
RegisterConfig() Options
RegisterConfig Fields
RegisterConfig controls how Hud instruments your Python service:
include_modules-
List of module name patterns to explicitly include for instrumentation. Useful when you want to focus on specific internal packages. Accepts glob-like strings.
Type:List[str]· Default:[](instrument all first-party code excluding third-party) max_mapped_functions-
Upper bound on the number of functions Hud will map and monitor. Helps keep overhead predictable in very large codebases.
Type:int· Default:50000 min_pod_memory_mb-
Minimum memory threshold in MB expected for the runtime. Hud may adjust behavior if available memory is below this value.
Type:int· Default:250MB max_file_size_bytes-
Maximum source file size that Hud will parse when mapping functions. Larger files are skipped to avoid heavy processing.
Type:int· Default:2097152bytes (2 MB) init_timeout-
Timeout in seconds for initialization tasks such as mapping and startup handshakes.
Type:int· Default:30seconds verbose-
Enables verbose logging from the SDK for debugging and development.
Type:bool· Default:false
Example:
from hud import register, RegisterConfig
config = RegisterConfig(
include_modules=["my_company.*", "internal_pkg"],
max_mapped_functions=50000,
min_pod_memory_mb=250,
max_file_size_bytes=2 * 1024 * 1024,
init_timeout=30,
verbose=True
)
3. Add Hud CLI to your start command
Hud's SDK uses a CLI wrapper to instrument every part of your code.
hud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> python main.pyhud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> gunicorn main:apphud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> hypercorn main:apphud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> uvcorn main:apphud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> arq worker.WorkerSettingshud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> python -m module.nameCannot pass secrets in the command line?
If your deployment environment prevents passing secrets (like API keys or service names) as command line arguments,
you can still use
Run your service using:
hud-run safely by omitting the parameters and initializing Hud within your code.
Run your service using:
hud-run --config ./hud_config.py python main.py
Then, in your code:
import hud_sdk
hud_sdk.init_session(<hud_api_key>, <your_service_name>)
Call hud_sdk.init_session() early in your code.
Cannot use the CLI?
If your environment doesn't allow using the
hud-run CLI wrapper,
you can start Hud directly from within your Python code:
import hud_sdk
hud_sdk.register(hud_sdk.RegisterConfig())
hud_sdk.init_session(<hud_api_key>, <your_service_name>)
Note: hud_sdk.register should be present as early as possible in your code. Hud will not instrument any files that were loaded before it
Functions in the same file also won't be instrumented - for full coverage, usehud-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.
Need help?
Use Hud's
SDK troubleshoot guide,
Chat with our support team
or email us at
[email protected]
.
Updated 10 days ago
