Skip to main content

A CLI tool to call REST APIs defined in OpenAPI 3.0 specs

Project description

papycli — Python CLI for OpenAPI 3.0 REST APIs

papycli is an interactive CLI that reads OpenAPI 3.0 specs and lets you call REST API endpoints directly from the terminal.

Features

  • Auto-generates a CLI from any OpenAPI 3.0 spec
  • Shell completion for bash and zsh
  • Register and switch between multiple APIs
  • Inspect API specs with papycli spec
  • Validate request parameters before sending with --check / --check-strict

Requirements

Item Notes
Python 3.12 or later

Installation

pip install papycli

Enable Shell Completion

bash:

# Add to ~/.bashrc or ~/.bash_profile
eval "$(papycli config completion-script bash)"

zsh:

# Add to ~/.zshrc
eval "$(papycli config completion-script zsh)"

Restart your shell or run source ~/.bashrc / source ~/.zshrc to apply.


Quick Start — Petstore Demo

This repository includes a demo using the Swagger Petstore.

1. Start the Petstore server

docker compose -f examples/docker-compose.yml up -d

The API will be available at http://localhost:8080/api/v3/.

2. Register the API

papycli config add examples/petstore-oas3.json

3. Try some commands

# List available endpoints
papycli summary

# GET /store/inventory
papycli get /store/inventory

# GET with a path parameter
papycli get /pet/99

# GET with a query parameter
papycli get /pet/findByStatus -q status available

# POST with body parameters
papycli post /pet -p name "My Dog" -p status available -p photoUrls "http://example.com/photo.jpg"

# POST with a raw JSON body
papycli post /pet -d '{"name": "My Dog", "status": "available", "photoUrls": ["http://example.com/photo.jpg"]}'

# Array parameter (repeat the same key)
papycli put /pet -p id 1 -p name "My Dog" -p photoUrls "http://example.com/a.jpg" -p photoUrls "http://example.com/b.jpg" -p status available

# Nested object (dot notation)
papycli put /pet -p id 1 -p name "My Dog" -p category.id 2 -p category.name "Dogs" -p photoUrls "http://example.com/photo.jpg" -p status available

# DELETE /pet/{petId}
papycli delete /pet/1

4. Tab completion

Once shell completion is enabled, tab completion is available:

$ papycli <TAB>
  get  post  put  patch  delete  config  spec  summary

$ papycli get <TAB>
  /pet/findByStatus  /pet/{petId}  /store/inventory  ...

$ papycli get /pet/findByStatus <TAB>
  -q  -p  -H  -d  --summary  --verbose  --check  --check-strict

$ papycli get /pet/findByStatus -q <TAB>
  status

$ papycli get /pet/findByStatus -q status <TAB>
  available  pending  sold

$ papycli post /pet -p <TAB>
  name  status  photoUrls

$ papycli post /pet -p status <TAB>
  available  pending  sold

Adding Your Own API

Step 1 — Run config add

papycli config add your-api-spec.json

This command will:

  1. Resolve all $ref references in the OpenAPI spec
  2. Convert the spec to papycli's internal API definition format
  3. Save the result to $PAPYCLI_CONF_DIR/apis/<name>.json
  4. Create or update $PAPYCLI_CONF_DIR/papycli.conf

The API name is derived from the filename (e.g. your-api-spec.jsonyour-api-spec).

Step 2 — Set the base URL

If the spec contains servers[0].url, it is used automatically. Otherwise, edit $PAPYCLI_CONF_DIR/papycli.conf and set the url field:

{
  "default": "your-api-spec",
  "your-api-spec": {
    "openapispec": "your-api-spec.json",
    "apidef": "your-api-spec.json",
    "url": "https://your-api-base-url/"
  }
}

Managing Multiple APIs

# Register multiple APIs
papycli config add petstore-oas3.json
papycli config add myapi.json

# Switch the active API
papycli config use myapi

# Remove a registered API
papycli config remove petstore-oas3

# Show registered APIs and the current default
papycli config list

Reference

# Configuration management commands
papycli config add <spec-file>             Register an API from an OpenAPI spec file
papycli config remove <api-name>           Remove a registered API
papycli config use <api-name>              Switch the active API
papycli config list                        List registered APIs and current configuration
papycli config completion-script <bash|zsh>  Print a shell completion script

# Inspection commands
papycli spec [resource]             Show the raw internal API spec (filter by resource path)
papycli summary [resource]          List available endpoints (filter by resource prefix)
                                      Required params marked with *, array params with []
papycli summary --csv               Output endpoints in CSV format

# API call commands
papycli <method> <resource> [options]

Methods:
  get | post | put | patch | delete

Options:
  -H <header: value>      Custom HTTP header (repeatable)
  -q <name> <value>       Query parameter (repeatable)
  -p <name> <value>       Body parameter (repeatable)
                            - Repeat the same key to build a JSON array:
                              -p tags foo -p tags bar  →  {"tags":["foo","bar"]}
                            - Use dot notation to build a nested object:
                              -p category.id 1 -p category.name Dogs
                              →  {"category":{"id":"1","name":"Dogs"}}
  -d <json>               Raw JSON body (overrides -p)
  --summary               Show endpoint info without sending a request
  --check                 Validate params before sending (warn on stderr, request is still sent)
  --check-strict          Validate params before sending (warn on stderr, abort with exit 1 on failure)
  --verbose / -v          Show HTTP status line
  --version               Show version
  --help / -h             Show help

Environment variables:
  PAPYCLI_CONF_DIR        Path to the config directory (default: ~/.papycli)
  PAPYCLI_CUSTOM_HEADER   Custom HTTP headers applied to every request.
                            Separate multiple headers with newlines:
                            export PAPYCLI_CUSTOM_HEADER=$'Authorization: Bearer token\nX-Tenant: acme'

Limitations

  • Request bodies are application/json only
  • Array parameters support scalar element types only (arrays of objects are not supported)
  • Dot notation for nested objects supports one level of nesting only
  • Pass auth headers via -H "Authorization: Bearer token" or the PAPYCLI_CUSTOM_HEADER env var

Development

git clone https://github.com/tmonj1/papycli.git
cd papycli
pip install -e ".[dev]"

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

papycli-0.5.3.tar.gz (71.1 kB view details)

Uploaded Source

Built Distribution

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

papycli-0.5.3-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file papycli-0.5.3.tar.gz.

File metadata

  • Download URL: papycli-0.5.3.tar.gz
  • Upload date:
  • Size: 71.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for papycli-0.5.3.tar.gz
Algorithm Hash digest
SHA256 a1b65405c5ec954205d1c66053be075bca1e08ad024d3c988eed3cce277e0325
MD5 3c9178fd2342ef3df9553b37283f5129
BLAKE2b-256 a3b3bb646c1462814fd5071abec5d1a4e4ee35f32c42d124175997e94e776606

See more details on using hashes here.

Provenance

The following attestation bundles were made for papycli-0.5.3.tar.gz:

Publisher: release.yml on tmonj1/papycli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file papycli-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: papycli-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for papycli-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 112a1e8f05bd020b247eb993c4eb773246b80a7035d99919de50d97b413f9413
MD5 abd474c17a8ca104a313a67d09b2f99d
BLAKE2b-256 29cb1d1b5d00a10b54a0657d5801cac75eee26021eba540c66ae4ef37b26b080

See more details on using hashes here.

Provenance

The following attestation bundles were made for papycli-0.5.3-py3-none-any.whl:

Publisher: release.yml on tmonj1/papycli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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