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. 🚀 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.

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.91.tar.gz (4.7 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.91-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: portale-0.9.91.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for portale-0.9.91.tar.gz
Algorithm Hash digest
SHA256 bd933cb0d14e01875fd99020c59d4a84429b4b17da8dafc5732424d86d2eec0e
MD5 b6cd34191dd6813e17f1bcf8fef7e86f
BLAKE2b-256 60abbab59eeeff07a82f2520a30d08d3344b26be2a828befb5756fdce95d8b2b

See more details on using hashes here.

File details

Details for the file portale-0.9.91-py3-none-any.whl.

File metadata

  • Download URL: portale-0.9.91-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for portale-0.9.91-py3-none-any.whl
Algorithm Hash digest
SHA256 62abf6a5e33f0b15374b5aaf73aa3d5b266c5d3295ffb3e8c8bff111ff8f26a9
MD5 87cfd17405421ed1e06eb5fa83c1a38b
BLAKE2b-256 2bf3eb5339e240e18730c33915df54e8f73b3fb8d4da9e4ed7817e8e531a7c9f

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