Requests based HTTP/REST API client with flexible cache support
Project description
Portale is minimalistic requests based HTTP/REST API client.
Advantage over other libraries: Allows different cache timeout policy for each API
Simple example
from portale import PrefixedURLSession
session = PrefixedURLSession('https://httpbin.org/')
get_thing = session.GETRequest('anything?thing={0}', timeout=10)
long_request = session.GETJSONRequest('delay/{n}', timeout=20)
thing = get_thing('snake')
result = long_request(n=2)
result = long_request(n=2) # cached response
Cache
timeout if not specified in Request initialization, session’s timeout is used as default timeout for all the APIs using same session.
from portale import PrefixedURLSession
session = PrefixedURLSession('https://httpbin.org/', timeout=10)
get_thing = session.GETRequest('anything?thing={0}')
long_request = session.GETJSONRequest('delay/{n}')
Busting cache
long_request.cache.bust(n=n)
Access cache metrics
print(long_request.cache.metrics)
Tests
nosetests -xv tests.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
portale-0.7.2.tar.gz
(2.5 kB
view details)
File details
Details for the file portale-0.7.2.tar.gz
.
File metadata
- Download URL: portale-0.7.2.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee823e3164e762a29c4fd4e008fda85df4571506cf855cd126b0f54c6dbdcfd2 |
|
MD5 | da9e33fbc04eb995f00e682541e5a960 |
|
BLAKE2b-256 | ea41e8017d0a9bd4620d967a391b72b9896c6815c2b32c22695561420fd87d99 |