https://github.com/wy-z/requests-openapi
A lightweight but powerful and easy-to-use Python client library for OpenAPI v3.
https://github.com/wy-z/requests-openapi
openapi openapi3 pydantic requests
Last synced: 11 months ago
JSON representation
A lightweight but powerful and easy-to-use Python client library for OpenAPI v3.
- Host: GitHub
- URL: https://github.com/wy-z/requests-openapi
- Owner: wy-z
- License: mit
- Created: 2019-05-25T09:22:34.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-30T08:34:10.000Z (almost 2 years ago)
- Last Synced: 2025-04-10T16:54:16.576Z (12 months ago)
- Topics: openapi, openapi3, pydantic, requests
- Language: Python
- Homepage:
- Size: 37.1 KB
- Stars: 65
- Watchers: 4
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# requests-openapi
[](https://pypi.org/project/requests-openapi/)
[](https://pypi.org/project/requests-openapi/)
[](https://pypi.org/project/requests-openapi/)
[](https://github.com/wy-z/requests-openapi)
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
```python
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