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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

httpx_openapi_gen-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for httpx_openapi_gen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b60ca232fc7295b45c53ec6c485cc417ef5b9fda8939c7616643cb42ffa4ea67
MD5 bf2b6a2927c48f20589681c8ca9c0269
BLAKE2b-256 5882c3db2d3ff72619c788ad5f84b7eb0456b82e7ce8a7d9b37cd72854da8176

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