Skip to main content

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


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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

portale-0.9.9-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

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

Hashes for portale-0.9.9.tar.gz
Algorithm Hash digest
SHA256 dee46d87f47d007392e2486a3a8b1eee4c5bb3fac10f8c851e9c5b363cb3b5f4
MD5 ddb035f7411f8f2200d2c13f277bf096
BLAKE2b-256 d9a4fce58cd22555debdd9213bdd956c2f9ccd9b965e20be66095587f8e8646b

See more details on using hashes here.

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

Hashes for portale-0.9.9-py3-none-any.whl
Algorithm Hash digest
SHA256 122a9bd31f62ba2f740adf3a820ff0272c7a362aec9cd11c27e4873fbdffc138
MD5 3134ecb6bc9a3184601053a9366b17f9
BLAKE2b-256 273ae0783849764212d968c7895c9f147603df35199bd6ce144011b11dea85f5

See more details on using hashes here.

Supported by

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