Code Monkey home page Code Monkey logo

requests-openapi's Introduction

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

requests-openapi's People

Contributors

wy-z avatar chrism2671 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.