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 --base-url https://catfact.ninja Facts get-random

# Browse cat breeds as a table
openapi-cli-gen run --spec https://catfact.ninja/docs --base-url https://catfact.ninja Breeds get --limit 5 --output-format table
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ 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)

Pre-Built CLIs

We publish ready-to-use CLI wrappers for popular APIs, generated with this tool. Install one and start using it instantly:

# Full-coverage CLI for the OpenAI REST API
pipx install openai-rest-cli
export OPENAI_REST_CLI_TOKEN=sk-...
openai-rest-cli Chat create-completion --model gpt-4o-mini --messages '[{"role":"user","content":"Hi"}]'

openai-rest-cli — every OpenAI endpoint (chat, embeddings, images, moderations, files, vector stores, batch) exposed as a typed command. PyPI

# Full-coverage CLI for Meilisearch
pipx install meilisearch-rest-cli
meilisearch-rest-cli Health get

meilisearch-rest-cli — every Meilisearch REST endpoint, generated from their official OpenAPI spec. PyPI

More CLIs coming: Qdrant, Typesense, Airflow.

Tested Against Real APIs

36/36 regression tests passing across 6 live APIs. Full CRUD validated — not just reads.

API Type Tests Notes
OpenAI AI/LLM 8/8 Models, Chat Completions, Embeddings, Images (DALL-E), Moderations, Files, Vector Stores
Qdrant Vector DB 14/14 Collections + Points CRUD, semantic search with real similarity scores
Meilisearch Search 7/7 Health, version, indexes, documents, tasks, stats
Typesense Search 1/1 Manually verified, health works live
GitHub Public 6/6 Meta, licenses, users, rate limit, zen, octocat
Apache Airflow 3.2.0 Workflow 26/27 Full CRUD: create/patch/delete connections, trigger DAG runs

Real commands that work today:

# OpenAI Chat — one command, real GPT-4o-mini response
openapi-cli-gen run --spec <openai-spec> Chat create-completion \
  --model gpt-4o-mini \
  --messages '[{"role":"user","content":"Hello"}]'

# Qdrant vector search — create collection, insert vectors, semantic search
openapi-cli-gen run --spec <qdrant-spec> --base-url http://localhost:6333 \
  Collections create --collection-name pets --vectors '{"size": 4, "distance": "Cosine"}'

openapi-cli-gen run --spec <qdrant-spec> --base-url http://localhost:6333 \
  Search query-points --collection-name pets --query '[0.1, 0.2, 0.3, 0.4]' --limit 5

# Airflow — trigger a DAG with datetime params
openapi-cli-gen run --spec <airflow-spec> --base-url http://localhost:28080 \
  DagRun trigger-dag-run --dag-id my_dag --logical-date 2026-04-09T12:00:00+00:00

# GitHub — public API, no auth needed
openapi-cli-gen run --spec <github-spec> --base-url https://api.github.com \
  users users/get-by-username --username torvalds

See CHANGELOG.md for the full list of bug fixes and improvements.

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. 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.14.tar.gz (102.8 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.14-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openapi_cli_gen-0.0.14.tar.gz
  • Upload date:
  • Size: 102.8 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.14.tar.gz
Algorithm Hash digest
SHA256 cad3c88c93abfa5bb3a7736c51f2e5e3696a009602e763e8f8cb8926ea95271e
MD5 f64148c04ce23a0e4c01096779c2c1ec
BLAKE2b-256 6e8c9acf650ae412737b230fb73f3f3d0fe243308f370c0e39bc4471f3a82f16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openapi_cli_gen-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 32988743bcb57aba68b6361848996f0b9cc68af7f60efa31d61bf2d720e366a7
MD5 7a1ad99a82fb970c6e8eb8476162e512
BLAKE2b-256 6d36b0392810a0149aefeb52ea7f53f68f50b78791e7190eca1d12cdb1c6a34c

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