Interactive command-line tutorials with PTY-backed steps
Project description
pytorial
A Python library for interactive command-line tutorials.
Install
pipx install pytorial
# or
uv tool install pytorial
To run from a clone instead of an installed copy, see
CONTRIBUTING.md.
Usage
The package ships with three built-in tutorials. The first one is a self-guided tour of the tool itself:
tutorial run using-tutorials
Companion tours: tutorial run shell-basics (shell and editor skills)
and tutorial run writing-tutorials (authoring tutorials of your own).
Discover what's available
tutorial list
Pipe the same command into a script to get tab-separated rows instead of the rich table.
Run or resume
tutorial run <id> # start or resume saved progress
tutorial run --restart <id> # discard saved progress and start over
Review past runs
tutorial review <id>
tutorial review <id> --step 2
tutorial review <id> --run-id <run-id>
Trust author-supplied shell code
tutorial run --allow-shell <id>
A tutorial step may declare pre_command, check_command, or
post_command. Those fields run author-supplied shell code, so they are
opt-in: pass --allow-shell only when you trust the tutorial author.
Writing tutorials
Take the interactive walkthrough first:
tutorial run writing-tutorials
File format
A tutorial is a single Markdown file beginning with YAML front matter:
---
id: my-tutorial
title: My Tutorial
summary: One-line description shown by `tutorial list`.
---
# First step
```tutorial-step
required_patterns:
- some-command
hint: Try running `some-command`.
```
Step body in Markdown.
- Required front-matter fields:
id,title,summary. - Each top-level
# Headingbecomes one step. - A step may begin with a fenced
tutorial-stepYAML block. Recognised fields arerequired_patterns,pre_command,check_command,post_command,hint,edit_file,kind,options, andanswers. - Without
kindoredit_file, a step opens an interactive shell. edit_fileopens a workspace-relative file in$EDITOR, falling back tovim,vi, ornanowhen$EDITORis unset.kind: input,kind: single_select, andkind: multi_selectprompt directly in the CLI instead of opening a shell or editor.inputanswers use the same string-or-{mode, pattern}format asrequired_patterns; select questions use literal option text inoptionsandanswers.pre_command,check_command, andpost_commandonly run when the reader passes--allow-shell.- Use one YAML string for each shell field. Multi-line shell scripts
should use YAML
|so one bash process sees the whole script and keepscd,export, and shell options across lines. - Do not use YAML
>for shell fields: it folds newlines into spaces and can break shell syntax.
Share and install
Install a tutorial Markdown file or URL into the user's tutorial directory:
tutorial install path/to/tutorial.md
tutorial install https://example.com/tutorial.md
tutorial install --force path/to/tutorial.md
Use --force to overwrite an installed tutorial with the same id.
The standalone CLI auto-loads installed tutorials alongside the
built-ins.
Load ad hoc
To use a tutorial without installing it, point at the file or directory on the command line:
tutorial list --tutorial-path some/dir
tutorial run --tutorial-path some/dir <id>
--tutorial-path may be repeated and is appended after the built-ins.
Embedding the CLI
The package can be mounted as a subcommand inside another Typer or
argparse application via add_typer_subcommand and
add_argparse_subcommand in src/pytorial/cli.py. Embedded hosts
prepend the using-tutorials lesson before host-specific tutorials, do
not load the user's installed tutorial directory, and hide the
standalone-only install command.
Contributing
For the literate sources, the make build, and the repo layout, see
CONTRIBUTING.md.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytorial-0.6.tar.gz.
File metadata
- Download URL: pytorial-0.6.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.4 CPython/3.13.7 Linux/6.17.0-22-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0a9f1cbd4c7e3553017ffdadceb865cccc1748338cb1729fb8c4a9b04cb0ecb
|
|
| MD5 |
e49d134a5504fb14c61e507594e508b4
|
|
| BLAKE2b-256 |
186bd3021dd3f8bbb02b283077fab976016ce941543ad211285dc17c3a468835
|
File details
Details for the file pytorial-0.6-py3-none-any.whl.
File metadata
- Download URL: pytorial-0.6-py3-none-any.whl
- Upload date:
- Size: 39.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.4 CPython/3.13.7 Linux/6.17.0-22-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e14c77a963022ae9fefe0a543110a9dfe0fc85a62e711e2a4ed0469be4c8cc45
|
|
| MD5 |
8a1b599a030d34e57339a7b3d6247b97
|
|
| BLAKE2b-256 |
0c64fe386eef3b9f04c6f64bb5bd07103f508a93a741b3c23e6e7afa9f74c325
|