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.2.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file api_session-1.4.2.tar.gz
.
File metadata
- Download URL: api_session-1.4.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.16 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fbbd497b247c8d405ba3fb606be9a4ba28ad46ece347b120a50cbaf167d901c |
|
MD5 | bd869b51583a557da89eef04b6668d21 |
|
BLAKE2b-256 | 9ae5713ad926308018462cbe4abf1042c40d0c430b018b1e990d1ef6df8cde38 |
File details
Details for the file api_session-1.4.2-py3-none-any.whl
.
File metadata
- Download URL: api_session-1.4.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.16 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 650cfcba61dd58aee3b70c386cc9ac87d82580b15591d0c2741c80d929fe7ba6 |
|
MD5 | 6999b576a26cbb69be45f6ed621bea75 |
|
BLAKE2b-256 | 4b2a23cf1af55efc160cc4892b7ca17cf655a66517cb17ec607429a916e147b7 |