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

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


### Live.\_\_aiter\_\_
Using [async for](https://docs.python.org/3/reference/compound_stmts.html#the-async-for-statement); records will be yielded as they arrive.
Iteration will stop when the connection is closed and all records are processed.
This is best for integration into asynchronous applications.

Asynchronous iteration is only supported inside a [coroutine](https://docs.python.org/3/library/asyncio-task.html#coroutines).

Asynchronous iteration will automatically call [Live.start](https://databento.com/docs/api-live/client/start.md) if the session is connected but it has not been started.
Starting iteration after the session has started will cause a `ValueError`.

Asynchronous iteration will automatically call [Live.stop](https://databento.com/docs/api-live/client/stop.md) if the iterator is destroyed, such as when an async for loop is escaped with an exception or `break` statement.
To prevent this behavior, an iterator can be created explicitly using [aiter()](https://docs.python.org/3/library/functions.html#aiter).

#### API method

```python
Live.__aiter__() -> AsyncIterator[DBNRecord]
```

#### Example usage

```python
import databento as db

# Create a live client
client = db.Live(key="$YOUR_API_KEY")

# Subscribe to a data stream
client.subscribe(
    dataset="GLBX.MDP3",
    schema="trades",
    stype_in="parent",
    symbols="ES.FUT",
)

# Start streaming and asynchronously iterate the records
async for record in client:
    print(record)
```
