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

# Configuration

> Configure the Apitally SDK for Python.

<CodeGroup>
  ```python FastAPI {7-10} theme={null}
  from fastapi import FastAPI
  from apitally.fastapi import ApitallyMiddleware

  app = FastAPI()
  app.add_middleware(
      ApitallyMiddleware,
      client_id="your-client-id",
      env="dev",
      enable_request_logging=True,
      # other parameters ...
  )
  ```

  ```python Django {2-5} theme={null}
  APITALLY_MIDDLEWARE = {
      "client_id": "your-client-id",
      "env": "dev",
      "enable_request_logging": True,
      # other parameters ...
  }
  ```

  ```python Flask {7-10} theme={null}
  from flask import Flask
  from apitally.flask import ApitallyMiddleware

  app = Flask(__name__)
  app.wsgi_app = ApitallyMiddleware(
      app,
      client_id="your-client-id",
      env="dev",
      enable_request_logging=True,
      # other parameters ...
  )
  ```
</CodeGroup>

See the [setup guides](/setup-guides#python) for more examples.

## Parameters

The following configuration parameters are available. Only `client_id` and `env` are required.

| Parameter                     | Description                                                                                                                                                                       | Type        | Default |
| :---------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------- | :------ |
| `client_id`                   | Client ID for your application. Find it on the *Setup instructions* page for your app.                                                                                            | `string`    |         |
| `env`                         | Name of the environment, e.g. `prod` or `dev`. The environment will be automatically created if it doesn't exist.                                                                 | `string`    | `dev`   |
| `app_version`                 | The current version of your application, e.g. `1.0.0`.                                                                                                                            | `string`    | `None`  |
| `enable_request_logging`      | Whether request logging is enabled.                                                                                                                                               | `bool`      | `False` |
| `log_query_params`            | Whether to include query parameters in the logs. If disabled, these will be stripped from the request URLs logged.                                                                | `bool`      | `True`  |
| `log_request_headers`         | Whether to include request headers in the logs. Default masking for common sensitive headers (e.g. `Authorization`) applies.                                                      | `bool`      | `False` |
| `log_request_body`            | Whether to include the request body in the logs. Only JSON and text are supported, up to 50 KB.                                                                                   | `bool`      | `False` |
| `log_response_headers`        | Whether to include response headers in the logs.                                                                                                                                  | `bool`      | `True`  |
| `log_response_body`           | Whether to include the response body in the logs. Only JSON and text are supported, up to 50 KB.                                                                                  | `bool`      | `False` |
| `log_exception`               | Whether to include exception details in the logs.                                                                                                                                 | `bool`      | `True`  |
| `capture_logs`                | Whether to capture application logs emitted during request handling.                                                                                                              | `bool`      | `False` |
| `capture_traces`              | Whether to enable tracing with OpenTelemetry.                                                                                                                                     | `bool`      | `False` |
| `mask_query_params`           | List of regular expressions for matching query parameters to mask. These are in addition to the default masking patterns.                                                         | `list[str]` | `[]`    |
| `mask_headers`                | List of regular expressions for matching headers to mask. These are in addition to the default masking patterns.                                                                  | `list[str]` | `[]`    |
| `mask_body_fields`            | List of regular expressions for matching request/response body fields to mask. These are in addition to the default masking patterns.                                             | `list[str]` | `[]`    |
| `mask_request_body_callback`  | Callback function for masking the request body. Takes one parameter `request` and returns the request body as `bytes` or `None`.                                                  | `Callable`  | `None`  |
| `mask_response_body_callback` | Callback function for masking the response body. Takes two parameters `request` and `response` and returns the response body as `bytes` or `None`.                                | `Callable`  | `None`  |
| `exclude_paths`               | List of regular expressions for matching paths to exclude from logging.                                                                                                           | `list[str]` | `[]`    |
| `exclude_callback`            | Callback function for excluding requests from logging. Takes two parameters `request` and `response` and returns `True`, if the request should be excluded, or `False` otherwise. | `Callable`  | `None`  |
