Skip to content
/ Portale Public

Minimalist requests based HTTP/REST API client

License

Notifications You must be signed in to change notification settings

shon/Portale

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Portale

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}', 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

cache_ttl if not specified in Request initialization, session's cache_ttl is used as default cache_ttl for all the APIs using same 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)

Access cache metrics

print(long_request.cache.metrics)

Tests

nosetests -xv tests.py

About

Minimalist requests based HTTP/REST API client

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages