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 openapi-httpx-client

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()
        print("client", client, dir(client))

        print("client.operations", client.operations)
        print("client.paths", client.paths)
        print("client.functions", client.functions)
        print("client.tools", client.tools)  # get function call tools

        # 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']}")

        # Call an operation using the generated method
        response = await client('getPetById', petId=1)
        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.3.1.tar.gz (5.9 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.3.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file openapi-httpx-client-0.3.1.tar.gz.

File metadata

  • Download URL: openapi-httpx-client-0.3.1.tar.gz
  • Upload date:
  • Size: 5.9 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.3.1.tar.gz
Algorithm Hash digest
SHA256 c39a54c6b3327f6a583a81ea3449d14656dc4ea3f2ca1695b48c61b606a07e8f
MD5 998a5dbd3b22170ddd93099895b5facb
BLAKE2b-256 bc28ac17d78eeddeeda7ff83d9a971c3cbc6be68bad6df91379632551cd624e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openapi_httpx_client-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f306238a5f8f50ddfd17586e9d01043804b812e96feef33027a8d8e8e6da1cf
MD5 a56cf5d0cfb02534267889651d98333e
BLAKE2b-256 b24cfc71984f2a5d228e752436dbdfa52809857f9a55f5e53efaba544296fadb

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