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. 🚀 If available, portale will prioritize it, with requests serving as a fallback.
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
Build and Upload
First, install uv:
pip install uv
To build the distribution, you can use the uv build command:
uv build
This will create the dist directory with the source and wheel distributions.
To upload the distribution to PyPI, you can use uv publish:
uv publish
It is recommended to set a PyPI token with the UV_PUBLISH_TOKEN environment variable.
Release files for portale 0.9.91
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| portale-0.9.91.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| portale-0.9.91-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.7 kB
Release files / portale-0.9.91.tar.gz
| Download URL | portale-0.9.91.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd933cb0d14e01875fd99020c59d4a84429b4b17da8dafc5732424d86d2eec0e
|
|
BLAKE2b-256 checksum How to use checksums |
60abbab59eeeff07a82f2520a30d08d3344b26be2a828befb5756fdce95d8b2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.11
|
Release files / portale-0.9.91-py3-none-any.whl
| Download URL | portale-0.9.91-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
62abf6a5e33f0b15374b5aaf73aa3d5b266c5d3295ffb3e8c8bff111ff8f26a9
|
|
BLAKE2b-256 checksum How to use checksums |
2bf3eb5339e240e18730c33915df54e8f73b3fb8d4da9e4ed7817e8e531a7c9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.11
|