---
source_path: "api/sample/python/index.md"
canonical_url: "https://doc.sensory.com/tnl/7.8/api/sample/python/"
---

# Python examples

The Python sample projects are available in _sample/python/_ in the
TrulyNatural installation directory.

See _~/Sensory/TrulyNaturalSDK/7.9.0-pre.0/sample/python/_

New to the Session API? Start with the **Python** tab in
[Your first program](https://doc.sensory.com/tnl/7.8/getting-started/your-first-program.md#your-first-program), then explore the samples below.

## Run the samples

1.  Create the virtual environment and install the SDK wheel from
    _$HOME/Sensory/TrulyNaturalSDK/7.9.0-pre.0/lib/python/_:

    ```console
    cd ~/Sensory/TrulyNaturalSDK/7.9.0-pre.0/sample/python
    uv venv
    uv sync
    ```

2.  Run the smallest phrase-spotting sample:

    ```console
    uv run src/hello_world.py
    ```

3.  Run the sample acceptance tests:

    ```console
    uv run --group dev pytest
    ```

    [live_audio.py](https://doc.sensory.com/tnl/7.8/api/sample/python/live_audio.md#live_audiopy) is excluded from the default sweep because CI machines
    usually have no microphone. Set `SNSR_RUN_LIVE_AUDIO=1` to include a
    short live-capture run.

## Examples
[hello_world.py](https://doc.sensory.com/tnl/7.8/api/sample/python/hello_world.md#hello_worldpy)

- Loads a wake-word model, runs pull-mode inference from a WAV file, and prints
  each result event.

[stt_push.py](https://doc.sensory.com/tnl/7.8/api/sample/python/stt_push.md#stt-push-py)

- Runs push-mode Speech-to-Text by feeding WAV audio chunks with [push](https://doc.sensory.com/tnl/7.8/api/inference.md#push).
  On SDK builds without STT, it exits cleanly with an "STT not supported"
  message.

[custom_stream.py](https://doc.sensory.com/tnl/7.8/api/sample/python/custom_stream.md#custom_streampy)

- Implements a custom input source with [fromProvider](https://doc.sensory.com/tnl/7.8/api/io.md#fromprovider) and a zero-copy Python
  `memoryview` callback.

[live_audio.py](https://doc.sensory.com/tnl/7.8/api/sample/python/live_audio.md#live_audiopy)

- Captures from the default microphone with [fromAudioDevice](https://doc.sensory.com/tnl/7.8/api/io.md#fromaudiodevice) and runs a
  wake-word spotter for a fixed duration.

[live_enroll.py](https://doc.sensory.com/tnl/7.8/api/sample/python/live_enroll.md#live_enrollpy)

- Runs interactive UDT wake-word enrollment from recordings or live microphone
  input.

<!-- Abbreviation definitions from includes/abbreviations.md -->
*[API]: Application Programming Interface
*[SDK]: Software Development Kit
*[STT]: Speech To Text: transformers with language model and CTC decoding
*[TNL]: TrulyNatural, Sensory's large-vocabulary speech recognition technology
*[UDT]: User-Defined Trigger: enrolled wake words and command sets
