Skip to main content

A Python client for OpenAPI specifications using httpx

Project description

OpenAPI Client for Python

A Python implementation inspired by openapi-client-axios that provides a dynamic client for OpenAPI specifications. This implementation uses httpx for HTTP requests and Python's metaprogramming capabilities to dynamically generate a client.

Installation

pip install -e .

Usage

from openapiclient import OpenAPIClient
import asyncio

async def main():
    # Initialize the client with the OpenAPI definition
    api = OpenAPIClient(definition="https://petstore3.swagger.io/api/v3/openapi.json")

    try:
        # Initialize and get the dynamic client
        client = await api.init()

        # Call an operation using the generated method
        response = await client.getPetById(petId=1)

        # Print the response
        print(f"Status code: {response['status']}")
        print(f"Pet data: {response['data']}")
    finally:
        # Close the HTTP session
        await api.close()

if __name__ == "__main__":
    asyncio.run(main())

Features

  • Dynamic client generation using Python metaprogramming
  • Supports OpenAPI 3.0 and 3.1
  • Supports JSON and YAML specification formats
  • Supports specification loading from URL, file, or dictionary
  • Asynchronous API using httpx
  • Response format similar to axios (data, status, headers, config)

Author

lloydzhou (2025-02-27)

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_httpx_client-0.1.0.tar.gz (4.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_httpx_client-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file openapi_httpx_client-0.1.0.tar.gz.

File metadata

  • Download URL: openapi_httpx_client-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.2

File hashes

Hashes for openapi_httpx_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bfb10ce23732aec9a3b3ba176925a68838f6e4663390a7cdf136c0fbc9674919
MD5 d2355b34b55bd2dbc36bda84d8792c0b
BLAKE2b-256 54110e2c1395ce18a9f353f3baec15df09d4dcc4739549f62fdf0d4c9e0f23a7

See more details on using hashes here.

File details

Details for the file openapi_httpx_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openapi_httpx_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22e4607049370dc3e5d126f8c164b2f05258dd6789c58c76680d518a638952ee
MD5 3af3ff90276ad78c075c99265d034399
BLAKE2b-256 129f24eb87a4fd74ce75511b9833eb2ed6b37dddf2d7d90c153ecb38876b269f

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