OpenAPI Python Client Generator

0.28.3 · active · verified Sat Apr 11

OpenAPI Python Client Generator is a Python library and CLI tool that generates modern, type-hinted Python clients from OpenAPI specifications. It supports both OpenAPI v2 (Swagger) and v3 specifications, generating Pydantic-based models and httpx-based clients. It's actively maintained with frequent releases, currently at version 0.28.3.

Warnings

Install

Imports

Quickstart

Generates a Python client for the Petstore API from its OpenAPI specification. The primary interaction with openapi-python-client is via its command-line interface. The generated client is then imported and used like a standard Python library.

openapi-python-client generate --url https://petstore.swagger.io/v2/swagger.json --path my-api-client

# The above command generates a client in the 'my-api-client' directory.
# Example usage of the generated client (assuming 'my-api-client' is in your PYTHONPATH):
# import my_api_client.client as my_client
# client = my_client.Client(base_url="https://petstore.swagger.io/v2")
# # You can now use client.pet, client.store, etc.
# response = client.pet.find_pets_by_status(status="available")
# if response.status_code == 200:
#     pets = response.parsed
#     for pet in pets:
#         print(pet.name)

view raw JSON →