Name | aiorezka JSON |
Version |
1.2.0
JSON |
| download |
home_page | |
Summary | |
upload_time | 2023-12-30 13:12:48 |
maintainer | |
docs_url | None |
author | iYasha |
requires_python | >=3.8,<4.0 |
license | |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# aiorezka
## Installation
### Without cache
```bash
pip install aiorezka
```
### With cache
_It's recommended to use cache, because it will reduce load on Rezka API._
```bash
pip install aiorezka[request_cache]
```
## Usage
```python
from aiorezka.api import RezkaAPI
import asyncio
async def main():
async with RezkaAPI() as api:
details = await api.movie_detail.get(
'https://rezka.ag/cartoons/comedy/2136-rik-i-morti-2013.html'
)
print(details)
asyncio.run(main())
```
You can find more examples in [examples](examples) directory.
## Configuration
### Hostname configuration
You can configure hostname for requests. By default it will use `rezka.ag` hostname.
To change it, you can pass environment variable `REZKA_HOSTNAME` or change it in code:
```python
import aiorezka
aiorezka.host = 'rezka.co'
```
### Concurrency configuration
You can configure concurrency for API client, basically it will limit number of concurrent requests via asyncio.Semaphore.
By default it will use 60 concurrent requests.
To change it, you can pass environment variable `REZKA_CONCURRENCY_LIMIT` or change it in code:
```python
import aiorezka
aiorezka.concurrency_limit = 100
```
### Retry configuration
You can configure retry policy for requests. By default it will retry 3 times with 1 * (backoff ** retry_no) second delay.
To change it, you can pass environment variables, such as `REZKA_MAX_RETRY` and `REZKA_RETRY_DELAY` or change it in code:
```python
import aiorezka
aiorezka.max_retry = 5
aiorezka.retry_delay = 2
```
### Cache configuration
You can configure cache for requests. By default, it will use `aiorezka.cache.QueryCache` + `aiorezka.cache.DiskCacheThreadProvider` with 1 day TTL.
Cache will periodically save to disk, so you can use it between restarts.
#### use_cache
Enable or disable cache. By default, it's disabled.
```python
import aiorezka
aiorezka.use_cache = False # disable cache
```
or use environment variable `REZKA_USE_CACHE`
#### cache_directory
Directory where cache will be stored. By default, it's `/tmp/aiorezka_cache`.
```python
import aiorezka
aiorezka.cache_directory = '/tmp/aiorezka_cache'
```
or use environment variable `REZKA_CACHE_DIRECTORY`
#### memcache_max_len
Max number of items in memory cache. When it's reached, it will be saved to disk.
By default, it's 1000.
```python
import aiorezka
aiorezka.memcache_max_len = 1000
```
or use environment variable `REZKA_MEMCACHE_MAX_LEN`
#### cache_ttl
TTL for cache objects.
By default, it's 1 day.
```python
import aiorezka
aiorezka.cache_ttl = 60 * 60 * 24 # 1 day
```
or use environment variable `REZKA_CACHE_TTL`
#### max_open_files
Max number of open files for cache. It's used for `aiorezka.cache.DiskCacheThreadProvider`. When app starts cache will be rebuilt on disk, so it will open a lot of files to check if they are expired.
By default, it's 5000.
```python
import aiorezka
aiorezka.max_open_files = 5000
```
or use environment variable `REZKA_MAX_OPEN_FILES`
You can disable cache rebuild on start, then TTL will be ignored.
```python
from aiorezka.api import RezkaAPI
async def main():
async with RezkaAPI(cache_rebuild_on_start=False) as api:
pass
```
### Logging configuration
You can configure logging for aiorezka. By default, it will use `logging.INFO` level.
```python
import aiorezka
aiorezka.log_level = "DEBUG"
```
or use environment variable `REZKA_LOG_LEVEL`
## Debugging
### Measure RPS
Measure requests per second, use it only for debug purposes.
```python
import asyncio
from aiorezka.api import RezkaAPI
from aiorezka.cli import measure_rps
@measure_rps
async def main():
async with RezkaAPI() as api:
movies = await api.movie.iter_pages(range(1, 10), chain=True)
detailed_movies = await api.movie_detail.many(movies)
for movie in detailed_movies:
attributes = '\n'.join([f'{attr["key"]}: {attr["value"]}' for attr in movie.attributes])
print(f'{movie.title}\n{attributes}\n')
if __name__ == '__main__':
asyncio.run(main())
```
Output will look like:
```bash
[main][333 requests in 37.82s] 8.81 rps
```
Raw data
{
"_id": null,
"home_page": "",
"name": "aiorezka",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "iYasha",
"author_email": "33287747+iYasha@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/34/7a/0d8b57edc16bbe02477286443e362629e1ee745de6d3d01045c6ef6821f8/aiorezka-1.2.0.tar.gz",
"platform": null,
"description": "# aiorezka\n\n## Installation\n\n### Without cache\n```bash\npip install aiorezka\n```\n\n### With cache\n_It's recommended to use cache, because it will reduce load on Rezka API._\n\n```bash\npip install aiorezka[request_cache]\n```\n\n## Usage\n```python\nfrom aiorezka.api import RezkaAPI\nimport asyncio\n\nasync def main():\n async with RezkaAPI() as api:\n details = await api.movie_detail.get(\n 'https://rezka.ag/cartoons/comedy/2136-rik-i-morti-2013.html'\n )\n print(details)\n\nasyncio.run(main())\n```\nYou can find more examples in [examples](examples) directory.\n\n## Configuration\n### Hostname configuration\nYou can configure hostname for requests. By default it will use `rezka.ag` hostname.\nTo change it, you can pass environment variable `REZKA_HOSTNAME` or change it in code:\n```python \nimport aiorezka\n\naiorezka.host = 'rezka.co'\n```\n\n### Concurrency configuration\nYou can configure concurrency for API client, basically it will limit number of concurrent requests via asyncio.Semaphore.\nBy default it will use 60 concurrent requests.\nTo change it, you can pass environment variable `REZKA_CONCURRENCY_LIMIT` or change it in code:\n```python\nimport aiorezka\n\naiorezka.concurrency_limit = 100\n```\n\n### Retry configuration\nYou can configure retry policy for requests. By default it will retry 3 times with 1 * (backoff ** retry_no) second delay.\nTo change it, you can pass environment variables, such as `REZKA_MAX_RETRY` and `REZKA_RETRY_DELAY` or change it in code:\n```python\nimport aiorezka\n\naiorezka.max_retry = 5\naiorezka.retry_delay = 2\n```\n\n### Cache configuration\nYou can configure cache for requests. By default, it will use `aiorezka.cache.QueryCache` + `aiorezka.cache.DiskCacheThreadProvider` with 1 day TTL.\nCache will periodically save to disk, so you can use it between restarts.\n\n\n#### use_cache\nEnable or disable cache. By default, it's disabled.\n```python\nimport aiorezka\n\naiorezka.use_cache = False # disable cache\n```\nor use environment variable `REZKA_USE_CACHE`\n\n#### cache_directory\nDirectory where cache will be stored. By default, it's `/tmp/aiorezka_cache`.\n```python\nimport aiorezka\n\naiorezka.cache_directory = '/tmp/aiorezka_cache'\n```\nor use environment variable `REZKA_CACHE_DIRECTORY`\n\n#### memcache_max_len\nMax number of items in memory cache. When it's reached, it will be saved to disk. \n\nBy default, it's 1000.\n```python\nimport aiorezka\n\naiorezka.memcache_max_len = 1000\n```\nor use environment variable `REZKA_MEMCACHE_MAX_LEN`\n\n#### cache_ttl\nTTL for cache objects.\n\nBy default, it's 1 day.\n```python\nimport aiorezka\n\naiorezka.cache_ttl = 60 * 60 * 24 # 1 day\n```\nor use environment variable `REZKA_CACHE_TTL`\n\n#### max_open_files\nMax number of open files for cache. It's used for `aiorezka.cache.DiskCacheThreadProvider`. When app starts cache will be rebuilt on disk, so it will open a lot of files to check if they are expired.\n\nBy default, it's 5000.\n```python\nimport aiorezka\n\naiorezka.max_open_files = 5000\n```\nor use environment variable `REZKA_MAX_OPEN_FILES`\n\nYou can disable cache rebuild on start, then TTL will be ignored.\n```python\nfrom aiorezka.api import RezkaAPI\n\nasync def main():\n async with RezkaAPI(cache_rebuild_on_start=False) as api:\n pass\n```\n\n### Logging configuration\nYou can configure logging for aiorezka. By default, it will use `logging.INFO` level.\n```python\nimport aiorezka\n\naiorezka.log_level = \"DEBUG\"\n```\nor use environment variable `REZKA_LOG_LEVEL`\n\n## Debugging\n### Measure RPS\nMeasure requests per second, use it only for debug purposes.\n```python\nimport asyncio\n\nfrom aiorezka.api import RezkaAPI\nfrom aiorezka.cli import measure_rps\n\n\n@measure_rps\nasync def main():\n async with RezkaAPI() as api:\n movies = await api.movie.iter_pages(range(1, 10), chain=True)\n detailed_movies = await api.movie_detail.many(movies)\n for movie in detailed_movies:\n attributes = '\\n'.join([f'{attr[\"key\"]}: {attr[\"value\"]}' for attr in movie.attributes])\n print(f'{movie.title}\\n{attributes}\\n')\n\nif __name__ == '__main__':\n asyncio.run(main())\n```\nOutput will look like:\n```bash\n[main][333 requests in 37.82s] 8.81 rps\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "",
"version": "1.2.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a868a7f70e2a8ce52c034cf5e426a975d473c3e248bfff6b975d96146953fc61",
"md5": "1d71f64142fdc55bf6690abaff4accc9",
"sha256": "fbca6f22511190ce631653133b54cc5056219e9db5506c2cd0087789f7a73e34"
},
"downloads": -1,
"filename": "aiorezka-1.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1d71f64142fdc55bf6690abaff4accc9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 18304,
"upload_time": "2023-12-30T13:12:47",
"upload_time_iso_8601": "2023-12-30T13:12:47.107891Z",
"url": "https://files.pythonhosted.org/packages/a8/68/a7f70e2a8ce52c034cf5e426a975d473c3e248bfff6b975d96146953fc61/aiorezka-1.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "347a0d8b57edc16bbe02477286443e362629e1ee745de6d3d01045c6ef6821f8",
"md5": "36d85d56ad1e25451913c646061d904a",
"sha256": "2566eb021ab4c57ce98b6561e3c9700c992120c268ceb0cedc96c74ffd7d8c73"
},
"downloads": -1,
"filename": "aiorezka-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "36d85d56ad1e25451913c646061d904a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 15514,
"upload_time": "2023-12-30T13:12:48",
"upload_time_iso_8601": "2023-12-30T13:12:48.647299Z",
"url": "https://files.pythonhosted.org/packages/34/7a/0d8b57edc16bbe02477286443e362629e1ee745de6d3d01045c6ef6821f8/aiorezka-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-30 13:12:48",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "aiorezka"
}