Package: aiorezka
aiorezkaInstallationWithout cachepipinstallaiorezkaWith cacheIt's recommended to use cache, because it will reduce load on Rezka API.pipinstallaiorezka[request_cache]Usagefromaiorezka.apiimportRezkaAPIimportasyncioasyncdefmain():asyncwithRezkaAPI()asapi:details=awaitapi.movie_detail.get('https://rezka.ag/cartoons/comedy/2136-rik-i-morti-2013.html')print(details)asyncio.run(main())You can find more examples inexamplesdirectory.ConfigurationHostname configurationYou can configure hostname for requests. By default it will userezka.aghostname.
To change it, you can pass environment variableREZKA_HOSTNAMEor change it in code:importaiorezkaaiorezka.host='rezka.co'Concurrency configurationYou 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 variableREZKA_CONCURRENCY_LIMITor change it in code:importaiorezkaaiorezka.concurrency_limit=100Retry configurationYou 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 asREZKA_MAX_RETRYandREZKA_RETRY_DELAYor change it in code:importaiorezkaaiorezka.max_retry=5aiorezka.retry_delay=2Cache configurationYou can configure cache for requests. By default, it will useaiorezka.cache.QueryCache+aiorezka.cache.DiskCacheThreadProviderwith 1 day TTL.
Cache will periodically save to disk, so you can use it between restarts.use_cacheEnable or disable cache. By default, it's disabled.importaiorezkaaiorezka.use_cache=False# disable cacheor use environment variableREZKA_USE_CACHEcache_directoryDirectory where cache will be stored. By default, it's/tmp/aiorezka_cache.importaiorezkaaiorezka.cache_directory='/tmp/aiorezka_cache'or use environment variableREZKA_CACHE_DIRECTORYmemcache_max_lenMax number of items in memory cache. When it's reached, it will be saved to disk.By default, it's 1000.importaiorezkaaiorezka.memcache_max_len=1000or use environment variableREZKA_MEMCACHE_MAX_LENcache_ttlTTL for cache objects.By default, it's 1 day.importaiorezkaaiorezka.cache_ttl=60*60*24# 1 dayor use environment variableREZKA_CACHE_TTLmax_open_filesMax number of open files for cache. It's used foraiorezka.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.importaiorezkaaiorezka.max_open_files=5000or use environment variableREZKA_MAX_OPEN_FILESYou can disable cache rebuild on start, then TTL will be ignored.fromaiorezka.apiimportRezkaAPIasyncdefmain():asyncwithRezkaAPI(cache_rebuild_on_start=False)asapi:passLogging configurationYou can configure logging for aiorezka. By default, it will uselogging.INFOlevel.importaiorezkaaiorezka.log_level="DEBUG"or use environment variableREZKA_LOG_LEVELDebuggingMeasure RPSMeasure requests per second, use it only for debug purposes.importasynciofromaiorezka.apiimportRezkaAPIfromaiorezka.cliimportmeasure_rps@measure_rpsasyncdefmain():asyncwithRezkaAPI()asapi:movies=awaitapi.movie.iter_pages(range(1,10),chain=True)detailed_movies=awaitapi.movie_detail.many(movies)formovieindetailed_movies:attributes='\n'.join([f'{attr["key"]}:{attr["value"]}'forattrinmovie.attributes])print(f'{movie.title}\n{attributes}\n')if__name__=='__main__':asyncio.run(main())Output will look like:[main][333requestsin37.82s]8.81rps