> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abv.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK - Setup

To get started with the ABV Python SDK you need to install the SDK and initialize the client.

<Steps>
  <Step title="Installation" icon="download">
    To install the SDK, run:

    ```bash theme={null}
    pip install abvdev
    ```
  </Step>

  <Step title="Initialize Client" icon="gear">
    Begin by initializing the `ABV` client. You must provide your ABV api key. These can be passed as constructor arguments or set as environment variables (recommended).

    If you are using a data region other than the US default (e.g., EU: `https://eu.app.abv.dev`), ensure you configure the `host` argument or the `ABV_HOST` environment variable (recommended).

    **via Environment Variables (recommended)**

    ```bash title=".env" theme={null}
    ABV_API_KEY="sk-abv-..."
    ABV_HOST="https://app.abv.dev" # US region
    # ABV_HOST="https://eu.app.abv.dev" # EU region
    ```

    **via Constructor Arguments**

    ```python theme={null}
    from abvdev import ABV

    # Initialize with constructor arguments
    abv = ABV(
        api_key="YOUR_API_KEY",
        host="https://app.abv.dev" # US region
        # host="https://eu.app.abv.dev" # EU region
    )
    ```

    <Info>
      If you are reinstantiating the ABV client with different constructor arguments in the same process, the new configuration will be used for all subsequent calls.
    </Info>

    <Expandable title="Verify connection with abv.auth_check()">
      You can also verify your connection to the ABV server using `abv.auth_check()`. We do not recommend using this in production as this adds latency to your application.

      ```python theme={null}
      from abvdev import get_client

      abv = get_client()

      # Verify connection, do not use in production as this is a synchronous call
      if abv.auth_check():
          print("ABV client is authenticated and ready!")
      else:
          print("Authentication failed. Please check your credentials and host.")
      ```
    </Expandable>

    Key configuration options:

    | Constructor Argument        | Environment Variable            | Description                                                                                                                                     | Default value           |
    | --------------------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
    | `api_key`                   | `ABV_API_KEY`                   | Your ABV project's secret API key. **Required.**                                                                                                |                         |
    | `host`                      | `ABV_HOST`                      | The API host for your ABV instance.                                                                                                             | `"https://app.abv.dev"` |
    | `timeout`                   | `ABV_TIMEOUT`                   | Timeout in seconds for API requests.                                                                                                            | `5`                     |
    | `httpx_client`              | -                               | Custom `httpx.Client` for making non-tracing HTTP requests.                                                                                     |                         |
    | `debug`                     | `ABV_DEBUG`                     | Enables debug mode for more verbose logging. Set to `True` or `"True"`.                                                                         | `False`                 |
    | `tracing_enabled`           | `ABV_TRACING_ENABLED`           | Enables or disables the ABV client. If `False`, all observability calls become no-ops.                                                          | `True`                  |
    | `flush_at`                  | `ABV_FLUSH_AT`                  | Number of spans to batch before sending to the API.                                                                                             | `512`                   |
    | `flush_interval`            | `ABV_FLUSH_INTERVAL`            | Time in seconds between batch flushes.                                                                                                          | `5`                     |
    | `environment`               | `ABV_TRACING_ENVIRONMENT`       | Environment name for tracing (e.g., "development", "staging", "production"). Must be lowercase alphanumeric with hyphens/underscores.           | `"default"`             |
    | `release`                   | `ABV_RELEASE`                   | [Release](/developer/basic-features/releases-versioning) version/hash of your application. Used for grouping analytics.                         |                         |
    | `media_upload_thread_count` | `ABV_MEDIA_UPLOAD_THREAD_COUNT` | Number of background threads for handling media uploads.                                                                                        | `1`                     |
    | `sample_rate`               | `ABV_SAMPLE_RATE`               | [Sampling](/developer/basic-features/sampling) rate for traces (float between 0.0 and 1.0). `1.0` means 100% of traces are sampled.             | `1.0`                   |
    | `mask`                      | -                               | A function `(data: Any) -> Any` to [mask](/developer/basic-features/masking-sensitive-data) sensitive data in traces before sending to the API. |                         |
    |                             | `ABV_MEDIA_UPLOAD_ENABLED`      | Whether to upload media files to ABV S3.                                                                                                        | `True`                  |
  </Step>
</Steps>

# Accessing the Client Globally

The ABV client is a singleton. It can be accessed anywhere in your application using the `get_client` function.

Optionally, you can initialize the client via `ABV()` to pass in configuration options (see above). Otherwise, it is created automatically when you call `get_client()` based on environment variables.

```python theme={null}
from abvdev import get_client

# Optionally, initialize the client with configuration options
# abv = ABV(api_key="sk-abv-...")

# Get the default client
client = get_client()
```
