cli-schema-typer exports existing Click and Typer command trees as CLI Schema v1 documents.
It is intentionally additive: existing commands and help output stay unchanged; the package adds the hidden __schema meta-command required by the specification.
import click
from cli_schema_typer import install_click_schema
@click.group()
def app():
pass
@app.command()
@click.option("--region", required=True)
def deploy(region: str):
pass
install_click_schema(
app,
version="1.0.0",
metadata={
("deploy",): {
"intent": {"destructive": False, "idempotent": True, "scope": "global"},
"output": {"formats": ["json"], "formatFlag": "--output"},
}
},
)The CLI now supports:
mytool __schemaTo package a sidecar without starting the CLI process, generate a document and write it next to the binary:
from cli_schema_typer import schema_from_click, write_sidecar
document = schema_from_click(app, version="1.0.0")
write_sidecar(document, "/usr/local/bin")
# /usr/local/bin/mytool.cli-schema.jsonThe exporter derives command names, command nesting, options, positionals,
aliases, enum values, defaults, repeatability, and numeric range constraints.
It never guesses operational semantics. Add intent, output metadata, and
special parameter roles explicitly through metadata.
For a Typer application, preserve its existing command shape by routing its
entry point through run_typer after installing the typer extra:
from cli_schema_typer import run_typer
if __name__ == "__main__":
run_typer(app, version="1.0.0")python -m venv .venv
. .venv/bin/activate
pip install -e '.[dev]'
pytest