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

# Stream Files to Indexes

> Stream videos into an index to get real-time results

## Starting a Stream

To start a stream through the SDK, use the steps below :

<Steps>
  <Step title="Create a Stream Object">
    <CodeGroup>
      ```python python theme={null}
      ms = Stream("your-index-name")
      ```
    </CodeGroup>
  </Step>

  <Step title="Discover Available Sources">
    <CodeGroup>
      ```python python theme={null}
      sources = ms.sources()  # returns a list of device names
      print(sources)
      ```
    </CodeGroup>

    Example console output would look like the following:

    ```
    2 Sources Detected
    ==================================================
    Device Camera or Screen
    --------------------------------------------------
    0 FaceTime HD Camera
    1 Color LCD (1728 x 1117 @ 120 Hz)
    ==================================================
    ```
  </Step>

  <Step title="Select a Source">
    <CodeGroup>
      ```python python theme={null}
      ms.set(1)  # choose the “Color LCD” screen capture from the list above
      ```
    </CodeGroup>

    If no source is set explicitly, index 0 is used by default.
  </Step>

  <Step title="Start Streaming">
    <CodeGroup>
      ```python python theme={null}
      ms.start()  # stream indefinitely (Ctrl-C to stop)

      # OR limit the session to N seconds
      ms.start(30)  # stream for 30 seconds
      ```
    </CodeGroup>

    Once started, the stream will begin capturing video from the selected source functions can be run on the stream from its respective index. For example:

    <CodeGroup>
      ```python python theme={null}
      resp = moonshine.search(
          index="your-index-name",
          query="some prompt here"
      )
      ```
    </CodeGroup>
  </Step>
</Steps>

## Best Practices

Some best practices for streaming:

1. Verify devices first with `ms.sources()`— ID ordering can change between reboots.
2. Combine live `Stream` sessions with batch `upload()` to cover both real-time and historical footage.
3. Keep streams short when testing (`ms.start(10)`) to conserve local and network resources.
4. Use `search` or `inquire` during a live session to build interactive dashboards or alerts.

***

<Accordion title="Stream() Constructor" icon="code-simple">
  <ParamField path="index" type="string" required>
    Index that receives the live feed.

    Must have been created with  **performance=True**
  </ParamField>
</Accordion>

\
**Stream()** methods

<Accordion title=".sources()" icon="code-simple">
  Returns **List\[str]**—the display-ready names of cameras or screens detected on your machine.
</Accordion>

<Accordion title=".set()" icon="code-simple">
  <ParamField path="source_id" type="int" required>
    The integer ID shown by `.sources()`
  </ParamField>
</Accordion>

<Accordion title=".start()" icon="code-simple">
  <ParamField path="timeout" type="int">
    Optional. Duration to stream in **seconds**.\
    Omit or pass `None`to run until manually stopped.
  </ParamField>
</Accordion>
