Skip to main content

snippet-cast

Turn an annotated Python snippet into a narrated screencast video.

Narration is written as trailing #: comments on the snippet's own lines, so the input stays valid, runnable Python:

def fib(n):             #: We define fib, taking one argument, n.
    a, b = 0, 1          #: Start from the first two Fibonacci numbers.
    for _ in range(n):   #: Loop n times.
        a, b = b, a + b  #: Advance the pair; b becomes the running sum.
    return a             #: Return a — the nth Fibonacci number.

Each #: line becomes one "beat": the code is revealed up to that line, the line is highlighted, and its narration is spoken. snippet-cast renders syntax-highlighted code frames with a progressive reveal, a Python-Tutor-style live variable panel, optional burned-in captions and a typing-in animation, synthesises speech per line, and stitches everything into an MP4 with ffmpeg.

Installation

Requires Python 3.10+ and ffmpeg (with ffprobe) on PATH.

pip install snippet-cast
# or
pixi add snippet-cast
# or
conda install -c munch-group snippet-cast

Usage

snippet-cast snippet.py -o out.mp4 --tts silent --subtitles   # fast, voiceless proof
snippet-cast snippet.py -o out.mp4 --typing --subtitles       # type each new line in
snippet-cast loop.py    -o out.mp4 --every --subtitles        # animate each loop iteration

Or from Python:

from snippet_cast import build

build("snippet.py", "out.mp4", tts="silent", subtitles=True)

Or in a Jupyter notebook — write the snippet directly in a cell instead of a separate .py file:

pip install snippet-cast[jupyter]
%load_ext snippet_cast.magic
%%snippet-cast -o out.mp4 --tts silent --subtitles
def fib(n):             #: We define fib, taking one argument, n.
    a, b = 0, 1          #: Start from the first two Fibonacci numbers.
    for _ in range(n):   #: Loop n times.
        a, b = b, a + b  #: Advance the pair; b becomes the running sum.
    return a             #: Return a — the nth Fibonacci number.
result = fib(7)          #: Call fib with seven; result becomes {result}.

The cell magic takes the same flags as the CLI and displays the rendered MP4 inline.

See SETUP.md for all TTS backends — the zero-setup say (macOS) and manual (your own recordings, including --record for recording live via the microphone) backends, plus configuring Piper (local) and ElevenLabs (cloud) — and snippet-cast --help for all options.

Configuration

-o/--output sets an explicit path; without it, -n/--name (default out) and -d/--output-dir (default ., created if missing) build one as output-dir/name.mp4:

snippet-cast snippet.py --tts silent -n intro -d ./videos   # -> ./videos/intro.mp4

Every option (except -o/--output) also has a SNIPPET_CAST_<NAME> environment variable default — an explicit flag always wins over its env var:

import os
os.environ["SNIPPET_CAST_TTS"] = "say"
os.environ["SNIPPET_CAST_SUBTITLES"] = "1"
os.environ["SNIPPET_CAST_PAUSE"] = "0.6"
os.environ["SNIPPET_CAST_OUTPUT_DIR"] = "./videos"

set in one notebook cell, applies to every %%snippet-cast cell after it (picked up fresh each time, so setting it in a later cell still works). Toggle flags (--every, --subtitles, --typing, --record, --export-script) accept --no-X to override an env-var-forced default back off for one run.

Development

This repository is built from the munch-group library template.

Initial set up

pixi run init

Get updates to upstream fork

Add upstream if not already added

git remote add upstream https://github.com/munch-group/snippet-cast.git

Fetch upstream changes

git fetch upstream

Either rebase your changes on top of upstream (cleaner history)

git rebase upstream/main

Or, merge upstream into your fork (preserves history)

git merge upstream/main

If you want to see what's changed upstream before applying:

git log HEAD..upstream/main

See the actual diff

git diff HEAD...upstream/main

Then push your updated fork:

git push origin main

If you rebased and need to force push

git push origin main --force-with-lease

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snippet_cast-0.1.52.tar.gz (600.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snippet_cast-0.1.52-py3-none-any.whl (90.5 kB view details)

Uploaded Python 3

File details

Details for the file snippet_cast-0.1.52.tar.gz.

File metadata

  • Download URL: snippet_cast-0.1.52.tar.gz
  • Upload date:
  • Size: 600.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for snippet_cast-0.1.52.tar.gz
Algorithm Hash digest
SHA256 2877d0b02212e8a9598dfc883332c670eed2adae81d291a3c6d41752e05c75d8
MD5 2117838a22f01a152d8a9fb5b29ca0ff
BLAKE2b-256 7a48f86b678c5d8214b017d2a64a7f3c0ece9db15ab1b7f620d7073e076a8938

See more details on using hashes here.

File details

Details for the file snippet_cast-0.1.52-py3-none-any.whl.

File metadata

  • Download URL: snippet_cast-0.1.52-py3-none-any.whl
  • Upload date:
  • Size: 90.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for snippet_cast-0.1.52-py3-none-any.whl
Algorithm Hash digest
SHA256 e133cc9b6e37f7b765035d32d4c07dab8f123198897f6c6a5648b754695819c0
MD5 31287d720b0ee0f121467ef0e1d637be
BLAKE2b-256 851bd95ed710552cac03fa85bf148087c1a29d921c1003c68fc858f9ef363eda

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.56

2 files

0.1.55

2 files

0.1.54

2 files

0.1.53

2 files

This release

0.1.52 This release

2 files

0.1.51

2 files

0.1.50

2 files

0.1.49

2 files

0.1.47

2 files

0.1.45

2 files

0.1.43

2 files

0.1.41

2 files

0.1.39

2 files

0.1.37

2 files

0.1.35

2 files

0.1.33

2 files

0.1.31

2 files

0.1.29

2 files

0.1.25

2 files

0.1.24

2 files

0.1.22

2 files

0.1.20

2 files

0.1.18

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page