Skip to main content

Agent-first Python CLI library — Typer-compatible, built on argparse + pydantic

Project description

agentyper

Agent-first Python CLI library — built on argparse + pydantic, Typer-compatible.

Typer was built for the era when type hints changed Python.
agentyper is built for the era when AI agents changed how software is operated.

Why Agentyper?

Typer was built for humans. Agents need something different.

Typer revolutionized CLI development by elegantly using type hints. However, because it is built on Click and Rich, it is fundamentally optimized for human eyeballs. When interacting with standard CLIs, AI Agents struggle: they cannot organically discover the tool's schema, they get blocked by interactive prompts ([y/N]), they hallucinate when parsing ANSI-colored tables, and they fail to self-correct when errors are returned as flat strings.

Agentyper keeps the beloved Developer Experience (DX) of Typer but replaces the execution engine with argparse and Pydantic. With a one-line switch (import agentyper as typer), your CLI instantly yields OpenAPI/JSON schemas, strict Pydantic structured errors, and deterministic programmatic overrides for interactive features.

📖 Learn more in our docs:

agentyper implements the CLI Agent Spec — a formal specification for agent-ergonomic CLI tools.

Install

pip install agentyper

Quick Start

Absolute minimum:

Create a main.py:

def main(name: str):
    print(f"Hello {name}")

Run it without importing anything:

agentyper main.py run Camila

Single function (like typer.run()):

import agentyper

def search(ticker: str, limit: int = 10):
    """Search securities by ticker."""
    results = service.search(ticker, limit)
    agentyper.output(results)   # routes via --format automatically

agentyper.run(search)

Multi-command app:

import agentyper

app = agentyper.Agentyper(name="my-tool", version="1.0.0")

@app.command()
def search(ticker: str, limit: int = agentyper.Option(10, help="Max results")):
    """Search securities."""
    agentyper.output(service.search(ticker, limit))

@app.command()
def delete(name: str):
    """Delete a record."""
    if agentyper.confirm(f"Delete '{name}'?"):
        service.delete(name)

app()

Typer migration — one line:

# import typer          ← before
import agentyper as typer  # ← after; everything else stays identical

What Agents Get for Free

Every command automatically gains:

my-tool --schema                  # full JSON Schema of the entire app
my-tool search --schema           # JSON Schema for this command's params
my-tool search AAPL --format csv  # 4× cheaper output than table
my-tool search AAPL --format json # structured JSON output
my-tool delete alice --yes        # skip confirm() in agent mode
my-tool wizard --answers '{"confirms":[true],"prompts":["Alice","admin"]}'

If you are an agent consuming an agentyper CLI, read docs/for-agents.md for schema discovery, error handling, and the full flag reference.
If you are building a CLI with agentyper, read docs/for-developers.md for patterns, best practices, and a pre-ship checklist.

Agent Ergonomics

Feature agentyper Typer
--schema on every command ✅ automatic ❌ manual
--format json/csv/table ✅ automatic ❌ manual
Structured JSON errors ✅ automatic ❌ free text
Exit code taxonomy (0/1/2) ❌ 0 or 1
Interactive features in agent mode --yes/--answers bypass ❌ blocks
isatty() auto-format detection
Dependencies argparse + pydantic Click + Typer

Typer Compatibility Matrix

agentyper implements Typer's core API. For most CLIs, import agentyper as typer works flawlessly. Because it is built from scratch on argparse + Pydantic (for LLM reliability) instead of Click, there are some differences.

Feature / API Status Notes
@app.command(), @app.callback() ✅ Supported Core app routing works identically.
Option(), Argument() ✅ Supported Core args mapping (default, help, etc.)
Type Hint Extraction ✅ Supported Uses Pydantic for robust validation.
Interactive Prompts (confirm()) ✅ Supported Enhanced with non-blocking agent overrides.
typer.Context (ctx) ⚠️ Mocked Minimal Context mock. click-specific methods (ctx.forward(), ctx.meta) do not exist.
click Parameter Types ❌ Unsupported Fully replaced by Pydantic. Use Literal["A"] instead of click.Choice.
typer.style(), colors ❌ Unsupported Removed. Agents prefer plain text or structured JSON.
Custom Click logic ❌ Unsupported Executed purely via standard argparse.

Exit Codes

agentyper.EXIT_SUCCESS    = 0  # success
agentyper.EXIT_VALIDATION = 1  # bad input — agent should retry with correction
agentyper.EXIT_SYSTEM     = 2  # system error — agent should abort

Interactive Features

All interactive features from Typer work identically in a terminal. In agent/non-TTY mode, they resolve without blocking:

# Human terminal: asks interactively
my-tool delete alice

# Agent: auto-confirm via flag
my-tool delete alice --yes

# Agent: pre-supply all answers
my-tool wizard --answers '{"confirms":[true,false],"prompts":["Alice","admin"]}'

# Agent: pipe answers from stdin
echo '{"confirms":[true]}' | my-tool delete alice --answers -

License

MIT

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

agentyper-0.1.8.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

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

agentyper-0.1.8-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

Details for the file agentyper-0.1.8.tar.gz.

File metadata

  • Download URL: agentyper-0.1.8.tar.gz
  • Upload date:
  • Size: 37.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for agentyper-0.1.8.tar.gz
Algorithm Hash digest
SHA256 67b197ef53dfc5051bddcc62c0966abeaa7a032b3a93790e12c97d3a30be1548
MD5 989b786e496221f8fd0fe265cd26c7f4
BLAKE2b-256 f6b747fc4e867a21461a6a0c38d77d1856ad7aee46443ad5c419f76670b6dcb8

See more details on using hashes here.

File details

Details for the file agentyper-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: agentyper-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 36.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for agentyper-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ea974ffa06c5adb3a3cfd49bbcaeef1a2051ac93fd6a83c51e9c713d6a641aaa
MD5 f7c894ed734cc866d0f2e7f687b2644d
BLAKE2b-256 e4cb45f02e37b6e274ad5626d32958cadcf939860eaa82ecf3722bde283b94e8

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