requests.Session to work with JSON APIs
Project description
api-session
api-session is a small module providing an extended requests.Session
class to work with JSON APIs.
We use it at Bixoto as a basis for JSON API clients such as PyMagento or PyBigBuy.
It aims at factoring the common parts of these clients while staying very lightweight (<100 SLOC).
Features
- base URL: the base API URL is given only once on object creation; subsequent calls use
.get("/path")
- read-only flag: if given, prevents the API from doing
POST
and similar calls - offline flag: if given, prevents the API from doing any call. This is useful for tests.
requests.Session
inheritance: the class inherits fromrequests.Session
, so it stays 100% compatible with it- (since 1.4) Response bodies are included in exception messages for 4xx errors. This behavior can be customized.
Install
pip install api-session
Or with Poetry:
poetry add api-session
Dependency: Python 3.8+.
Usage
from api_session import APISession
client = APISession("https://httpbin.org")
client.get_json_api("/get")
# => {...}
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
api_session-1.4.0.tar.gz
(4.6 kB
view details)
Built Distribution
File details
Details for the file api_session-1.4.0.tar.gz
.
File metadata
- Download URL: api_session-1.4.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.16 Linux/6.5.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47e6e18f8306df162d599c68e2af4c656ac2a4b9e4a97562548a215aecc3c2b6 |
|
MD5 | b238fea8ae18a92066ca42cfe8cf4439 |
|
BLAKE2b-256 | 93eeb80dc19bfc6580c6fb02b5b5fedaf3f4ca5f434572c564e8e834a28793db |
File details
Details for the file api_session-1.4.0-py3-none-any.whl
.
File metadata
- Download URL: api_session-1.4.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.16 Linux/6.5.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ba58c42d57a4d53ce6b56682d8d38cfc2dc2d8428258f132065546c160488c7 |
|
MD5 | 27d5d433d58112b5170e140d1e9bd2b6 |
|
BLAKE2b-256 | fd012ff04de39b06d006007e89a57310985727eff850b68856bcfd1c8c7e333a |