Skip to main content

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

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.9.1.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file portale-0.9.1.tar.gz.

File metadata

  • Download URL: portale-0.9.1.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for portale-0.9.1.tar.gz
Algorithm Hash digest
SHA256 023b8d419739d57db2785f31adca3fd0b637e9c6d80d405503886fa24398578f
MD5 f8c31f462aa9238551149ec2f3f8d96b
BLAKE2b-256 e42b91dc49c12335937494a33e55b9054fe55486595e0b2a3ccb2cf210d7a2f4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page