Name | async-http-requests JSON |
Version |
0.0.5
JSON |
| download |
home_page | |
Summary | Asynchronous HTTP requests |
upload_time | 2024-01-16 18:13:06 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.9 |
license | MIT License Copyright (c) 2023 sclash - Andrea Sergi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
http
requests
api
asyncio
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Async Requests
Python library to handle asynchronous http requests, built on top of the [requests](https://requests.readthedocs.io/en/latest/) library
- [Installation](#installation)
- [Usage](#usage)
## Installation
[PyPI page](https://pypi.org/project/async-http-requests/)
```bash
pip install async-http-requests
```
## Usage
The library provide support for asynchronous http requests, using the consumer-producer pattern leveraging the built-in python modu.
Instantiate the class `AsyncHTTP` specifying a list of `RequestObject`, (you can specify `N_PRODUCERS` and `N_CONSUMERS`: default values are `10` for both)
The `RequestObject` supports all keyword arguments of the requests methods (`headers`,`params`,`data`, ...). It allows you to specify different keyword arguments across different requests
```python
from AysncRequests import AsyncHTPP, RequestObject, RequestType,
# Public API endpoint, it retrieves all public APIs listed under params specification
# Refer to this if you want to know more https://api.publicapis.org/
api = 'https://api.publicapis.org/entries'
# default N_PRODUCERS and N_CONSUMERS to 10
endpoints = [
RequestObject(url = api, params = {"title":"cat"}),
RequestObject(url = api, params = {"title":"dog"})
]
requests = AsyncHTTP(
url = endpoints
)
# specify number of producers and consumers
requests = AsyncHTTP(
url = endpoints,
N_PRODUCERS = 10,
N_CONSUMERS = 10
)
```
To get the responses you can either call the generic `async_request` method explicitly specifying the http request type by passing to the `request_type` argument a `RequestType` Enum (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`),
or you can use the `async_get`, `async_post`, `async_delete`, `async_put`, `async_patch`, `async_head` method without having to spepcify the request type.
```python
requests.async_request(
request_type=RequestType.GET,
)
requests.async_get()
```
All methods support additional fixed keyword arguments such as `headers`, `auth` etc. as per the usual requests module, in case you need certain arguments to stay fixed across requests
For the additional paramaters refer to the requests module documentation [Requests docs](https://requests.readthedocs.io/en/latest/)
```python
headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'} # Keyword arguments FIXED for all requests
# Specify the RequestType
requests.async_request(
request_type=RequestType.GET,
haeders = headers # using the same header across all the requests
)
# Using async_get
requests.async_get(headers = headers) # using the same header across all the requests
```
All methods support the use of callback functions, to be used by the consumers on the `request.Response` object generated by the producers, as they become available in the `asyncio.Queue`.
In case of unsuccessfull requests the parameter `max_retries` can be specified (default is 0).
When `max retries` is set larger than zero, any http request that has returned an error will be sent again up to the specified number of times if not successfull.
If the given requests still generates problems after all the attempts it will be pushed to the `requests.error_response` and won't be found in `requests.response`
The `max_retries` paramater can be useful when you are sending a big number of requests to the same server, in which case you can get an error just momentarily even if nothing is really wrong.
```python
def example_callaback(response: request.Response):
return response.status_code
requests.async_request(
request_type=RequestType.GET,
max_retries = 5, # retry sendign the requests 5 times for all the unsuccessfull ones
callback = example_callback,
headers = headers
)
# no retries specified -> defaults to no further attempts in case of errors
requests.async_get(
headers = headers,
callback = lambda x: x.json() # lambda as callback
)
```
- The results will be stored in a list object, where you'll find either the `requests.Response` objects, or the output of the `callback` function.
- Requests that return an error code will be saved in `requests.error_response`
- A summary of all the requests that were not successfull (if any) can be displayed summarized in a `pandas.DataFrame` object through the `requests.error_data` attribute
```python
requests.response
requests.error_response
requests.error_data
```
Check the `test.py` script for an example.
Raw data
{
"_id": null,
"home_page": "",
"name": "async-http-requests",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "http,requests,api,asyncio",
"author": "",
"author_email": "Andrea Sergi <andrea.serg1@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a0/12/2e17023679738881efe30181938084de367d97fea95a59aa576a344111b8/async-http-requests-0.0.5.tar.gz",
"platform": null,
"description": "# Async Requests\n\nPython library to handle asynchronous http requests, built on top of the [requests](https://requests.readthedocs.io/en/latest/) library \n\n\n- [Installation](#installation)\n- [Usage](#usage)\n\n## Installation\n\n[PyPI page](https://pypi.org/project/async-http-requests/)\n\n```bash\npip install async-http-requests\n```\n\n## Usage\n\nThe library provide support for asynchronous http requests, using the consumer-producer pattern leveraging the built-in python modu.\n\nInstantiate the class `AsyncHTTP` specifying a list of `RequestObject`, (you can specify `N_PRODUCERS` and `N_CONSUMERS`: default values are `10` for both)\n\nThe `RequestObject` supports all keyword arguments of the requests methods (`headers`,`params`,`data`, ...). It allows you to specify different keyword arguments across different requests \n\n```python\nfrom AysncRequests import AsyncHTPP, RequestObject, RequestType,\n\n# Public API endpoint, it retrieves all public APIs listed under params specification\n# Refer to this if you want to know more https://api.publicapis.org/\napi = 'https://api.publicapis.org/entries'\n\n# default N_PRODUCERS and N_CONSUMERS to 10\n\nendpoints = [\n RequestObject(url = api, params = {\"title\":\"cat\"}),\n RequestObject(url = api, params = {\"title\":\"dog\"})\n]\n\nrequests = AsyncHTTP(\n url = endpoints\n) \n\n\n# specify number of producers and consumers\n\nrequests = AsyncHTTP(\n url = endpoints,\n N_PRODUCERS = 10,\n N_CONSUMERS = 10\n)\n```\n\nTo get the responses you can either call the generic `async_request` method explicitly specifying the http request type by passing to the `request_type` argument a `RequestType` Enum (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`),\nor you can use the `async_get`, `async_post`, `async_delete`, `async_put`, `async_patch`, `async_head` method without having to spepcify the request type.\n\n```python\nrequests.async_request(\n request_type=RequestType.GET,\n)\n\nrequests.async_get()\n\n```\n\nAll methods support additional fixed keyword arguments such as `headers`, `auth` etc. as per the usual requests module, in case you need certain arguments to stay fixed across requests \n\nFor the additional paramaters refer to the requests module documentation [Requests docs](https://requests.readthedocs.io/en/latest/)\n\n```python\nheaders = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'} # Keyword arguments FIXED for all requests\n\n# Specify the RequestType\n\nrequests.async_request(\n request_type=RequestType.GET,\n haeders = headers # using the same header across all the requests\n)\n\n# Using async_get\n\nrequests.async_get(headers = headers) # using the same header across all the requests\n```\n\nAll methods support the use of callback functions, to be used by the consumers on the `request.Response` object generated by the producers, as they become available in the `asyncio.Queue`.\n\nIn case of unsuccessfull requests the parameter `max_retries` can be specified (default is 0). \nWhen `max retries` is set larger than zero, any http request that has returned an error will be sent again up to the specified number of times if not successfull.\nIf the given requests still generates problems after all the attempts it will be pushed to the `requests.error_response` and won't be found in `requests.response`\n\n\nThe `max_retries` paramater can be useful when you are sending a big number of requests to the same server, in which case you can get an error just momentarily even if nothing is really wrong.\n\n```python\ndef example_callaback(response: request.Response):\n return response.status_code \n\n\nrequests.async_request(\n request_type=RequestType.GET,\n max_retries = 5, # retry sendign the requests 5 times for all the unsuccessfull ones\n callback = example_callback,\n headers = headers\n)\n\n\n# no retries specified -> defaults to no further attempts in case of errors\nrequests.async_get(\n headers = headers,\n callback = lambda x: x.json() # lambda as callback\n)\n\n```\n\n- The results will be stored in a list object, where you'll find either the `requests.Response` objects, or the output of the `callback` function.\n- Requests that return an error code will be saved in `requests.error_response`\n- A summary of all the requests that were not successfull (if any) can be displayed summarized in a `pandas.DataFrame` object through the `requests.error_data` attribute\n\n```python \nrequests.response\nrequests.error_response\nrequests.error_data\n```\n\nCheck the `test.py` script for an example.\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2023 sclash - Andrea Sergi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Asynchronous HTTP requests",
"version": "0.0.5",
"project_urls": {
"Homepage": "https://github.com/sclash/AsyncRequests"
},
"split_keywords": [
"http",
"requests",
"api",
"asyncio"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9a7f57b7a35bd99e9771585f0a0b99f09155cf7774965f86bbb5cb9c15d25486",
"md5": "2037a74e20509b10b56f8373b90c4df8",
"sha256": "df561723be55980182f0d3890ebcced407f693d4fd5440ef9fbcd9aa4e5b65e0"
},
"downloads": -1,
"filename": "async_http_requests-0.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2037a74e20509b10b56f8373b90c4df8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 7928,
"upload_time": "2024-01-16T18:13:03",
"upload_time_iso_8601": "2024-01-16T18:13:03.996079Z",
"url": "https://files.pythonhosted.org/packages/9a/7f/57b7a35bd99e9771585f0a0b99f09155cf7774965f86bbb5cb9c15d25486/async_http_requests-0.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a0122e17023679738881efe30181938084de367d97fea95a59aa576a344111b8",
"md5": "c08f79907cb1cb9a5fb50be1c5834192",
"sha256": "8184d18e4290c473194b970d631267337e011a51c07e6782e7ec10a0a2b5cf12"
},
"downloads": -1,
"filename": "async-http-requests-0.0.5.tar.gz",
"has_sig": false,
"md5_digest": "c08f79907cb1cb9a5fb50be1c5834192",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 8809,
"upload_time": "2024-01-16T18:13:06",
"upload_time_iso_8601": "2024-01-16T18:13:06.452890Z",
"url": "https://files.pythonhosted.org/packages/a0/12/2e17023679738881efe30181938084de367d97fea95a59aa576a344111b8/async-http-requests-0.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-16 18:13:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sclash",
"github_project": "AsyncRequests",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "async-http-requests"
}