Saravanan666/pypi-org huggingface dataset:
Package: aiorabbit
aiorabbit is an opinionated AsyncIO RabbitMQ client forPython 3(3.7+).Project GoalsTo create a simple, robustRabbitMQclient library forAsyncIOdevelopment in Python 3.To make use of new features and capabilities in Python 3.7+.Remove some complexity in using anAMQPclient by:Abstracting away the AMQP channel and use it only as a protocol coordination mechanism inside the client.Remove thenowaitkeyword to ensure a single round-trip pattern of behavior for client usage.To automatically reconnect when a connection is closed due to an AMQP exception/error.When such a behavior is encountered, the exception is raised, but the client continues to operate if the user catches and logs the error.To automatically create a new channel when the channel is closed due to an AMQP exception/error.When such a behavior is encountered, the exception is raised, but the client continues to operate if the user catches and logs the error.To ensure correctness of API usage, including values passed to RabbitMQ in AMQ method calls.Example UseThe following demonstrates an example of using the library to publish a message with publisher confirmations enabled:importasyncioimportdatetimeimportuuidimportaiorabbitRABBITMQ_URL='amqps://guest:guest@localhost:5672/%2f'asyncdefmain():asyncwithaiorabbit.connect(RABBITMQ_URL)asclient:awaitclient.confirm_select()ifnotawaitclient.publish('exchange','routing-key','message-body',app_id='example',message_id=str(uuid.uuid4()),timestamp=datetime.datetime.utcnow()):print('Publishing failure')if__name__=='__main__':asyncio.get_event_loop().run_until_complete(main())Documentationhttp://aiorabbit.readthedocs.orgLicenseCopyright (c) 2019-2023 Gavin M. Roy
All rights reserved.Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.Python Versions Supported3.7+
Package: aioradios
aioradiosaioradio is an asynchronous API wrapper forwww.radio-browser.infoInstallationUse the package managerpipto install aioradios.pipinstallaioradiosExample usagein:fromaioradiosimportRadioBrowserasyncdefmain():rb=RadioBrowser()awaitrb.init()radio=awaitrb.search(name='UpBeatRadio',limit=1)out:[{"changeuuid":"29c0910a-2fae-4623-8054-eaee674fe602","stationuuid":"ad95f623-c7fd-4ecb-98d5-32242708ce63","name":"UpBeatRadio","url":"http://live.upbeat.pw/","url_resolved":"http://live.upbeat.pw/","homepage":"https://upbeat.pw/","favicon":"http://upbeatradio.net/UpBeat.png","tags":"","country":"UK","countrycode":"","state":"","language":"english","votes":0,"lastchangetime":"2020-06-23 12:38:08","codec":"MP3","bitrate":128,"hls":0,"lastcheckok":1,"lastchecktime":"2020-11-04 04:14:11","lastcheckoktime":"2020-11-04 04:14:11","lastlocalchecktime":"2020-11-03 19:16:54","clicktimestamp":"2020-10-22 15:09:37","clickcount":8,"clicktrend":0}]ContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.DocumentationFor documentation do:fromaioradiosimportRadioBrowserhelp(RadioBrowser())LicenseMIT
Package: aiorate
aiorateLoop frequency regulator forasynciowith an API similar torospy.Rate.This project is archived as it has been superseded byloop-rate-limiters.InstallationpipinstallaiorateUsageTheRateclass provides a non-blocking loop frequency limiter:Set the loop frequency in Hz at construction:rate = aiorate.Rate(200.0)Callawait rate.sleep()at every loop cycleHere is what it looks like in practice:importasyncioimportaiorateasyncdefmain():rate=aiorate.Rate(400.0)# HzwhileTrue:loop_time=asyncio.get_event_loop().time()print(f"Hello from loop at{loop_time:.3f}s")awaitrate.sleep()if__name__=="__main__":asyncio.run(main())Check out theexamplesfolder for more advance use cases, such as multiple loops running simultaneously at different rates.
Package: aio-rate-limiter
aio-rate-limiterRate limit a function using Redis as a backend. This is a smaller library modeled afterpython-redis-rate-limitbut it usesaioredis. Supports Python 3.6+.Installationpipinstallaio-rate-limiterExampleimportloggingfromaio_rate_limiterimportRateLimiter,TooManyRequestsimportaioredisasyncdefexample():pool=awaitaioredis.create_redis_pool("redis://localhost:6379")try:asyncwithRateLimiter(redis_pool,# Rate limit requests to a resource"name-of-external-system",# Allow up to 100 requests in 60 secondsmax_requests=100,time_window=60):asyncdo_work()exceptTooManyRequests:logging.warning("Try again later")Development# Install poetrypipinstallpoetry# Install all package dependenciespoetryinstall# Launch a shell with dependencies availablepoetryshell# Run tests (requires Redis server running at localhost:6379)pytest# When you're ready to publish...# Bump versionpoetryversion<version># Set your pypi tokenexportPOETRY_PYPI_TOKEN_PYPI='...'# Build and publishpoetrybuild
poetrypublish
Package: aioratelimits
aioratelimitsClient rate limiter. It enqueues function calls and run them as leaky bucket to
ensure specified rates.ImplementationLeaky bucket. We have one queue for requests andcountnumber of workers.
Each worker can handle one request perdelaysecondsInstallpip install aioratelimitsUseThe following code prints not more than 2 lines per second.importasynciofromaioratelimitsimportRateLimiterasyncdefcritical_resource(i:int):print('request:',i)asyncdefmain():asyncwithRateLimiter(count=2,delay=1)aslimiter:awaitasyncio.gather(*(limiter.run(critical_resource(i))foriinrange(10)))asyncio.run(main())Arguments toRateLimiter:count- how many calls can we do in the specified intervaldelay- the interval in seconds
Package: aiorazemax
Aiorazemax✉️ Async communications using AWS SNS + SQS for Python services ✨DocumentationIn-Memory event managerShow me the codefromaiorazemax.event_managerimportEventManagerclassNorthKoreaThreatCreatedEvent:def__init__(self,id,target):self.id=idself.target=targetasyncdeftrump_subscriber(event:NorthKoreaThreatCreatedEvent):print(f"North korea will attack us or{event.target}!")EventManager.subscribe(trump_subscriber,NorthKoreaThreatCreatedEvent)awaitEventManager.trigger(NorthKoreaThreatCreatedEvent(0,"Mexico"))Result:North korea will attack us or Mexico!Trigger subscribers from SQSPreconditionsSQS queue has to be subscribed to SNS topic before running the consumerCodeimportasynciofromaiorazemax.consumersimportMessageConsumerfromaiorazemax.driversimportSQSDriverfromaiorazemax.event_managerimportEventManagerfromaiorazemax.publisherimportSNSMessagePublisheraws_settings={'region_name':"",'aws_access_key_id':"",'aws_secret_access_key':"",'endpoint_url':""}classNorthKoreaThreatCreatedEvent:def__init__(self,id,target):self.id=idself.target=targetdefkp_message_to_event(event_message):message=event_message.body# Highly recommended to use Marshmallow to validatereturnNorthKoreaThreatCreatedEvent(message['body']['id'],message['body']['target_name'])mapper={'KPThreatCreated':kp_message_to_event}asyncdeftrump_subscriber(event:NorthKoreaThreatCreatedEvent):print(f"North korea will attack us or{event.target}!")asyncdefmain():EventManager.subscribe(trump_subscriber,NorthKoreaThreatCreatedEvent)queue_driver=awaitSQSDriver.build('korea-threats-queue',aws_settings)consumer=MessageConsumer(mapper,EventManager,queue_driver)publisher=awaitSNSMessagePublisher.build('korea-topic',aws_settings)awaitpublisher.publish('KPThreatCreated',{'id':21,'target_name':'Portugal'})awaitconsumer.process_message()awaitqueue_driver.close()awaitpublisher.close()if__name__=='__main__':asyncio.run(main())Result:North korea will attack us or Portugal!Installingpip install aiorazemaxRunning the testsTo run end to end tests do:make unit-tests
make integration-testsAuthorsJairo Vadillo (@jairovadillo)LicenseThis project is licensed under the MIT License - see theLICENSE.mdfile for details
Package: aiordr
Simple and fast asynchronous library for the o!rdr API.FeaturesSupport for modern async syntax (async with)Event decoratorsRate limit handlingEasy to useInstallingPython 3.9 or higher is requiredTo install the library, simply run the following commands# Linux/macOSpython3-mpipinstall-Uaiordr# Windowspy-3-mpipinstall-UaiordrTo install the development version, do the following:$gitclonehttps://github.com/NiceAesth/aiordr$cdaiordr$python3-mpipinstall-U.API Exampleimportaiordrimportasyncioasyncdefmain():client=aiordr.ordrClient(verification_key="verylongstring")awaitclient.create_render("username","YUGEN",replay_url="https://url.to.replay",)@client.on_render_addedasyncdefon_render_added(event:aiordr.models.RenderAddEvent)->None:print(event)@client.on_render_progressasyncdefon_render_progress(event:aiordr.models.RenderProgressEvent)->None:print(event)@client.on_render_failasyncdefon_render_fail(event:aiordr.models.RenderFailEvent)->None:print(event)@client.on_render_finishasyncdefon_render_finish(event:aiordr.models.RenderFinishEvent)->None:print(event)if__name__=="__main__":asyncio.run(main())ContributingPlease read theCONTRIBUTING.rstto learn how to contribute to aiordr!Acknowledgmentsdiscord.pyfor README formattingaiosusister library for the osu! API
Package: aioreadline
aioreadlinePython has a builtin readline module. However, the builtin module is difficult
to use in async Python code. This module provides an interface around the
async-compatible functions of libreadline using a ctypes wrapper.Exampleimport asyncio, atexit

async def _main():
	while True:
		line = await aiorl.getLine()
		
		if line is None or line == b"quit":
			aiorl.stop()
			loop.stop()
			break
		elif len(line) > 0:
			aiorl.add_history(line)
			print(line)

loop = asyncio.get_event_loop()
loop.create_task(_main())

aiorl = AIOReadline(prompt="> ", loop=loop, history_file=".aioreadline_history")

atexit.register(lambda: aiorl.stop())

try:
	loop.run_forever()
except KeyboardInterrupt:
	loop.stop()
Package: aiorecollect
🗑 aiorecollect: A Python 3 Library for Pinboardaiorecollectis a Python 3, asyncio-based library for the ReCollect Waste API. It allows
users to programmatically retrieve schedules for waste removal in their area, including
trash, recycling, compost, and more.Special thanks to @stealthhacker for the inspiration!InstallationpipinstallaiorecollectPython Versionsaiorecollectis currently supported on:Python 3.10Python 3.11Python 3.12Place and Service IDsTo useaiorecollect, you must know both your ReCollect Place and Service IDs.In general, cities/municipalities that utilize ReCollect will give you a way to
subscribe to a calendar with pickup dates. If you examine the iCal URL for this
calendar, the Place and Service IDs are embedded in it:webcal://recollect.a.ssl.fastly.net/api/places/PLACE_ID/services/SERVICE_ID/events.en-US.icsUsageimportasynciofromdatetimeimportdatefromaiorecollectimportClientasyncdefmain()->None:"""Run."""client=awaitClient("<PLACE ID>","<SERVICE ID>")# The client has a few attributes that you can access:client.place_idclient.service_id# Get all pickup events on the calendar:pickup_events=awaitclient.async_get_pickup_events()# ...or get all pickup events within a certain date range:pickup_events=awaitclient.async_get_pickup_events(start_date=date(2020,10,1),end_date=date(2020,10,31))# ...or just get the next pickup event:next_pickup=awaitclient.async_get_next_pickup_event()asyncio.run(main())ThePickupEventObjectThePickupEventobject that is returned from the above calls comes with three
properties:date: adatetime.datethat denotes the pickup datepickup_types: a list ofPickupTypeobjects that will occur with this eventarea_name: the name of the area in which the event is occurringThePickupTypeObjectThePickupTypeobject contains the "internal" name of the pickup typeanda
human-friendly representation when it exists:name: the internal name of the pickup typefriendly_name: the humany-friendly name of the pickup type (if it exists)Connection PoolingBy default, the library creates a new connection to ReCollect with each coroutine. If
you are calling a large number of coroutines (or merely want to squeeze out every second
of runtime savings possible), anaiohttpClientSessioncan be used for
connection pooling:importasynciofromaiohttpimportClientSessionfromaiorecollectimportClientasyncdefmain()->None:"""Run."""asyncwithClientSession()assession:client=awaitClient("<PLACE ID>","<SERVICE ID>",session=session)# Get to work...asyncio.run(main())ContributingThanks to all ofour contributorsso far!Check for open features/bugsorinitiate a discussion on one.Fork the repository.(optional, but highly recommended) Create a virtual environment:python3 -m venv .venv(optional, but highly recommended) Enter the virtual environment:source ./.venv/bin/activateInstall the dev environment:script/setupCode your new feature or bug fix on a new branch.Write tests that cover your new functionality.Run tests and ensure 100% code coverage:poetry run pytest --cov aiorecollect testsUpdateREADME.mdwith any new documentation.Submit a pull request!
Package: aio-recurring
aio-recurringRecurring coroutines using asyncioUsage:importasynciofromdatetimeimportdatetimefromaio_recurring.jobimport(recurring,run_recurring_jobs,)@recurring(every=5)asyncdefprint_info_5():print(f"[{datetime.now()}] This coroutine is rescheduled every 5 seconds")@recurring(every=10)asyncdefprint_info_10():print(f"[{datetime.now()}] This coroutine is rescheduled every 10 seconds")asyncdefmain():run_recurring_jobs()if__name__=='__main__':loop=asyncio.get_event_loop()loop.create_task(main())loop.run_forever()
Package: aiorecycle
A decorator to recycle tasks in the event loopInstallationpipinstallaiorecycleUsage exampleimportasyncioimportaiorecycle@aiorecycle.cycle()asyncdeftask():ifasyncio.get_event_loop().time()%2==0:print('make some periodic work')asyncdefmain():awaittask()awaitasyncio.sleep(3)# emulate very important workif__name__=="__main__":asyncio.run(main())Licenseaiorecyclelibrary is offered under Apache 2 license.
Package: aioredis_fastapi
aioredis_fastapiis an asynchronousredis based sessionbackend for FastAPI powered applications.🚸This repository is currently under testing, kind of production-ready.🚸🛠️ Requirementsaioredis_fastapirequires Python 3.9 or above.To install Python 3.9, I recommend usingpyenv. You can refer tothis sectionof the readme file on how to install poetry and pyenv into your linux machine.🚨 InstallationWithpip:python3.9 -m pip install aioredis-fastapior by checking out the repo and installing it withpoetry:git clone https://github.com/wiseaidev/aioredis_fastapi.git && cd aioredis_fastapi && poetry install🚸 UsagefromtypingimportAnyfromfastapiimportDepends,FastAPI,Request,Responsefromaioredis_fastapiimport(get_session_storage,get_session,get_session_id,set_session,del_session,SessionStorage,)app=FastAPI(title=__name__)@app.post("/set-session")asyncdef_set_session(request:Request,response:Response,session_storage:SessionStorage=Depends(get_session_storage),):session_data=awaitrequest.json()awaitset_session(response,session_data,session_storage)@app.get("/get-session")asyncdef_get_session(session:Any=Depends(get_session)):returnsession@app.post("/del-session")asyncdef_delete_session(session_id:str=Depends(get_session_id),session_storage:SessionStorage=Depends(get_session_storage),):awaitdel_session(session_id,session_storage)returnNone🛠️ Custom Configfromaioredis_fastapiimportsettingsfromdatetimeimporttimedeltaimportrandomsettings(redis_url="redis://localhost:6379",session_id_name="session-id",session_id_generator=lambda:str(random.randint(1000,9999)),expire_time=timedelta(days=1))🌐 Interacting with the endpointsfromhttpximportAsyncClientimportasynciofromaioredis_fastapi.configimportsettingsasyncdefmain():client=AsyncClient()r=awaitclient.post("http://127.0.0.1:8000/set-session",json=dict(a=1,b="data",c=True))r=awaitclient.get("http://127.0.0.1:8000/get-session",cookies={settings().session_id_name:"ssid"})print(r.text)returnr.textloop=asyncio.new_event_loop()asyncio.set_event_loop(loop)try:loop.run_until_complete(main())finally:loop.close()asyncio.set_event_loop(None)🎉 CreditsThe following projects were used to build and testaioredis_fastapi.pythonpoetrypytestflake8coveragerstcheckmypypytestcovtoxisortblackprecommit👋 ContributeIf you are looking for a way to contribute to the project, please refer to theGuideline.📝 LicenseThis program and the accompanying materials are made available under the terms and conditions of theGNU GENERAL PUBLIC LICENSE.
Package: aioredis-lock
aioredis_lockImplementation of distributed locking withaioredis, an asyncio based redis client.This is a standalone lib until, and if,aio-libs/aioredis#573is accepted.UsageYou need anaioredis.RedisConnectionoraioredis.ConnectionsPoolalready created.Mutexfromaioredis_lockimportRedisLock,LockTimeoutErrortry:asyncwithRedisLock(pool,key="foobar",# how long until the lock should expire (seconds). this can be extended# via `await lock.extend(30)`timeout=30,# you can customize how long to allow the lock acquisitions to be# attempted.wait_timeout=30,)aslock:# If you get here, you now have a lock and are the only program that# should be running this code at this moment.# do some work...# we may want it longer...awaitlock.extend(30)exceptLockTimeoutError:# The lock could not be acquired by this worker and we should give uppassSimple Leader/Follower(s)Let's suppose you need a simple leader/follower type implementation where you have a number of web-workers but just want 1 to preform a repeated task. In the case the leader fails someone else should pick up the work. Simply passwait_timeout=Noneto RedisLock allowing the worker to keep trying to get a lock for when the leader eventually fails. The main complication here is extending the lock and validating the leader still owns it.fromaioredis_lockimportRedisLock# if the lock is lost, we still want to be a followerwhileTrue:# wait indefinitely to acquire a lockasyncwithRedisLock(pool,"shared_key",wait_timeout=None)aslock:# hold the lock as long as possiblewhileTrue:ifnotawaitlock.is_owner():logger.debug("We are no longer the lock owner, falling back")break# do some workifnotawaitlock.renew():logger.debug("We lost the lock, falling back to follower mode")breakThis mostly delegates the work of selecting and more importantly promoting leaders.
Package: aioredis-models
aioredis-modelsA wrapper overaioredisthat modelsRedisdata as simple data structures.Supported data structuresKeysStringsListsHash mapsSetsDouble hash mapsRequirementsPython 3.6+aioredisrequirementsDocumentationDetailed documentation is available athttps://aioredis-models.readthedocs.io/.UsageConstruction of all data structures requires at least anaioredis.Redisinstance
and a key. For example, to create aRedisString:fromaioredis-modelsimportRedisStringredis_string=RedisString(redis,'my-string')Once a model has been constructed, various functions can be used to interact with it.importaioredisfromaioredis-modelsimportRedisStringasyncdefdo_work(redis_string:RedisString):stored_value=awaitredis_string.get()print(stored_value)ContributingThe library is currently in very early stages of development and there is a lot of room for growth.
As such, contributions are welcome. To contribute, create a pull request into themainbranch.
Make sure the tests pass and there are no linting errors. Also, please update documentation, if
needed.TestingThe easiest way to run the tests is throughdocker-composeandDocker:docker-composeup--buildunit-testTo run directly on the host:pip3install-rrequirements.txt
tox-eunit-py39End-to-end tests can also be run withdocker-compose:docker-composeup--builde2e-testLintingSimilar to testing, linting rules can be run through:docker-composeup--buildlintTo run directly on the host:pip3install-rrequirements.txt
pylintaioredis_modelsDocumentationDocumentation can get regenerated by starting thegenerate-docsservice in docker-compose:docker-composeup--buildgenerate-docsTo run directly on the host:pip3install-rrequirements.txt
sphinx-apidoc-f-odocs/sourceaioredis_models&&(cddocs&&makehtml)LicenseThis library is offered under the MIT license.
Package: aioredisorm
AIORedisORMA Python class for interacting with Redis using asyncio and aioredis.InstallationYou can install AIORedisORM using pip:pip install aioredisormExample UsageHere is an example that demonstrates the usage of the AIORedisORM class:importasynciofromaioredisormimportAIORedisORMasyncdefmain():# Add prefix to beging of each keyredis_client=AIORedisORM(key_prefix='my_prefix')awaitredis_client.connect()# Set a valueawaitredis_client.set_value('my_key','my_value',ex=12)# Get a valueresult=awaitredis_client.get_value('my_key')print(result)# Output: b'my_value'# Set a hashawaitredis_client.set_hash('my_hash',{'key1':'value1','key2':'value2','key3':13})# Set a hash with expirationawaitredis_client.set_hash('my_hash',{'key1':'value1','key2':'value2','key3':13},ex=5)# Get a hashhash_result=awaitredis_client.get_hash('my_hash')print(hash_result)# Output: {b'key1': b'value1', b'key2': b'value2', b'key3': b'123'}awaitasyncio.sleep(5)# Wait for the expiration to passhash_result=awaitredis_client.get_hash('my_hash')print(hash_result)# Output: {}# Decode the bytes to a string if neededresult=result.decode('utf-8')print(result)# Output: 'my_value'# Set a setawaitredis_client.set_set('my_set','value1','value2','value3')# Get a setset_result=awaitredis_client.get_set('my_set')print("set_result",set_result)# Output: {b'value1', b'value2', b'value3'}# Transaction examplecommands=[('set','key1','value1'),('set','key2','value2')]results=awaitredis_client.execute_transaction(commands)print(results)# Output: [(True, True)]# Set a listawaitredis_client.set_list('my_list','value1','value2','value3')# Get a listlist_result=awaitredis_client.get_list('my_list')print(list_result)# Output: [b'value1', b'value2', b'value3']# Get the expiration time of a keyttl,pttl=awaitredis_client.get_key_expiration('key1')print(f"TTL of 'my_key':{ttl}seconds")print(f"PTTL of 'my_key':{pttl}milliseconds")# Close the connectionawaitredis_client.close()# Run the async exampleasyncio.run(main())Make sure to import the AIORedisORM class and replace 'my_prefix' with your desired key prefix.