Skip to main content

Generic dynamic Python client for APIs described by OpenAPI specifications.

Project description

openapi-dynamic-client

Generic dynamic Python client for APIs described by OpenAPI specifications.

This package allows you to consume REST APIs from an OpenAPI/Swagger JSON file without generating static client code.

Features

  • Dynamic operation discovery from OpenAPI
  • Call endpoints by operationId
  • Optional tag-scoped access through module proxies
  • Automatic pagination helper
  • JSON and CSV response support
  • Works with local OpenAPI files or Python dictionaries

Installation

pip install openapi-dynamic-client

For local development:

git clone https://github.com/lfeabreu/openapiclient-lib.git
cd openapiclient-lib
pip install -e .

Basic Usage

from openapiclient import OpenAPIClient

api = OpenAPIClient.from_file("api-docs.json")

response = api.call(
    "listUsers",
    page=1,
)

print(response)

Listing operations

operations = api.list_operations()

for operation in operations:
    print(operation)

Calling operations by tag

users = api.module("users")

response = users.listUsers(page=1)
print(response)

Pagination

For APIs that return paginated responses with fields such as resultado, totalPaginas, and paginasRestantes:

for item in api.items("listUsers", max_pages=1):
    print(item)

Using a tag/module proxy:

users = api.module("users")

for item in users.items("listUsers", max_pages=1):
    print(item)

CSV responses

csv_bytes = api.csv("exportUsers")

with open("users.csv", "wb") as file:
    file.write(csv_bytes)

Project Structure

openapiclient/
├─ __init__.py
├─ base.py
├─ client.py
├─ exceptions.py
├─ openapi.py
├─ pagination.py
└─ proxy.py

Future features

  • Dynamic pagination config (the current pagination implementation assumes fixed response field names).

License

MIT

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_dynamic_client-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

openapi_dynamic_client-0.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openapi_dynamic_client-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for openapi_dynamic_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e4960f3a8f4325bcaaa486984a97f6b7efcd6c9192865c5ab032f0ba88521bb1
MD5 2ea91c89a18199522906e571b7bef902
BLAKE2b-256 27450e9b8ee3323a88c855e8227752045d54bcbe5254b303e61c169e727ec83f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openapi_dynamic_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cd2e3dd37b8102bfb12a5cf11c79e824e412fff77508f0894c5dd1f1ab0228a
MD5 47f5c6b96ada5d55baaa4c39df6c9b7f
BLAKE2b-256 e5bf9f2a84c4e1114e9e890e5718b11e51d3df55e20623c9745c6e8b94d8d5f7

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