Requests based HTTP/REST API client with flexible cache support
Project description
Portale
Portale is a minimalistic, requests-based HTTP/REST API client with a key advantage over other libraries: it allows a different cache timeout policy for each API.
Additionally, Portale can use pyreqwest as a backend for improved performance. 🚀
Installation
You can install Portale from PyPI:
pip install portale
To use the pyreqwest backend, install the pyreqwest extra:
pip install portale[pyreqwest]
Simple Example
from portale import PrefixedURLSession
session = PrefixedURLSession('https://httpbin.org/')
get_thing = session.GETRequest('anything?thing={0}', cache_ttl=10)
thing = get_thing('snake')
get_thing_by_name = session.GETRequest('anything?thing={name}', cache_ttl=10)
thing = get_thing_by_name(name='snake')
long_request = session.GETJSONRequest('delay/{n}', cache_ttl=20)
result1 = long_request(n=2).json()
result2 = long_request(n=2).json() # cached response
Cache 💾
If cache_ttl is not specified in the Request initialization, the session's cache_ttl is used as the default for all APIs using that session.
from portale import PrefixedURLSession
session = PrefixedURLSession('https://httpbin.org/', cache_ttl=10)
get_thing = session.GETRequest('anything?thing={0}')
long_request = session.GETJSONRequest('delay/{n}')
Busting Cache
long_request.cache.bust(n=n)
Accessing Cache Metrics
print(long_request.cache.metrics)
Tests 🧪
To run the tests, use the following command:
pytest tests.py
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file portale-0.9.9.tar.gz.
File metadata
- Download URL: portale-0.9.9.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dee46d87f47d007392e2486a3a8b1eee4c5bb3fac10f8c851e9c5b363cb3b5f4
|
|
| MD5 |
ddb035f7411f8f2200d2c13f277bf096
|
|
| BLAKE2b-256 |
d9a4fce58cd22555debdd9213bdd956c2f9ccd9b965e20be66095587f8e8646b
|
File details
Details for the file portale-0.9.9-py3-none-any.whl.
File metadata
- Download URL: portale-0.9.9-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
122a9bd31f62ba2f740adf3a820ff0272c7a362aec9cd11c27e4873fbdffc138
|
|
| MD5 |
3134ecb6bc9a3184601053a9366b17f9
|
|
| BLAKE2b-256 |
273ae0783849764212d968c7895c9f147603df35199bd6ce144011b11dea85f5
|