Skip to main content

RequestsOpenAPI is a python client library for OpenAPI 3.0

Project description

requests-openapi

image image image image

A lightweight but powerful and easy-to-use Python client library for OpenAPI v3.

Key Features

  • Lightweight Design: Experience a minimalistic interface.
  • Focus on Essentials: Helps you simplify the handling of Paths, Parameters, Headers, Cookies, etc., while inheriting all the capabilities of Requests.
  • Testing and Integration Made Easy: Whether you're running tests or integrating with other systems, the client simplifies these tasks.

Usage

import requests_openapi

# load spec from url
c = requests_openapi.Client().load_spec_from_url("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml")
# or load from file
c = requests_openapi.Client().load_spec_from_file("openapi.json")
# set server
c.set_server(requests_openapi.Server(url="https://fake.com/api"))

# custom session for auth or others
c.requestor # a instance of requests.Session, see https://requests.readthedocs.io/en/latest/user/advanced/#session-objects
# set update token
c.requestor.headers.update({"Authorization": "token"})

# call api by operation id
resp = c.listPets() # resp: requests.Response
resp.json()
# get by path id
resp = c.showPetById(petId=1)
resp.json()
# post
resp = c.createPets(json={})
resp.json()

#
# Advanced Usage
#

# set req options, 'req_opts' param to custom request options
requests_openapi.Client(req_opts={"timeout": 60}).load_spec_from_file("xx")

# parameters starts with '_' or not found in openapi spec, will be passed through to the requesting
c.createPets(json={}, _headers={}, _params={}, _cookies={})

# parameters
# in: cookie, name: csrftoken
c.createPets(csrftoken="***")
# in: header, name: x-foo
c.createPets(**{"x-foo": "***"})
# in: path, name: userId
c.getUser(userId=1)
# in: query, name: offset
c.listUsers(offset=1)

# http body, just like requests.Session
c.createPets(json={}) or c.createPets(data={})

Installation

pip install requests-openapi

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

requests-openapi-1.0.2.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

requests_openapi-1.0.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file requests-openapi-1.0.2.tar.gz.

File metadata

  • Download URL: requests-openapi-1.0.2.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for requests-openapi-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8b21df845f50ed2c0c35d285c575b5d58312e2a023476b442c69222dfcef00ca
MD5 8febfefadb01c9dd12ad13d5068cd5ca
BLAKE2b-256 c99fed0d6d63d70714c963d245700af40ffd7742ed0e6adde28863f8477f4f05

See more details on using hashes here.

File details

Details for the file requests_openapi-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for requests_openapi-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d119cb538ef73602e47e62b4ff156815a1a2806e049ddce99707a44621c7e99a
MD5 ab4d0871dcc91fa091f1be3c533ef88f
BLAKE2b-256 c3edc4edf4a379be7a63477984262878303d52fd52a8181bf24096883f526b62

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