aio-request


Nameaio-request JSON
Version 0.1.30 PyPI version JSON
download
home_pagehttps://github.com/Pliner/aio-request
SummaryVarious strategies for sending requests
upload_time2023-07-23 13:33:57
maintainer
docs_urlNone
authorIurii Pliner
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aio-request

This library simplifies an interaction between microservices:
1. Allows sending requests using various strategies
1. Propagates a deadline and a priority of requests
1. Exposes client/server metrics

Example:
```python
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:
1. Single attempt. Only one attempt is sent.
1. Sequential. Attempts are sent sequentially with delays between them.
1. Parallel. Attempts are sent in parallel one by one with delays between them.

Attempts count and delays are configurable.

Example:
```python
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:
```python
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:
```python
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:
```python
import aiohttp.web
import aio_request

app = aiohttp.web.Application(
    middlewares=[
        aio_request.aiohttp_middleware_factory(
            metrics_provider=aio_request.PROMETHEUS_METRICS_PROVIDER
        )
    ]
)
```

# Circuit breaker

```python
import aiohttp
import aio_request

async with aiohttp.ClientSession() as client_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 support](https://github.com/anna-money/aio-request/pull/213)
* [Drop python 3.8 support](https://github.com/anna-money/aio-request/pull/216)


## v0.1.29 (2023-04-27)

* [Stop losing redirects params in headers update](https://github.com/anna-money/aio-request/pull/204)


## v0.1.28 (2023-04-27)

* [Add allow_redirects and max_redirects options to request](https://github.com/anna-money/aio-request/pull/195)


## v0.1.27 (2023-02-16)

* [Maintenance release](https://github.com/anna-money/aio-request/compare/v0.1.26...v0.1.27)


## v0.1.26 (2022-11-02)

* [Add python 3.11 support](https://github.com/anna-money/aio-request/pull/159)


## v0.1.25 (2022-08-25)

* [Reverted: URL-encode path_parameters](https://github.com/anna-money/aio-request/pull/155) - let user
  decide what to do


## v0.1.24 (2022-07-04)

* [URL-encode path_parameters](https://github.com/anna-money/aio-request/pull/146)


## v0.1.23 (2022-02-08)

* [Reject throttling(too many requests) status code](https://github.com/anna-money/aio-request/pull/123)


## v0.1.22 (2022-01-08)

* Return default json expected content_type to "application/json"
* [Release aiohttp response instead of close](https://github.com/Pliner/aio-request/pull/108)
* [Validate json content-type](https://github.com/Pliner/aio-request/pull/109)


## v0.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 default](https://github.com/Pliner/aio-request/pull/106)


## v0.1.19 (2021-11-01)

* [Support async-timeout 4.0+](https://github.com/Pliner/aio-request/pull/86)


## v0.1.18 (2021-09-08)

* [Reexport explicitly](https://github.com/Pliner/aio-request/pull/74)


## v0.1.17 (2021-09-01)

* [Fix patch/patch_json visibility](https://github.com/Pliner/aio-request/pull/73)


## v0.1.16 (2021-09-01)

* [Support patch method](https://github.com/Pliner/aio-request/pull/72)


## v0.1.15 (2021-09-01)

* [Clean up resources in single shield](https://github.com/Pliner/aio-request/pull/71)


## v0.1.14 (2021-08-18)

* [Keys should be materialized if dict is changed in loop](https://github.com/Pliner/aio-request/pull/66)


## v0.1.13 (2021-08-15)

* [Circuit breaker](https://github.com/Pliner/aio-request/pull/65)


## v0.1.12 (2021-07-21)

* [Basic repr implementation](https://github.com/Pliner/aio-request/commit/adaa4888c3d372fa65f3dd5eb6113ab68f46de24)


## v0.1.11 (2021-07-21)

* Fix Request.update_headers, add Request.extend_headers [#59](https://github.com/Pliner/aio-request/pull/59)


## v0.1.10 (2021-07-20)

* Add Response.is_json property to check whether content-type is json compatible [#58](https://github.com/Pliner/aio-request/pull/58)
* Tracing support [#54](https://github.com/Pliner/aio-request/pull/54), 
* [Configuration](https://github.com/Pliner/aio-request/commit/f0e1904f4d87daf7c242a834168c0f1b25dd86d5) of a new pipeline

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Pliner/aio-request",
    "name": "aio-request",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "",
    "author": "Iurii Pliner",
    "author_email": "yury.pliner@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/88/68/e98b13887dfef1ac6d8285652442aa2d04c15709dc54750be43e1bc3345b/aio-request-0.1.30.tar.gz",
    "platform": "macOS",
    "description": "# aio-request\n\nThis library simplifies an interaction between microservices:\n1. Allows sending requests using various strategies\n1. Propagates a deadline and a priority of requests\n1. Exposes client/server metrics\n\nExample:\n```python\nimport aiohttp\nimport aio_request\n\nasync with aiohttp.ClientSession() as client_session:\n    client = aio_request.setup(\n        transport=aio_request.AioHttpTransport(client_session),\n        endpoint=\"http://endpoint:8080/\",\n    )\n    response_ctx = client.request(\n        aio_request.get(\"thing\"),\n        deadline=aio_request.Deadline.from_timeout(5)\n    )\n    async with response_ctx as response:\n        pass  # process response here\n```\n\n# Request strategies \nThe following strategies are supported:\n1. Single attempt. Only one attempt is sent.\n1. Sequential. Attempts are sent sequentially with delays between them.\n1. Parallel. Attempts are sent in parallel one by one with delays between them.\n\nAttempts count and delays are configurable.\n\nExample:\n```python\nimport aiohttp\nimport aio_request\n\nasync with aiohttp.ClientSession() as client_session:\n    client = aio_request.setup(\n        transport=aio_request.AioHttpTransport(client_session),\n        endpoint=\"http://endpoint:8080/\",\n    )\n    response_ctx = client.request(\n        aio_request.get(\"thing\"),\n        deadline=aio_request.Deadline.from_timeout(5),\n        strategy=aio_request.parallel_strategy(\n            attempts_count=3,\n            delays_provider=aio_request.linear_delays(min_delay_seconds=0.1, delay_multiplier=0.1)\n        )\n    )\n    async with response_ctx as response:\n        pass  # process response here\n```\n\n# Deadline & priority propagation\n\nTo enable it for the server side a middleware should be configured:\n```python\nimport aiohttp.web\nimport aio_request\n\napp = aiohttp.web.Application(middlewares=[aio_request.aiohttp_middleware_factory()])\n```\n\n# Expose client/server metrics\n\nTo enable client metrics a metrics provider should be passed to the transport:\n```python\nimport aiohttp\nimport aio_request\n\nasync with aiohttp.ClientSession() as client_session:\n    client = aio_request.setup(\n        transport=aio_request.AioHttpTransport(\n            client_session,\n            metrics_provider=aio_request.PROMETHEUS_METRICS_PROVIDER\n        ),\n        endpoint=\"http://endpoint:8080/\",\n    )\n```\n\nIt is an example of how it should be done for aiohttp and prometheus.\n\nTo enable client metrics a metrics provider should be passed to the middleware:\n```python\nimport aiohttp.web\nimport aio_request\n\napp = aiohttp.web.Application(\n    middlewares=[\n        aio_request.aiohttp_middleware_factory(\n            metrics_provider=aio_request.PROMETHEUS_METRICS_PROVIDER\n        )\n    ]\n)\n```\n\n# Circuit breaker\n\n```python\nimport aiohttp\nimport aio_request\n\nasync with aiohttp.ClientSession() as client_session:\n    client = aio_request.setup_v2(\n        transport=aio_request.AioHttpTransport(client_session),\n        endpoint=\"http://endpoint:8080/\",\n        circuit_breaker=aio_request.DefaultCircuitBreaker[str, int](\n            break_duration=1.0,\n            sampling_duration=1.0,\n            minimum_throughput=2,\n            failure_threshold=0.5,\n        ),\n    )\n```\n\nIn the case of requests count >= minimum throughput(>=2) in sampling period(1 second) the circuit breaker will open\nif failed requests count/total requests count >= failure threshold(50%).\n\n## v0.1.30 (2023-07-23)\n\n* [Removal of tracing support](https://github.com/anna-money/aio-request/pull/213)\n* [Drop python 3.8 support](https://github.com/anna-money/aio-request/pull/216)\n\n\n## v0.1.29 (2023-04-27)\n\n* [Stop losing redirects params in headers update](https://github.com/anna-money/aio-request/pull/204)\n\n\n## v0.1.28 (2023-04-27)\n\n* [Add allow_redirects and max_redirects options to request](https://github.com/anna-money/aio-request/pull/195)\n\n\n## v0.1.27 (2023-02-16)\n\n* [Maintenance release](https://github.com/anna-money/aio-request/compare/v0.1.26...v0.1.27)\n\n\n## v0.1.26 (2022-11-02)\n\n* [Add python 3.11 support](https://github.com/anna-money/aio-request/pull/159)\n\n\n## v0.1.25 (2022-08-25)\n\n* [Reverted: URL-encode path_parameters](https://github.com/anna-money/aio-request/pull/155) - let user\n  decide what to do\n\n\n## v0.1.24 (2022-07-04)\n\n* [URL-encode path_parameters](https://github.com/anna-money/aio-request/pull/146)\n\n\n## v0.1.23 (2022-02-08)\n\n* [Reject throttling(too many requests) status code](https://github.com/anna-money/aio-request/pull/123)\n\n\n## v0.1.22 (2022-01-08)\n\n* Return default json expected content_type to \"application/json\"\n* [Release aiohttp response instead of close](https://github.com/Pliner/aio-request/pull/108)\n* [Validate json content-type](https://github.com/Pliner/aio-request/pull/109)\n\n\n## v0.1.21 (2022-01-05)\n\n* Content type should be None in Response.json()\n\n\n## v0.1.20 (2022-01-05)\n\n* [Do not expect json content type by default](https://github.com/Pliner/aio-request/pull/106)\n\n\n## v0.1.19 (2021-11-01)\n\n* [Support async-timeout 4.0+](https://github.com/Pliner/aio-request/pull/86)\n\n\n## v0.1.18 (2021-09-08)\n\n* [Reexport explicitly](https://github.com/Pliner/aio-request/pull/74)\n\n\n## v0.1.17 (2021-09-01)\n\n* [Fix patch/patch_json visibility](https://github.com/Pliner/aio-request/pull/73)\n\n\n## v0.1.16 (2021-09-01)\n\n* [Support patch method](https://github.com/Pliner/aio-request/pull/72)\n\n\n## v0.1.15 (2021-09-01)\n\n* [Clean up resources in single shield](https://github.com/Pliner/aio-request/pull/71)\n\n\n## v0.1.14 (2021-08-18)\n\n* [Keys should be materialized if dict is changed in loop](https://github.com/Pliner/aio-request/pull/66)\n\n\n## v0.1.13 (2021-08-15)\n\n* [Circuit breaker](https://github.com/Pliner/aio-request/pull/65)\n\n\n## v0.1.12 (2021-07-21)\n\n* [Basic repr implementation](https://github.com/Pliner/aio-request/commit/adaa4888c3d372fa65f3dd5eb6113ab68f46de24)\n\n\n## v0.1.11 (2021-07-21)\n\n* Fix Request.update_headers, add Request.extend_headers [#59](https://github.com/Pliner/aio-request/pull/59)\n\n\n## v0.1.10 (2021-07-20)\n\n* Add Response.is_json property to check whether content-type is json compatible [#58](https://github.com/Pliner/aio-request/pull/58)\n* Tracing support [#54](https://github.com/Pliner/aio-request/pull/54), \n* [Configuration](https://github.com/Pliner/aio-request/commit/f0e1904f4d87daf7c242a834168c0f1b25dd86d5) of a new pipeline\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Various strategies for sending requests",
    "version": "0.1.30",
    "project_urls": {
        "Homepage": "https://github.com/Pliner/aio-request"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "563bb23127bee4946874e35df78396dee157e540e24959510819f2bad605dc81",
                "md5": "32cd3acfc09ea5a9ea07a20420abd3c7",
                "sha256": "59ed53808e1eaad1e5b35915488f768a65ef0eaa12b2388f30297cb4fe86a709"
            },
            "downloads": -1,
            "filename": "aio_request-0.1.30-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "32cd3acfc09ea5a9ea07a20420abd3c7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 25101,
            "upload_time": "2023-07-23T13:33:55",
            "upload_time_iso_8601": "2023-07-23T13:33:55.335822Z",
            "url": "https://files.pythonhosted.org/packages/56/3b/b23127bee4946874e35df78396dee157e540e24959510819f2bad605dc81/aio_request-0.1.30-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8868e98b13887dfef1ac6d8285652442aa2d04c15709dc54750be43e1bc3345b",
                "md5": "c94bdbb947d9d0e4aad00e8e3ea11d19",
                "sha256": "1dd34913fbbf42aec7506fb2910b59cec7abff64398c208fd860d0d6a877ae55"
            },
            "downloads": -1,
            "filename": "aio-request-0.1.30.tar.gz",
            "has_sig": false,
            "md5_digest": "c94bdbb947d9d0e4aad00e8e3ea11d19",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 21069,
            "upload_time": "2023-07-23T13:33:57",
            "upload_time_iso_8601": "2023-07-23T13:33:57.086093Z",
            "url": "https://files.pythonhosted.org/packages/88/68/e98b13887dfef1ac6d8285652442aa2d04c15709dc54750be43e1bc3345b/aio-request-0.1.30.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-23 13:33:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Pliner",
    "github_project": "aio-request",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aio-request"
}
        
Elapsed time: 0.11519s