Skip to main content

Typer Model Args

An extension for Typer that enables model arguments.

Typer Model Args lets you declare Pydantic model parameters in your Typer command and automatically exposes its fields as proper Typer options/arguments on the command line. It keeps Typer’s annotations, adds missing ones when possible, and can convert typing.Literal fields into Enums for better CLI help and validation.

  • Works with Typer
  • Works with Pydantic models
  • Preserves Typer metadata/annotations
  • Optional Literal-to-Enum conversion for cleaner help and choices

Installation

uv add typer_model_args

Quickstart

# app.py
import typer
from typing import Annotated
from pydantic import BaseModel
from typer_model_args import flatten_parameter_model_to_signature

class CliArgs(BaseModel):
    name: Annotated[str, typer.Option(...)]
    description: str | None = None

app = typer.Typer()

@app.command()
@flatten_parameter_model_to_signature()
def create(arguments: CliArgs, another_arg: str):
    """
    After decoration, --name/--description become top-level CLI options.
    """
    typer.echo(f"name={arguments.name}, desc={arguments.description}, extra={another_arg}")

if __name__ == "__main__":
    app()

API

  • flatten_parameter_model_to_signature(*, literals_to_enums: bool = True)
    • Flattens all pydantic model parameters in the decorated function into the function signature used by Typer.
    • literals_to_enums: when True, fields annotated with typing.Literal are turned into Enums so Typer can display and validate choices.

Why use this?

  • Keep your CLI schema and validation centralized in Pydantic models.
  • Get clean, well-typed Typer commands without manually duplicating model fields as options.
  • Better help messages and validation with minimal boilerplate.

Requirements

  • Python 3.10+
  • Typer
  • Pydantic

License

MIT

Metadata

Release files for typer_model_args 0.3.2

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_model_args 0.3.2
File Size Uploaded
typer_model_args-0.3.2.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for typer_model_args 0.3.2
File Interpreter ABI Platform
typer_model_args-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / typer_model_args-0.3.2.tar.gz

Download URL typer_model_args-0.3.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2a74bc35b199e51ec981dfbda129cf03741d080037eaa9f9fb2661cf743cb3e7
BLAKE2b-256 checksum
How to use checksums
fdb260a1da4bd3c33cdcfd9e6f698732bc7f8078e35862ad67b50d66f361ed4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.20

Release files / typer_model_args-0.3.2-py3-none-any.whl

Download URL typer_model_args-0.3.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a65fde989dd2b797d4805f8c60d0c42c3b4d7b05a44715b7d4e454457ae80953
BLAKE2b-256 checksum
How to use checksums
e903721e0a06931797a1d5724eb60f89fd737cf58442095379fb21b3e2cf208c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.20

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

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