Package: aio-request
aio-requestThis library simplifies an interaction between microservices:Allows sending requests using various strategiesPropagates a deadline and a priority of requestsExposes client/server metricsExample:importaiohttpimportaio_requestasyncwithaiohttp.ClientSession()asclient_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))asyncwithresponse_ctxasresponse:pass# process response hereRequest strategiesThe 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:importaiohttpimportaio_requestasyncwithaiohttp.ClientSession()asclient_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)))asyncwithresponse_ctxasresponse:pass# process response hereDeadline & priority propagationTo enable it for the server side a middleware should be configured:importaiohttp.webimportaio_requestapp=aiohttp.web.Application(middlewares=[aio_request.aiohttp_middleware_factory()])Expose client/server metricsTo enable client metrics a metrics provider should be passed to the transport:importaiohttpimportaio_requestasyncwithaiohttp.ClientSession()asclient_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:importaiohttp.webimportaio_requestapp=aiohttp.web.Application(middlewares=[aio_request.aiohttp_middleware_factory(metrics_provider=aio_request.PROMETHEUS_METRICS_PROVIDER)])Circuit breakerimportaiohttpimportaio_requestasyncwithaiohttp.ClientSession()asclient_session:client=aio_request.setup_v2(transport=aio_request.AioHttpTransport(client_session),endpoint="http://endpoint:8080/",circuit_breaker=aio_request.DefaultCircuitBreaker[str,int](break_duration=1.0,sampling_duration=1.0,minimum_throughput=2,failure_threshold=0.5,),)In the case of requests count >= minimum throughput(>=2) in sampling period(1 second) the circuit breaker will open
if failed requests count/total requests count >= failure threshold(50%).v0.1.30 (2023-07-23)Removal of tracing supportDrop python 3.8 supportv0.1.29 (2023-04-27)Stop losing redirects params in headers updatev0.1.28 (2023-04-27)Add allow_redirects and max_redirects options to requestv0.1.27 (2023-02-16)Maintenance releasev0.1.26 (2022-11-02)Add python 3.11 supportv0.1.25 (2022-08-25)Reverted: URL-encode path_parameters- let user
decide what to dov0.1.24 (2022-07-04)URL-encode path_parametersv0.1.23 (2022-02-08)Reject throttling(too many requests) status codev0.1.22 (2022-01-08)Return default json expected content_type to "application/json"Release aiohttp response instead of closeValidate json content-typev0.1.21 (2022-01-05)Content type should be None in Response.json()v0.1.20 (2022-01-05)Do not expect json content type by defaultv0.1.19 (2021-11-01)Support async-timeout 4.0+v0.1.18 (2021-09-08)Reexport explicitlyv0.1.17 (2021-09-01)Fix patch/patch_json visibilityv0.1.16 (2021-09-01)Support patch methodv0.1.15 (2021-09-01)Clean up resources in single shieldv0.1.14 (2021-08-18)Keys should be materialized if dict is changed in loopv0.1.13 (2021-08-15)Circuit breakerv0.1.12 (2021-07-21)Basic repr implementationv0.1.11 (2021-07-21)Fix Request.update_headers, add Request.extend_headers#59v0.1.10 (2021-07-20)Add Response.is_json property to check whether content-type is json compatible#58Tracing support#54,Configurationof a new pipeline