Skip to main content

usage-spec-typer

Generates usage spec for CLIs written with Typer.

Install

pip install usage-spec-typer

Usage

import typer
from typer_usage import generate

app = typer.Typer(help="My CLI tool")

@app.command()
def hello(name: str = typer.Argument(help="Your name")):
    """Say hello"""

@app.command()
def build(
    output: str = typer.Option("dist", help="Output directory"),
    verbose: bool = typer.Option(False, help="Enable verbose output"),
):
    """Build the project"""

print(generate(app, "mycli"))

API

generate(app, bin_name=None)

Generates a usage spec in KDL format from a Typer Typer app.

generate_kdl(app, bin_name=None)

Alias for generate().

generate_json(app, bin_name=None)

Generates a usage spec in JSON format.

convert_root(app, bin_name=None)

Converts a Typer Typer app to the Spec data structure.

Supported Features

Typer Feature Usage Spec Mapping
app.info.name / bin_name name / bin
app.info.help about
typer.Option() flag
typer.Argument() arg
typer.Option(..., help=) Flag help
typer.Argument(..., help=) Arg help
typer.Option(...) (ellipsis) flag required=#true
bool type options Boolean flag (no arg)
--flag/--no-flag negate
count=True count=#true
type=click.Choice() choices
default=... default
hidden=True hide=#true
envvar="..." env
app.add_typer() cmd (recursive)
Subcommand groups subcommand_required=#true
Single command app Treated as root-level
--install-completion / --show-completion Filtered out

License

MIT

Download files

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

Source Distribution

usage_spec_typer-1.2.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

usage_spec_typer-1.2.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file usage_spec_typer-1.2.1.tar.gz.

File metadata

  • Download URL: usage_spec_typer-1.2.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for usage_spec_typer-1.2.1.tar.gz
Algorithm Hash digest
SHA256 8ebf66f5835308ea5199b8d5f26a6fac77267f550eb69ab4167799828f8ab654
MD5 8d6688ff7ccb12810bb13a2fb80351e1
BLAKE2b-256 e1ca1293f42ad68eada42ae6234be5b34a07f4fc0b43ec8f1032e3c63cd0e9f8

See more details on using hashes here.

File details

Details for the file usage_spec_typer-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: usage_spec_typer-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for usage_spec_typer-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4683b0ac37ed5e359336a16ad1f63fb710369f917ec1baad798bdcb0aa7593cf
MD5 be2121a113157424e878cc74da9d77a7
BLAKE2b-256 15d1c800362361f77da6a65d90d159e3157ba2fd8f2c3ccaeea399bf7ea79d1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page