Skip to main content

Simple API wrapper.

Project description

WrAPIpy

WrAPIpy provides:

  • a Pythonic wrapper wrapipy.WrAPIpy around 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-in json library.

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
        }
    }
)

Make a Swagger-like Documentation

Sometimes the API you wish to connec to does not have a Swagger documentation or has a lot more endpoints than the ones you need. In that case, you can create a Swagger-like documentation using Python dictionaries. The minimal working example follows, but any other Swagger 2.0 supported fields can be provided.

from wrapipy import WrAPI, SwaggerDoc

data = {
    "paths": {
        "/my/path": {
            "parameters": [],
            "get":{
                "responses":{
                    "200": {}
                }
            }
        }
    }
}
swagger = SwaggerDoc(**data)
wrapi = WrAPI(swagger)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wrapipy-2.0.1.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

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

wrapipy-2.0.1-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file wrapipy-2.0.1.tar.gz.

File metadata

  • Download URL: wrapipy-2.0.1.tar.gz
  • Upload date:
  • Size: 19.9 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

Hashes for wrapipy-2.0.1.tar.gz
Algorithm Hash digest
SHA256 ee6537f93a9e6e8cf0eca1a1978af7af622a0b3774f4268da752f135fc0f7e6d
MD5 f14cc6843d84f95ed98f4570b12a37a7
BLAKE2b-256 56521541008685cc40552f85317f6d55b484070f1490fdd88868ed46a79c3586

See more details on using hashes here.

File details

Details for the file wrapipy-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: wrapipy-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.4 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

Hashes for wrapipy-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59a4863583969977d5c6d4ed753829b6fb950fa879125eeb070d9e4d0ff424c3
MD5 8fd74250456abef88239cb2c8ff86f9a
BLAKE2b-256 39ae6675457e8e9e660c58b68536a0c1404fecfc4c280df7507d85cada99e1fa

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