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

# Stream live telemetry

> Stream telemetry from your application to Sift as it is produced.

After completing this workflow, you can stream telemetry from your application to Sift and watch it arrive in Explore as it is produced.

## Before you begin

* You are familiar with how [Sift organizes telemetry into Assets, Channels, and Runs](https://docs.siftstack.com/documentation/get-started/data-model.md).

## How telemetry streaming works

Sift recommends the Python and Rust clients, the only Sift clients with built-in ingestion. Both stream over a persistent gRPC connection with checkpoints, retries, and optional local backups.

An ingestion config registers the Asset and its Flows, the named groups of Channels you send together. You then send timestamped Flows that match the config.

A Run groups the stream's data. It is optional; without one, Sift stores the data on the Asset only.
Sift sets the Run's start and stop times from its first and last data points.

To stream from another language, [generate a gRPC client with Buf](https://docs.siftstack.com/api/clients/generate-a-client-with-buf.md) and build your own ingestion logic. To stream from National Instruments FlexLogger, [install the Sift FlexLogger plugins](https://docs.siftstack.com/documentation/integrate/stream-data-to-sift-from-flexlogger.md).

## Stream telemetry

> [tab] Python
>
> 1. From a Python environment, install the [Python client](https://sift-stack.github.io/sift/python/latest/) with its `sift-stream` extra, and `python-dotenv`:
>
>    ```bash theme={null}
>    pip install "sift-stack-py[sift-stream]" python-dotenv
>    ```
>
> 2. In your project directory, create a `.env` file and add your [API key](https://docs.siftstack.com/documentation/manage/set-up-api-access.md#create-an-api-key) and your gRPC and REST [base URLs](https://docs.siftstack.com/documentation/manage/set-up-api-access.md#obtain-the-base-url):
>
>    ```bash theme={null}
>    SIFT_API_KEY=your_api_key_here
>    SIFT_GRPC_URL=https://your-grpc-url
>    SIFT_REST_URL=https://your-rest-url
>    ```
>
> 3. In the same directory, create a `stream.py` file. Add a [`SiftClient`](https://sift-stack.github.io/sift/python/latest/reference/sift_client/client/#sift_client.client.SiftClient) that loads the values from the `.env` file:
>
>    ```python theme={null}
>    from dotenv import dotenv_values
>    from sift_client import SiftClient, SiftConnectionConfig
>
>    env_vars = dotenv_values(".env")
>
>    client = SiftClient(
>        connection_config=SiftConnectionConfig(
>            api_key=env_vars["SIFT_API_KEY"],
>            grpc_url=env_vars["SIFT_GRPC_URL"],
>            rest_url=env_vars["SIFT_REST_URL"],
>        )
>    )
>    ```
>
> 4. Define a Flow and its Channels with `FlowConfigPy`. Each `ChannelConfigPy` sets a Channel's `name`, `unit`, `data_type`, and `description`:
>
>    ```python theme={null}
>    from sift_stream_bindings import ChannelConfigPy, ChannelDataTypePy, FlowConfigPy
>
>    FLOW_NAME = "vehicle_metrics"
>
>    flow_config = FlowConfigPy(
>        name=FLOW_NAME,
>        channels=[
>            ChannelConfigPy(
>                name="velocity",
>                unit="m/s",
>                data_type=ChannelDataTypePy.Double,
>                description="Vehicle speed",
>                enum_types=[],
>                bit_field_elements=[],
>            ),
>            ChannelConfigPy(
>                name="temperature",
>                unit="C",
>                data_type=ChannelDataTypePy.Double,
>                description="Internal temperature",
>                enum_types=[],
>                bit_field_elements=[],
>            ),
>        ],
>    )
>    ```
>
> 5. Set the Asset and the Run:
>
>    * In `IngestionConfigFormPy`, set `asset_name` to the Asset name and `client_key` to a key you reuse each time this application streams.
>    * In [`RunCreate`](https://sift-stack.github.io/sift/python/latest/reference/sift_client/sift_types/run/#sift_client.sift_types.run.RunCreate), set `name` to the Run name and `client_key` to a unique key for the Run.
>
>    ```python theme={null}
>    from sift_client.sift_types import RunCreate
>    from sift_stream_bindings import IngestionConfigFormPy
>
>    ingestion_config = IngestionConfigFormPy(
>        asset_name="robot_vehicle_python",
>        client_key="robot_vehicle_python_config_v1",
>        flows=[flow_config],
>    )
>
>    run = RunCreate(name="robot_vehicle_python_run_01", client_key="robot_vehicle_python_run_01")
>    ```
>
> 6. Open the stream with [`create_ingestion_config_streaming_client`](https://sift-stack.github.io/sift/python/latest/reference/sift_client/resources/ingestion/#sift_client.resources.ingestion.IngestionAPIAsync.create_ingestion_config_streaming_client) and send each reading as a `FlowPy`. Set `streaming_mode` to one of the [streaming modes](#keep-a-long-running-stream-reliable); [`StreamingMode.LIVE_ONLY`](https://sift-stack.github.io/sift/python/latest/reference/sift_client/resources/ingestion/#sift_client.resources.ingestion.StreamingMode.LIVE_ONLY) streams without local backups.
>
>    ```python theme={null}
>    import asyncio
>    import random
>    from datetime import datetime, timezone
>
>    from sift_client.resources.ingestion import StreamingMode
>    from sift_stream_bindings import ChannelValuePy, FlowPy, TimeValuePy, ValuePy
>
>    # ... client, flow_config, ingestion_config, and run from the previous steps
>
>    async def main() -> None:
>        async with await client.async_.ingestion.create_ingestion_config_streaming_client(
>            ingestion_config=ingestion_config,
>            run=run,
>            streaming_mode=StreamingMode.LIVE_ONLY,
>        ) as ingest_client:
>            while True:
>                now = datetime.now(timezone.utc)
>                await ingest_client.send(
>                    FlowPy(
>                        flow_name=FLOW_NAME,
>                        timestamp=TimeValuePy.from_timestamp_millis(int(now.timestamp() * 1000)),
>                        values=[
>                            ChannelValuePy(name="velocity", value=ValuePy.Double(random.uniform(0, 10))),
>                            ChannelValuePy(name="temperature", value=ValuePy.Double(random.uniform(20, 40))),
>                        ],
>                    )
>                )
>                await asyncio.sleep(0.5)
>
>    if __name__ == "__main__":
>        asyncio.run(main())
>    ```
>
>    > [!NOTE]
>    >
>    > **Open the stream once**: Reuse the streaming client for the whole program. Creating a new one for each batch or loop iteration creates a new ingestion config each time, which slows streaming significantly.
>
> 7. Run `stream.py`. It streams until you stop it, for example with Ctrl+C.
>
>    ```bash theme={null}
>    python stream.py
>    ```

> [tab] Rust
>
> 1. In your project directory, create a Rust project and add [`sift_stream`](https://docs.rs/sift_stream/latest/sift_stream/), Tokio, `dotenvy`, and `rand`:
>
>    ```bash theme={null}
>    cargo init
>    cargo add sift_stream dotenvy rand
>    cargo add tokio --features full
>    ```
>
> 2. In your project directory, create a `.env` file and add your [API key](https://docs.siftstack.com/documentation/manage/set-up-api-access.md#create-an-api-key) and gRPC [base URL](https://docs.siftstack.com/documentation/manage/set-up-api-access.md#obtain-the-base-url):
>
>    ```bash theme={null}
>    SIFT_API_KEY=your_api_key_here
>    SIFT_GRPC_URL=https://your-grpc-url
>    ```
>
> 3. In `src/main.rs`, add an async `main` function that loads the values from the `.env` file into [`Credentials`](https://docs.rs/sift_stream/latest/sift_stream/enum.Credentials.html):
>
>    ```rust theme={null}
>    use sift_stream::Credentials;
>    use std::{env, error::Error};
>
>    #[tokio::main]
>    async fn main() -> Result<(), Box<dyn Error>> {
>        dotenvy::dotenv()?;
>        let credentials = Credentials::Config {
>            apikey: env::var("SIFT_API_KEY")?,
>            uri: env::var("SIFT_GRPC_URL")?,
>        };
>
>        // ... add the code from the following steps here
>
>        Ok(())
>    }
>    ```
>
> 4. In `main`, define a Flow and its Channels with [`FlowConfig`](https://docs.rs/sift_stream/latest/sift_stream/struct.FlowConfig.html). Each [`ChannelConfig`](https://docs.rs/sift_stream/latest/sift_stream/struct.ChannelConfig.html) sets a Channel's `name`, `unit`, `data_type`, and `description`:
>
>    ```rust theme={null}
>    use sift_stream::{ChannelConfig, ChannelDataType, FlowConfig};
>
>    const FLOW_NAME: &str = "vehicle_metrics";
>
>    let flow_config = FlowConfig {
>        name: FLOW_NAME.into(),
>        channels: vec![
>            ChannelConfig {
>                name: "velocity".into(),
>                unit: "m/s".into(),
>                data_type: ChannelDataType::Double.into(),
>                description: "Vehicle speed".into(),
>                ..Default::default()
>            },
>            ChannelConfig {
>                name: "temperature".into(),
>                unit: "C".into(),
>                data_type: ChannelDataType::Double.into(),
>                description: "Internal temperature".into(),
>                ..Default::default()
>            },
>        ],
>    };
>    ```
>
> 5. In `main`, set the Asset and the Run:
>
>    * In [`IngestionConfigForm`](https://docs.rs/sift_stream/latest/sift_stream/stream/builder/struct.IngestionConfigForm.html), set `asset_name` to the Asset name and `client_key` to a key you reuse each time this application streams.
>    * In [`RunForm`](https://docs.rs/sift_stream/latest/sift_stream/stream/builder/struct.RunForm.html), set `name` to the Run name and `client_key` to a unique key for the Run.
>
>    ```rust theme={null}
>    use sift_stream::{IngestionConfigForm, RunForm};
>
>    let ingestion_config = IngestionConfigForm {
>        asset_name: "robot_vehicle_rust".into(),
>        client_key: "robot_vehicle_rust_config_v1".into(),
>        flows: vec![flow_config],
>    };
>
>    let run = RunForm {
>        name: "robot_vehicle_rust_run_01".into(),
>        client_key: "robot_vehicle_rust_run_01".into(),
>        ..Default::default()
>    };
>    ```
>
> 6. In `main`, build the stream with [`SiftStreamBuilder`](https://docs.rs/sift_stream/latest/sift_stream/stream/builder/struct.SiftStreamBuilder.html) and select one of the [streaming modes](#keep-a-long-running-stream-reliable). [`live_only()`](https://docs.rs/sift_stream/latest/sift_stream/stream/builder/struct.StreamConfigBuilder.html#method.live_only) streams without local backups.
>
>    ```rust theme={null}
>    use sift_stream::SiftStreamBuilder;
>
>    let mut sift_stream = SiftStreamBuilder::new(credentials)
>        .ingestion_config(ingestion_config)
>        .attach_run(run)
>        .live_only()
>        .build()
>        .await?;
>    ```
>
> 7. In `main`, send a reading as a [`Flow`](https://docs.rs/sift_stream/latest/sift_stream/stream/mode/ingestion_config/struct.Flow.html) every 0.5 seconds for 10 minutes, then call [`finish()`](https://docs.rs/sift_stream/latest/sift_stream/stream/struct.SiftStream.html#method.finish):
>
>    ```rust theme={null}
>    use sift_stream::{ChannelValue, Flow, TimeValue};
>    use std::time::{Duration, Instant};
>
>    let start = Instant::now();
>    while start.elapsed() < Duration::from_secs(10 * 60) {
>        // Generate mock values; replace with readings from your system
>        let velocity = rand::random::<f64>() * 10.0;
>        let temperature = rand::random::<f64>() * 20.0 + 20.0;
>
>        let flow = Flow::new(
>            FLOW_NAME,
>            TimeValue::now(),
>            &[
>                ChannelValue::new("velocity", velocity),
>                ChannelValue::new("temperature", temperature),
>            ],
>        );
>        sift_stream.send(flow).await?;
>        tokio::time::sleep(Duration::from_millis(500)).await;
>    }
>
>    sift_stream.finish().await?;
>    ```
>
>    > [!NOTE]
>    >
>    > **Call `finish()`**: `finish()` sends any queued data before it closes the stream. If the program exits without it, data at the end of the stream can be lost.
>
> 8. Run the application. It streams for 10 minutes, then stops.
>
>    ```bash theme={null}
>    cargo run
>    ```

## Keep a long-running stream reliable

When a stream runs for hours or restarts partway through, keep its data in one Run and protect it from connection drops.

## Check the streamed telemetry

1. Select **Runs** in the navigation, then enter the Run name in the **Search** box.
2. In the **Runs** table, confirm the Run's Asset is the right one, then click the Run.
3. Click  **EXPLORE**.
4. In the **Explore** toolbar, click  **LIVE**.
5. In the  **Channels** tab, confirm each Channel from your Flows appears.
6. Click a Channel name to plot it.
7. Confirm new points arrive at the rate you send them, with the expected units and values.
8. Decide whether your data is arriving as expected, without gaps. If data is missing, [verify that your data is arriving](https://docs.siftstack.com/documentation/ingest/monitor-ingestion-health.md) to find the affected Asset and any failed records.

## What's next

* [Monitor telemetry in real time](https://docs.siftstack.com/documentation/analyze/monitor-telemetry-in-real-time.md): Watch Channels update in Panels as the stream runs.
* [Compare a Run against a baseline](https://docs.siftstack.com/documentation/analyze/compare-run-baseline.md): Plot the streamed Run alongside a baseline Run to spot regressions.
