Skip to main content

Use OpenAPI schema to generate command line client

Project description

OpenAPI CLI

OpenAPI CLI is a command-line interface (CLI) tool designed to interact with APIs generated by openapi-python-client. This tool allows you to configure and use API clients with ease.

Features

  • Configure API client modules
  • Validate client modules
  • Generate API client instances

Installation

To install OpenAPI CLI, use poetry:

poetry add openapi-cli[full]

To install the CLI globally, use pip:

pip install openapi-cli[full]

Optional

If you want to just use separator for your operation ids use:

poetry add openapi-cli

This will not have a cli, but you can use the separator in your code. If you want to still have ability to generate clients use the following:

poetry add openapi-cli[full] --group dev

This will keep your project build clean and will not install the cli in your production environment.

Usage

To use OpenAPI CLI in your project add the following to your pyproject.toml:

    [tool.poetry.scripts]
    your-api-cli = "openapi_cli:cli"

Then, you can run the CLI using in venv activated shell:

    your-api-cli --help

Configure the CLI

Before using the CLI, you need to configure it with your client module, base URL, and token.

Install the client module using downloaded module using openapi-python-client:

your-api-cli client install --module <name_of_your_module> 

Set the base URL and token for the client module:

openapi client api-config --base-url <url_of_your_api>
openapi client auth --token <your_token>

Patch the client to support nesting:

openapi client patch --separator <your_operation_id_separator>  # default is '_oaps_'

You can import separator to integrate it with your code:

from openapi_cli.separator import CLI_SEPARATOR

Requirements

  • Python 3.12+
  • Poetry

Setup

  1. Clone the repository.
  2. Install dependencies using poetry install.

Code Formatting

This project uses black and isort for code formatting. To format the code, run:

poetry run black .
poetry run isort .

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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-0.2.1.12.tar.gz (43.3 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-0.2.1.12-py3-none-any.whl (38.2 kB view details)

Uploaded Python 3

File details

Details for the file openapi_cli-0.2.1.12.tar.gz.

File metadata

  • Download URL: openapi_cli-0.2.1.12.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.1 Darwin/24.4.0

File hashes

Hashes for openapi_cli-0.2.1.12.tar.gz
Algorithm Hash digest
SHA256 4fd5c7a5636489cae2df547ee10179d5473e69be71875242888c4b6e2854cd71
MD5 b22de5d71feba5428fb076896c1bca7f
BLAKE2b-256 1dd94971f2430048d54e9e80823c3f3b8adc7227a98b2cfaf52a81d4fe7414a6

See more details on using hashes here.

File details

Details for the file openapi_cli-0.2.1.12-py3-none-any.whl.

File metadata

  • Download URL: openapi_cli-0.2.1.12-py3-none-any.whl
  • Upload date:
  • Size: 38.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.1 Darwin/24.4.0

File hashes

Hashes for openapi_cli-0.2.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 76843616c23562bbd5802f8626e8c050c69ffa76bba6532f1141c0c3ac6563ab
MD5 c897c3f8e22dd67c3a55227f08e38412
BLAKE2b-256 41a943c8a6a8017426dee119e561e4c5526798bcafdc3be681c69a7df03601ca

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