Available languages: [Python](https://databento.com/docs/api-live/client/live.python.md) · [C++](https://databento.com/docs/api-live/client/live.cpp.md) · [Rust](https://databento.com/docs/api-live/client/live.rust.md) · [Raw](https://databento.com/docs/api-live/client/live.raw.md)

Source: https://databento.com/docs/api-live/client/live


### Live

To access Databento's live API, first create an instance of the
`Live` client. The entire API for a streaming session is exposed
through instance methods of the client.

Databento's `Live` client is built with Python's [asyncio](https://docs.python.org/3/library/asyncio.html) module and can be
easily integrated into asynchronous applications.

Note that the API key can be passed as a parameter, which is
[not recommended for production applications](https://databento.com/docs/portal/api-keys.md#securing-your-api-keys).
Instead, you can leave out this parameter to pass your API key via the `DATABENTO_API_KEY` environment variable:

#### API method

```python
class Live(
    key: str | None = None,
    gateway: str | None = None,
    port: int | None = None,
    ts_out: bool = False,
    heartbeat_interval_s: int | None = None,
    reconnect_policy: ReconnectPolicy | str = ReconnectPolicy.NONE,
    slow_reader_behavior: SlowReaderBehavior | str | None = None,
    compression: Compression | str = Compression.NONE,
    loop: asyncio.AbstractEventLoop | None = None,
)
```

#### Example usage

```python
import databento as db

# Pass as parameter
client = db.Live(key="$YOUR_API_KEY")

# Or, pass as `DATABENTO_API_KEY` environment variable
client = db.Live()
```
#### Parameters

| Parameter | Type | Required | Description |
| `key` | str | optional | 32-character API key. Found on your [API keys]($PLATFORM_HOSTNAME/portal/keys) page. If `None` then `DATABENTO_API_KEY` environment variable is used. |
| `gateway` | str | optional | The url of the remote gateway to connect to. This is for advanced use. |
| `port` | int | optional | The port to connect to the remote gateway on. This is for advanced use. |
| `ts_out` | bool, default False | optional | Whether the gateway should append the send timestamp (`ts_out`) to each record. |
| `heartbeat_interval_s` | int, default None | optional | The interval in seconds at which the gateway will send [heartbeat records](https://databento.com/docs/api-live/basics/system-messages.md) if no other data records are sent. By default heartbeats will be sent at the gateway's default interval. Must be between 5 and 1800 seconds. |
| `reconnect_policy` | ReconnectPolicy or str, default None | optional | The reconnection policy for automatically resuming a live session when an unexpected disconnection occurs. A single reconnection attempt is made; if it fails the session closes and the error is raised from `block_for_close` or `wait_for_close`. |
| `slow_reader_behavior` | SlowReaderBehavior or str, default None | optional | How the gateway should handle a connection unable to keep up with realtime. |
| `compression` | Compression or str, default None | optional | Sets the [compression](https://databento.com/docs/api-live/basics/compression.md) mode for the read stream. Uncompressed by default. |
| `loop` | asyncio.AbstractEventLoop, default None | optional | The event loop to run the client connection in. If `None`, a shared event loop running on a background thread will be used. |
