https://github.com/bixoto/api-session
requests.Session to work with JSON APIs
https://github.com/bixoto/api-session
json-api-client python3 requests-python
Last synced: about 2 months ago
JSON representation
requests.Session to work with JSON APIs
- Host: GitHub
- URL: https://github.com/bixoto/api-session
- Owner: Bixoto
- License: mit
- Created: 2021-10-11T10:27:48.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-14T12:15:53.000Z (about 2 months ago)
- Last Synced: 2025-04-14T23:14:52.037Z (about 2 months ago)
- Topics: json-api-client, python3, requests-python
- Language: Python
- Homepage: https://pypi.org/project/api-session/
- Size: 221 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# api-session
**api-session** is a small module providing an extended `requests.Session` class to work with JSON APIs.
We use it at [Bixoto](https://bixoto.com/) 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).
[PyMagento]: https://github.com/Bixoto/PyMagento
[PyBigBuy]: https://github.com/Bixoto/PyBigBuy## 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 from `requests.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
```python3
from api_session import APISessionclient = APISession("https://httpbin.org")
client.get_json_api("/get")
# => {...}
```