Poast: Python OAS Toolkit

Poast [1] is an OpenAPI 3.0 specification parser and client library for Python.

Danger

This project is still in alpha.

Features

  • OpenAPI 3.0.3 compliant parsing and validation
  • Runtime client generation
  • Utilizes requests for underlying HTTP request/response
  • Compatible with requests_futures and requests_oauthlib sessions

Demo

Creating a client from a spec::

>>> from poast.openapi3.spec import OpenApiObject
>>> from poast.openapi3.client import gen_client_cls

>>> # Load the spec (path, io stream, url, or string!)
>>> api_spec = OpenApiObject(
...     'https://petstore3.swagger.io/api/v3/openapi.json')

>>> # [Optionally, perform validation]
>>> api_spec.validate()

>>> # Generate a client class from the spec:
>>> PetStoreClient = gen_client_cls('PetStoreClient', api_spec)

>>> # Instantiate a client and start using the API!
>>> client = PetStoreClient('https://petstore3.swagger.io/api/v3')

>>> print(client.op.getInventory().execute().json())
{'approved': 57, 'placed': 100, 'delivered': 50}

>>> print(client.op.getPetById(petId=2).execute().json())
{'id': 2, 'category': {'id': 2, 'name': 'Cats'}, 'name': 'Cat 2', 'photoUrls': ['url1', 'url2'], 'tags': [{'id': 1, 'name': 'tag2'}, {'id': 2, 'name': 'tag3'}], 'status': 'sold'}
[1]Python OpenAPI Specification Toolkit