Skip to main content

typer-examples

CI Typer Compatibility Python License: MIT

Attach structured, syntax-highlighted usage examples to Typer commands. They appear automatically in --help output as a Rich panel — no subclassing, no epilog hacks.

 Usage: myapp deploy [OPTIONS] ENV

╭─ Options ──────────────────────────────────────────────────────────╮
│ --tag    TEXT  Docker image tag to deploy.  [default: latest]      │
│ --yes          Skip confirmation prompt.                           │
│ --help         Show this message and exit.                         │
╰────────────────────────────────────────────────────────────────────╯
╭─ Examples ─────────────────────────────────────────────────────────╮
│ Deploy to staging with a pinned tag                                │
│ Pulls the image, runs migrations, and restarts services.           │
│ $ myapp deploy staging --tag 1.4.2                                 │
│                                                                    │
│ Deploy to production and skip confirmation                         │
│ Pass --yes in CI pipelines to avoid interactive prompts.           │
│ $ myapp deploy production --tag 2.0.0 --yes                        │
╰────────────────────────────────────────────────────────────────────╯

Installation

pip install typer-examples
# or
uv add typer-examples

Requires Python ≥ 3.9 and Typer ≥ 0.9.

Quick start

import typer
from typer_examples import example, install

app = typer.Typer()
install(app)

@app.command()
@example(
    "Deploy to staging with a pinned tag",
    "{env} --tag {version}",
    env="staging",
    version="1.4.2",
    detail="Pulls the image, runs migrations, and restarts services.",
)
@example(
    "Deploy to production and skip confirmation",
    "{env} --tag {version} --yes",
    env="production",
    version="2.0.0",
    detail="Pass --yes in CI pipelines to avoid interactive prompts.",
)
def deploy(env: str, tag: str = typer.Option("latest"), yes: bool = False):
    ...

if __name__ == "__main__":
    app()

Decorator order: @example must sit below @app.command() — closest to def. This ensures the metadata is attached to the raw function before Typer wraps it.

Features

  • Decorator-first — examples live next to the command, not buried in docstrings or epilog strings
  • Template variables{placeholders} resolved from per-example kwargs, app-level defaults, sys.argv, or Click parameter defaults → details
  • Per-app config — each Typer() instance gets its own panel title, style theme, and variable defaults → details
  • Docs generation — export all examples to Markdown or reStructuredText for CI doc pipelines → API
  • Chain-safe — composes with rich-click and any other rich_format_help patch without clobbering
  • Graceful degradation — if rich is absent, install() returns silently with no error

Documentation

Topic
Template variables Resolution chain: per-example → app-level → argv → defaults
Configuration ExamplesConfig fields, global config, per-app config for sub-commands
API reference Full public API with signatures and return types
How it works Internal implementation and the rich_format_help hook

Try the examples

# Minimal single-app setup — three commands, each with examples
uv run python examples/simple.py deploy --help
uv run python examples/simple.py logs --help
uv run python examples/simple.py shell --help

# Root app + two sub-apps with independent per-app config
uv run python examples/app.py deploy --help
uv run python examples/app.py db migrate --help
uv run python examples/app.py server start --help

# Static docs generation
uv run python examples/app.py docs
uv run python examples/app.py docs --format rst

Compatibility

Typer Python rich-click
≥ 0.9 3.9 – 3.12 Supported

Compatibility is verified daily across all supported Typer × Python combinations in CI.

License

MIT

Release files for typer-examples 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for typer-examples 1.1.1
File Size Uploaded
typer_examples-1.1.1.tar.gz 35.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for typer-examples 1.1.1
File Interpreter ABI Platform
typer_examples-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 45.7 kB

Release files / typer_examples-1.1.1.tar.gz

Download URL typer_examples-1.1.1.tar.gz
Size 35.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8d82a32bd9f240bea89997bf809b30894529c8025b71cd1e51a60524a0689ac1
BLAKE2b-256 checksum
How to use checksums
12b1235a0d53cfa666cbb34454b2e764561ab7c1146b98cf13f80ddd0ff1fb80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

Release files / typer_examples-1.1.1-py3-none-any.whl

Download URL typer_examples-1.1.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79dbe350cbfe567b4302eb6768fe0417b74b35c9a01a6d8cb761faf7c6ef14e7
BLAKE2b-256 checksum
How to use checksums
685e4527ffe87de163788324b3f931ddec36fa6af64d03586c4f75fa048c52fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release 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