OpenAPI specification tools for analyzing, updating, and generating a CLI.
Project description
openapi-spec-tools
This is a collection of tools for using OpenAPI specifications. The OpenAPI community has a plethora of tools, and this is intended to supplement those. The tools here provide functionality that has not been readily available elsewhere.
Getting started
The project has been published to PyPi, so you should be able to install it with something like one of the following (depending on how you do Python package management):
% pip install openapi-spec-tools
% poetry add openapi-spec-tools
Generally, there are two intended ways to utilize this package:
- Use the CLI tools to perform actions
oas- analyzing and modifying an OpenAPI speclayout- generating and analyzing a YAML file that provides structure to the CLI/API generatorcli-gen- generates a CLI from an OpenAPI spec (and optionally a layout file)api-gen- generates API code from an OpenAPI spec (and optionally a layout file)
- Use the code in the Python modules for your own purpose
The sections below provide a brief description with links to more examples and details.
OAS
The oas script provides a tool for analyzing and modifying an OpenAPI spec. See OAS.md for more info.
Here's a trivial example:
(.env) % oas analyze models list pet.yaml
Found 3 models:
Error
Pet
Pets
(.env) % oas analyze models ops pet.yaml Pet
Found Pet is used by 3 operations:
createPets
listPets
showPetById
(.env) %
CLI Generation
The cli-gen tool allows users to create a user-friendly CLI using the OpenAPI spec and a layout file. The layout file provides the CLI structure and refers to the OpenAPI spec for details of operations. LAYOUT.md has more details about the layout file, and the CLI_GEN.md has more info about CLI generation.
Turn a simple layout like:
main:
description: Manage pets
operations:
- name: add
operationId: createPets
Into code that produces a CLI that has commands like:
% pets add --help
Usage: pets add [OPTIONS]
Create a pet
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --id INTEGER │
│ --name TEXT │
│ --tag TEXT │
│ --owner TEXT │
│ --api-host TEXT API host address [env var: API_HOST] │
│ --api-key TEXT API key for authentication [env var: API_KEY] │
│ --api-timeout INTEGER API request timeout in seconds for a single request [env var: API_TIMEOUT] [default: 5] │
│ --log [critical|error|warn|info|debug] Log level [env var: LOG_LEVEL] [default: warn] │
│ --format [table|json|yaml] Output format style [env var: OUTPUT_FORMAT] [default: table] │
│ --style [none|bold|all] Style for output [env var: OUTPUT_STYLE] [default: all] │
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
%
See the examples in examples/ for some more complete works.
API Generation
The api-gen tool allows users to generate API code using the OpenAPI spec. The generated Python code provides type hints and helpful comments, but does no real checking of the arguments and/or return values. The return values are typically dictionaries instead of a data class, such as the models provided in the standard OpenAPI generator.
Contributing
The DEVELOPMENT.md has more information about getting setup as a developer.
The TODO.md has some ideas where this project can be improved and expanded -- please add your ideas here, or email Rick directly (rickwporter@gmail.com).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openapi_spec_tools-0.9.4.tar.gz.
File metadata
- Download URL: openapi_spec_tools-0.9.4.tar.gz
- Upload date:
- Size: 66.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8926cad33b2291ce0cee8abc426c470f5bc76a1fcece1bd95798ef5f5aa2c2fa
|
|
| MD5 |
77118b00893c3b4f6d88e818defd6d36
|
|
| BLAKE2b-256 |
e1ae350bd7692f53e5554587c43d166127e55ba0647ae96ab1c448b3a8d22fd5
|
Provenance
The following attestation bundles were made for openapi_spec_tools-0.9.4.tar.gz:
Publisher:
pypi_publish.yaml on rickwporter/openapi-spec-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openapi_spec_tools-0.9.4.tar.gz -
Subject digest:
8926cad33b2291ce0cee8abc426c470f5bc76a1fcece1bd95798ef5f5aa2c2fa - Sigstore transparency entry: 624663120
- Sigstore integration time:
-
Permalink:
rickwporter/openapi-spec-tools@9d8c020cdc27f616d8b776043277dfd1a70fe6d4 -
Branch / Tag:
refs/tags/v0.9.4 - Owner: https://github.com/rickwporter
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yaml@9d8c020cdc27f616d8b776043277dfd1a70fe6d4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file openapi_spec_tools-0.9.4-py3-none-any.whl.
File metadata
- Download URL: openapi_spec_tools-0.9.4-py3-none-any.whl
- Upload date:
- Size: 86.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bc5d898e9bc7421967b7ba764952a35d0ccf1dd59dfc3769c3c564587cbc33c
|
|
| MD5 |
601b1657e1ed7cab5043f492790497eb
|
|
| BLAKE2b-256 |
50c396c8e970712d995b61de5f183fde14476def2946ad21ddfdc64c578dd53b
|
Provenance
The following attestation bundles were made for openapi_spec_tools-0.9.4-py3-none-any.whl:
Publisher:
pypi_publish.yaml on rickwporter/openapi-spec-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openapi_spec_tools-0.9.4-py3-none-any.whl -
Subject digest:
7bc5d898e9bc7421967b7ba764952a35d0ccf1dd59dfc3769c3c564587cbc33c - Sigstore transparency entry: 624663170
- Sigstore integration time:
-
Permalink:
rickwporter/openapi-spec-tools@9d8c020cdc27f616d8b776043277dfd1a70fe6d4 -
Branch / Tag:
refs/tags/v0.9.4 - Owner: https://github.com/rickwporter
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yaml@9d8c020cdc27f616d8b776043277dfd1a70fe6d4 -
Trigger Event:
release
-
Statement type: