Various strategies for sending requests
Project description
aio-request
This library simplifies an interaction between microservices:
- Allows sending requests using various strategies
- Propagates a deadline and a priority of requests
- Exposes client/server metrics
Example:
import aiohttp
import aio_request
async with aiohttp.ClientSession() as client_session:
client = aio_request.setup(
transport=aio_request.AioHttpTransport(client_session),
endpoint="http://endpoint:8080/",
)
response_ctx = client.request(
aio_request.get("thing"),
deadline=aio_request.Deadline.from_timeout(5)
)
async with response_ctx as response:
pass # process response here
Request strategies
The following strategies are supported:
- Single attempt. Only one attempt is sent.
- Sequential. Attempts are sent sequentially with delays between them.
- Parallel. Attempts are sent in parallel one by one with delays between them.
Attempts count and delays are configurable.
Example:
import aiohttp
import aio_request
async with aiohttp.ClientSession() as client_session:
client = aio_request.setup(
transport=aio_request.AioHttpTransport(client_session),
endpoint="http://endpoint:8080/",
)
response_ctx = client.request(
aio_request.get("thing"),
deadline=aio_request.Deadline.from_timeout(5),
strategy=aio_request.parallel_strategy(
attempts_count=3,
delays_provider=aio_request.linear_delays(min_delay_seconds=0.1, delay_multiplier=0.1)
)
)
async with response_ctx as response:
pass # process response here
Deadline & priority propagation
To enable it for the server side a middleware should be configured:
import aiohttp.web
import aio_request
app = aiohttp.web.Application(middlewares=[aio_request.aiohttp_middleware_factory()])
Expose client/server metrics
To enable client metrics a metrics provider should be passed to the transport:
import aiohttp
import aio_request
async with aiohttp.ClientSession() as client_session:
client = aio_request.setup(
transport=aio_request.AioHttpTransport(
client_session,
metrics_provider=aio_request.PROMETHEUS_METRICS_PROVIDER
),
endpoint="http://endpoint:8080/",
)
It is an example of how it should be done for aiohttp and prometheus.
To enable client metrics a metrics provider should be passed to the middleware:
import aiohttp.web
import aio_request
app = aiohttp.web.Application(
middlewares=[
aio_request.aiohttp_middleware_factory(
metrics_provider=aio_request.PROMETHEUS_METRICS_PROVIDER
)
]
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aio-request-0.1.10.tar.gz
(16.6 kB
view details)
Built Distribution
File details
Details for the file aio-request-0.1.10.tar.gz
.
File metadata
- Download URL: aio-request-0.1.10.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4433dde2c164c0042241ed6e96e6f2d86a2abfc442bc363ad75765d2f1e8efb4 |
|
MD5 | 490d65f240c1cea2e7d3de2a0848b213 |
|
BLAKE2b-256 | 92d29c35f6dc625e51450b1a61851cd206cdff64a0c9e0e6f9e3963f69e0c632 |
Provenance
File details
Details for the file aio_request-0.1.10-py3-none-any.whl
.
File metadata
- Download URL: aio_request-0.1.10-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eeea05643c0b7b1b278f323c482985959c33b6dbaa0a5ff35d95c55c3d589f0 |
|
MD5 | 297cadf40513dbf8932155a5dd4ce66f |
|
BLAKE2b-256 | 034d7840768611d859c189cfbb2d4f26c6840f451782b7bfb21763b640508bbe |