API Consumer
Create clients for consuming endpoints in a class-based way.
Describe the endpoints using a class
from api_client_framework.requests import RequestsEndpoint
from api_client_framework.requests import Methods
from api_client_framework.parsers import NamedTupleParser
from collections import namedtuple
User = namedtuple("User", ["id", "uid", "password","first_name", ...], rename=True)
class UsersEndpoint(RequestsEndpoint):
method = Methods.GET
url = "https://random-data-api.com/api/v2/users"
params = {"response_type": "json"}
parser = NamedTupleParser(User)
Create your client
import requests
from examples.random_data_api.endpoints import UsersEndpoint
from examples.random_data_api.models import User
from api_client_framework.requests import RequestsClient
class RandomDataAPI(RequestsClient):
"""Client for random-data-api.com"""
def __init__(self):
self.session = requests.Session()
def get_user(self) -> User:
"""Retrieve a single random user"""
return self._perform_request(UsersEndpoint())
Advanced
Create your own data parsers
...using Parser protocol.
Convert HTTP exceptions in your custom exceptions
...by creating your own exception_handler
Define a base URL for all your endpoints only once
...using BaseUrlSession from requests_toolbelt package
Log responses
...by adding a hook in your requests.Session instance
def print_response(response, *args, **kwargs):
print(response.url)
session = requests.Session()
session.hooks.setdefault("response", [])
session.hooks["response"].append(print_response)
Examples
There's a small example in this repo, under examples/random_data_api, which implements some endpoints of random-data-api.com
Made with python-api-consumer
- PyWegowAPI - A client for the public, undocumented, Wegow API
Metadata
Release files for api-client-framework 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| api_client_framework-0.1.0.tar.gz | 3.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| api_client_framework-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.2 kB
Release files / api_client_framework-0.1.0.tar.gz
| Download URL | api_client_framework-0.1.0.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67561ac74cce9856bad91f6c40211dcecc2868b89beb5f55cff15d84466ab184
|
|
BLAKE2b-256 checksum How to use checksums |
2fa6f0cb3da419adde66a01e15b2bd2c809f14f5f0c72ea68eb8f0df986e25ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Release files / api_client_framework-0.1.0-py3-none-any.whl
| Download URL | api_client_framework-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e42f6e9c9ea83c772eb360b955ca492cbc59efa8877b4844449680c045e64561
|
|
BLAKE2b-256 checksum How to use checksums |
cdcdf870c63522b2b54dabbd50f555dd269a9d2a8f8794946035ec6b5b2e444b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for api-client-framework 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.