Simple API wrapper.
Project description
WrAPIpy
WrAPIpy provides:
- a Pythonic wrapper
wrapipy.WrAPIpyaround a Swagger 2.0 API documentation object that allows to conveniently send requests to the API's endpoints and receive their responses, - and a Pydantic specification of the documentation object,
wrapipy.SwaggerDoc, which is a relaxed model of Swagger 2.0 directly parseable using the build-injsonlibrary.
Basic Usage
Parse a Swagger JSON File
from wrapipy import SwaggerDoc
import json
with open("path_to_swagger", "r") as f:
data = json.load(f)
swagger = SwaggerDoc(**data)
Send Requests to an API
from wrapipy import WrAPI
api = WrAPI(swagger)
r = api.request(
"endpoint_path",
{
"query": {
# query params here as key-value dicts
},
"path": "path_param",
"payload": {
# payload params here as key-value dicts
}
}
)
Full Example
from wrapipy import SwaggerDoc, WrAPI
import json
with open("path_to_swagger", "r") as f:
data = json.load(f)
swagger = SwaggerDoc(**data)
api = WrAPI(swagger)
r = api.request(
"endpoint_path",
{
"query": {
# query params here as key-value dicts
},
"path": "path_param",
"payload": {
# payload params here as key-value dicts
}
}
)
A full API documentation is available at wrapi-documentation.onrender.com.
Advanced Options: Resend Requests
The request method of wrapipy.WrAPI allows to specify an additional parameter retry_responses (default [429]). When a response from this list of response codes is received, it resend the request after wait_time seconds (default 0.1) until a different response is received or until there have been max_attempts attempts (default 100).
This project was initialised with Cookiecutter.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wrapipy-2.0.0.tar.gz.
File metadata
- Download URL: wrapipy-2.0.0.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.2 Linux/6.12.20-2-MANJARO
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa7b99fe549c2ffc45896fd51a2266c62fb5dbbf68229ed0ab3006da2696f69b
|
|
| MD5 |
ac03336d633eb5902119961fdf908e1e
|
|
| BLAKE2b-256 |
7b02923fd851140d26916acc8e3086fb9dd1f98b5013562fda6919c62748fd30
|
File details
Details for the file wrapipy-2.0.0-py3-none-any.whl.
File metadata
- Download URL: wrapipy-2.0.0-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.2 Linux/6.12.20-2-MANJARO
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b3a6e87e5f441d886ae4386815a464ee91bfc9d572932d46589b411808f42ea
|
|
| MD5 |
268fe03586f9a2fd82d62d4999bf015b
|
|
| BLAKE2b-256 |
5d498c97800abca92ea36568bc8fbb29e7ef3503212c168bc802ca396a8fce25
|