Skip to main content

Generate typed Python CLIs from OpenAPI specs with Pydantic model flattening into CLI flags

Project description

openapi-cli-gen

Generate a full CLI from any OpenAPI spec in seconds. Nested request bodies become flat --flags automatically.

PyPI Python License: MIT

# Instead of this:
curl -X POST /api/users -d '{"name": "John", "address": {"city": "NYC", "state": "NY"}}'

# You get this:
mycli users create --name John --address.city NYC --address.state NY

Install

# Recommended: pipx (installs in isolated environment)
pipx install openapi-cli-gen

# Or with uv
uv tool install openapi-cli-gen

# Or in a virtual environment
pip install openapi-cli-gen

Try It Now

Point at any public API — no setup, no files needed:

# Get a random cat fact
openapi-cli-gen run --spec https://catfact.ninja/docs Facts get-random --base-url https://catfact.ninja

# Browse cat breeds as a table
openapi-cli-gen run --spec https://catfact.ninja/docs Breeds get --limit 5 --output-format table --base-url https://catfact.ninja
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ breed          ┃ country       ┃ origin         ┃ coat       ┃ pattern       ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ Abyssinian     │ Ethiopia      │ Natural/Stand… │ Short      │ Ticked        │
│ Aegean         │ Greece        │ Natural/Stand… │ Semi-long  │ Bi- or tri-…  │
│ American Curl  │ United States │ Mutation       │ Short/Long │ All           │
└────────────────┴───────────────┴────────────────┴────────────┴───────────────┘
# Inspect any spec to see what commands you'd get
openapi-cli-gen inspect --spec https://petstore3.swagger.io/api/v3/openapi.json

Generate Your Own CLI

openapi-cli-gen generate --spec https://api.example.com/openapi.json --name mycli
cd mycli && pip install -e .
mycli users list
mycli users create --name John --email john@example.com --address.city NYC

Ship it to your users: pip install mycli.

Nested Model Flattening

The core feature. Works at any depth:

--address.city NYC                                  # depth 1
--ceo.name Bob --ceo.email bob@acme.com             # depth 2
--retry.backoff.strategy exponential                 # depth 3
--tags admin --tags reviewer                         # arrays
--environment JAVA_HOME=/usr/lib/jvm                 # dicts
--role admin                                         # enums (validated)
--address '{"street": "123 Main", "city": "NYC"}'   # JSON fallback

As a Library

from openapi_cli_gen import build_cli

app = build_cli(spec="openapi.yaml", name="mycli")
app()

Or plug API commands into your existing CLI:

from openapi_cli_gen import build_command_group

registry = build_command_group(spec="openapi.yaml", name="mycli")

Auth

Auto-configures from your spec's securitySchemes:

export MYCLI_TOKEN=sk-xxx    # env var
mycli users list --token sk-xxx  # or flag (overrides env)

Tested Against Real APIs

Live CRUD validated against Apache Airflow 3.2.0 (111 endpoints) — create, update, delete connections, trigger DAG runs, manage pools and variables. All pass.

Also parsed: Petstore (19 endpoints), ReqRes (40), Redocly Museum (8), Open-Meteo (1). 182 endpoints across 6 APIs, all specs parse successfully.

Compared to Alternatives

Feature openapi-cli-gen specli restish Stainless
Nested model flattening All depths Scalars only No 2 levels
Generates distributable code Yes No No Yes
Runtime mode (no codegen) Yes Yes Yes No
Pluggable into existing CLI Yes No No No
Open source Yes Yes Yes No

Status

Early release (v0.0.1). Core features work. Issues and feedback welcome.

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

openapi_cli_gen-0.0.5.tar.gz (72.2 kB view details)

Uploaded Source

Built Distribution

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

openapi_cli_gen-0.0.5-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file openapi_cli_gen-0.0.5.tar.gz.

File metadata

  • Download URL: openapi_cli_gen-0.0.5.tar.gz
  • Upload date:
  • Size: 72.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for openapi_cli_gen-0.0.5.tar.gz
Algorithm Hash digest
SHA256 94021fc80d4c274cda6cc54371a6dbc15e62a801022131a0b6116b82d24788ec
MD5 edf1da1a3ebef984104fd07d46a1b9be
BLAKE2b-256 3e3e8d69303e6b54fef13d5e4ec2bcc3e43dfff13594d32c4c5cb20bb6434694

See more details on using hashes here.

File details

Details for the file openapi_cli_gen-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for openapi_cli_gen-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8e83204518b28f8c10a26fd09bbacfa96bddd724cf65040b6f95d9725a178580
MD5 349bd4a32c6a9dd913d72bfefa7afbed
BLAKE2b-256 fc06dc90f509c217a3f5b8de5da45252cb0ab36e6c8ce3053a65e26f981b4750

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