---
updatedAt: 2026-06-22T16:01:10.000Z
agentTools:
  projectIndex: https://docs.hud.io/llms.txt
---

# Python Installation

Integrate Hud Python SDK for enhanced observability in your application in a few simple steps

> 📘 Prerequisites for Hud Integration
>
> Before integrating Hud, please make sure your application meets the [requirements](/docs/hud-sdk-compatibility-matrix-for-python).

<br />

## 1. Install SDK package

Run the installation command according to your package manager.

```shell pip
pip install hud-sdk
```
```shell poetry
poetry add hud-sdk
```
```Text uv
uv add hud-sdk
```

<br />

## 2. Create hud\_config.py

Create the following file:

```python hud_config.py
import hud_sdk
config = hud_sdk.RegisterConfig() # the var name must be config
```

<HTMLBlock>{`
<style>
  .Accordion[open] .Accordion-toggleIcon {
    transform: rotate(90deg);
    transition: transform 0.2s ease;
  }

  .Accordion-toggleIcon {
    display: inline-block;
    transition: transform 0.2s ease;
  }

  .Accordion-icon {
    margin: 0 8px;
    background: #555;
    border-radius: 50%;
    padding: 4px;
    color: white;
  }

  .Accordion h3 {
    margin-left: 16px;
    margin-top: 1.5em;
  }

  .Accordion dl {
    margin: 0;
    padding: 0 0 1em 0;
  }

  .Accordion dt {
    font-weight: bold;
    margin-top: 1em;
  }

  .Accordion dd {
    margin: 0 0 0.5em 1em;
  }

  .Accordion pre {
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
  }

  .Accordion code {
    font-family: monospace;
    padding: 1px 4px;
    border-radius: 4px;
  }
</style>

<details class="Accordion">
  <summary class="Accordion-title">
    <i class="Accordion-toggleIcon fa fa-chevron-right"></i>
    <i class="Accordion-icon fa fa-info-circle"></i>
    <code>RegisterConfig()</code> Options
  </summary>

  <section style="margin-top: 1em;">
    <h3>RegisterConfig Fields</h3>
    <div style="padding: 0 16px;">
      <p><code>RegisterConfig</code> controls how Hud instruments your Python service:</p>

      <dl>
        <dt><code>include_modules</code></dt>
        <dd>
          List of module name patterns to explicitly include for instrumentation. Useful when you want to focus on specific internal packages. Accepts glob-like strings.<br>
          <small>Type: <code>List[str]</code> &middot; Default: <code>[]</code> (instrument all first-party code excluding third-party)</small>
        </dd>

        <dt><code>max_mapped_functions</code></dt>
        <dd>
          Upper bound on the number of functions Hud will map and monitor. Helps keep overhead predictable in very large codebases.<br>
          <small>Type: <code>int</code> &middot; Default: <code>50000</code></small>
        </dd>

        <dt><code>min_pod_memory_mb</code></dt>
        <dd>
          Minimum memory threshold in MB expected for the runtime. Hud may adjust behavior if available memory is below this value.<br>
          <small>Type: <code>int</code> &middot; Default: <code>250</code> MB</small>
        </dd>

        <dt><code>max_file_size_bytes</code></dt>
        <dd>
          Maximum source file size that Hud will parse when mapping functions. Larger files are skipped to avoid heavy processing.<br>
          <small>Type: <code>int</code> &middot; Default: <code>2097152</code> bytes (2 MB)</small>
        </dd>

        <dt><code>init_timeout</code></dt>
        <dd>
          Timeout in seconds for initialization tasks such as mapping and startup handshakes.<br>
          <small>Type: <code>int</code> &middot; Default: <code>30</code> seconds</small>
        </dd>

        <dt><code>verbose</code></dt>
        <dd>
          Enables verbose logging from the SDK for debugging and development.<br>
          <small>Type: <code>bool</code> &middot; Default: <code>false</code></small>
        </dd>
      </dl>

      <p><strong>Example:</strong></p>
      <pre><code class="language-python">from hud_sdk import 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
)
</code></pre>
    </div>
  </section>
</details>
`}</HTMLBlock>

<br />

## 3. Add Hud CLI to your start command

Hud's SDK uses a CLI wrapper to instrument every part of your code.

```shell python
python -m hud_run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> main.py
```
```shell gunicorn
hud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> gunicorn main:app
```
```shell hypercorn
hud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> hypercorn main:app
```
```shell uvicorn
hud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> uvicorn main:app
```
```shell arq
hud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> arq worker.WorkerSettings
```
```shell -m
hud-run --config ./hud_config.py --key <hud_api_key> --service <your_service_name> python -m module.name
```

> 📘 Tag your deployment (recommended)
>
> Pass a **deployment ID** so Hud attributes data to a specific code version. You can then filter every page in the web app (and MCP) by version using the **Filters** menu in the top-right corner.
>
> Pass `deployment_id` to `init_session()`:
>
> ```python
> hud_sdk.init_session(<hud_api_key>, <your_service_name>, deployment_id="v2.4.1")
> ```
>
> Alternatively, you can set the `HUD_DEPLOYMENT_ID` environment variable.
>
> Use a value that is **unique per version but low cardinality** — e.g. a semantic version (`v2.4.1`), CI build number (`build-1847`), or git tag (`release-2026-04-06`). Avoid high-cardinality values such as a deployment timestamp.

<HTMLBlock>{`
<style>
  .Accordion[open] .Accordion-toggleIcon {
    transform: rotate(90deg);
    transition: transform 0.2s ease;
  }

  .Accordion-toggleIcon {
    display: inline-block;
    transition: transform 0.2s ease;
  }

  .Accordion-icon {
    margin: 0 8px;
    background: #555;
    border-radius: 50%;
    padding: 4px;
    color: white;
  }

  .Accordion h3 {
    margin-left: 16px;
    margin-top: 1.5em;
  }

  .Accordion dl {
    margin: 0;
    padding: 0 0 1em 0;
  }

  .Accordion dt {
    font-weight: bold;
    margin-top: 1em;
  }

  .Accordion dd {
    margin: 0 0 0.5em 1em;
  }

  .Accordion pre {
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
  }

  .Accordion code {
    font-family: monospace;
    padding: 1px 4px;
    border-radius: 4px;
  }
</style>

<details class="Accordion">
  <summary class="Accordion-title">
    <i class="Accordion-toggleIcon fa fa-chevron-right"></i>
    <i class="Accordion-icon fa fa-info-circle"></i>
    Cannot pass secrets in the command line?
  </summary>

  <section style="margin-top: 1em;">
    <div style="padding: 16px 16px;">
      If your deployment environment prevents passing secrets (like API keys or service names) as command line arguments,
      you can still use <code>hud-run</code> safely by omitting the parameters and initializing Hud within your code.
      <br><br>
      <strong>Run your service using:</strong>
      <pre><code class="language-bash">hud-run --config ./hud_config.py python main.py</code></pre>

      <strong>Then, in your code:</strong>
      <pre><code class="language-python">import hud_sdk

hud_sdk.init_session(&lt;hud_api_key&gt;, &lt;your_service_name&gt;, tags={"region": "us-east", "env": "production"}, deployment_id="v2.4.1")</code></pre>

      <blockquote>
        Call <code>hud_sdk.init_session()</code> early in your code. The <code>tags</code> and <code>deployment_id</code> parameters are optional — use <code>tags</code> to attach key-value metadata for filtering, and <code>deployment_id</code> to attribute data to a specific code version.
      </blockquote>
    </div>
  </section>
</details>
`}</HTMLBlock>

<HTMLBlock>{`
<style>
  .Accordion[open] .Accordion-toggleIcon {
    transform: rotate(90deg);
    transition: transform 0.2s ease;
  }

  .Accordion-toggleIcon {
    display: inline-block;
    transition: transform 0.2s ease;
  }

  .Accordion-icon {
    margin: 0 8px;
    background: #555;
    border-radius: 50%;
    padding: 4px;
    color: white;
  }

  .Accordion h3 {
    margin-left: 16px;
    margin-top: 1.5em;
  }

  .Accordion dl {
    margin: 0;
    padding: 0 0 1em 0;
  }

  .Accordion dt {
    font-weight: bold;
    margin-top: 1em;
  }

  .Accordion dd {
    margin: 0 0 0.5em 1em;
  }

  .Accordion pre {
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
  }

  .Accordion code {
    font-family: monospace;
    padding: 1px 4px;
    border-radius: 4px;
  }
</style>

<details class="Accordion">
  <summary class="Accordion-title">
    <i class="Accordion-toggleIcon fa fa-chevron-right"></i>
    <i class="Accordion-icon fa fa-info-circle"></i>
    Cannot use the CLI?
  </summary>

  <section style="margin-top: 1em;">
    <div style="padding: 16px 16px;">
      If your environment doesn't allow using the <code>hud-run</code> CLI wrapper,
      you can start Hud directly from within your Python code:
      <pre><code class="language-python">import hud_sdk

hud_sdk.register(hud_sdk.RegisterConfig())
hud_sdk.init_session(&lt;hud_api_key&gt;, &lt;your_service_name&gt;, tags={"region": "us-east"}, deployment_id="v2.4.1")</code></pre>
      <blockquote>
        Note: <em>hud_sdk.register</em> should be present <em>as early as possible</em> in your code. Hud will not instrument any files that were loaded before it
        <br><br>
        Functions in the same file also won't be instrumented - for full coverage, use <code>hud-run</code>.
      </blockquote>
    </div>
  </section>
</details>
`}</HTMLBlock>

<br />

## 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](https://www.app.hud.io) to explore your data live, or [install the IDE extension](https://docs.hud.io/docs/install-ide-extension#/)  to view it directly alongside your code.

<HTMLBlock>{`
<b>Need help? </b>
Use Hud's
<a href="/docs/py-sdk-ie#/">SDK troubleshoot guide</a>,
<a href="https://www.app.hud.io/?support_chat=true" target="_blank">Chat with our support team</a>
or email us at
<a href="mailto:support@hud.io" target="_blank">support@hud.io</a>
.
`}</HTMLBlock>