Saravanan666/pypi-org huggingface dataset:
Package: asyncio-rpc
Asyncio-rpc: Remote procedure calling frameworkThe Python package for the asyncio remote procedure callingFree software: BSD licenseDocumentation:https://asyncio-rpc.readthedocs.io.OverviewFeaturesAsyncio RPC client/serverMsgpack serialization with option to use own dataclasses (Python 3.8)Redis communication layerOther serialization methods and communication layers can be addedExamplesThe examples can be run from this directory, for the dataclass example
(using localhost as redis host):>>> python3.8 -m examples.dataclass.server localhost
>>> python3.8 -m examples.dataclass.client localhostTesting>>> docker-compose run pytest --cov=asyncio_rpc --cov-report=html0.2.0 (2024-01-02)Droppedaioredispackage, useredispackage instead.Github actions for unit-tests & linting.Numpy is optional.0.1.11 (2023-07-06)Add support for RPC client graceful shutdown.0.1.10 (2021-02-26)Disabled logging errors for missing Asyncio futures
for subscriptions.0.1.9 (2021-02-22)Bugfix: asyncio future that waits for return RPC message needs
to be created before sending RPC message to RPC server.Added debug logging statements.0.1.8 (2021-02-05)Add numpy int32 and int64 serializer.0.1.7 (2020-01-10)When a message from the client has not been received by
a server it raises a NotReceived exception instead of
an assert error.0.1.6 (2019-12-30)Added pub/sub support to allow sending continuous updates
from the server for a client subscriptionAdd slice serialization/deserialization support0.1.5 (2019-12-23)Server.serve() methode respawns on internal tasks errorsBetter error handling in server.0.1.4 (2019-10-03)Client now raises RPCTimeoutError if the result of a RPC call took to long to
be received.Client.serve() method respawns internal tasks on errors.0.1.3 (2019-08-21)Verbose feedback on assertion error while trying to unpack dataclasses.0.1.2 (2019-07-04)Fixed bug with bytes/str serialization/deserialization0.1.1 (2019-04-29)Added channel override option in client.rpc_call0.1.0 (2019-03-20)first pypi release
Package: asyncio-run-in-process
asyncio-run-in-processSimple asyncio friendly replacement for multiprocessingRead more in thedocumentation on ReadTheDocs.View the change log.Quickstartpipinstallasyncio-run-in-processDeveloper SetupIf you would like to hack on asyncio-run-in-process, please check out theSnake Charmers
Tactical Manualfor information on how we do:TestingPull RequestsCode StyleDocumentationDevelopment Environment SetupYou can set up your dev environment with:gitclonegit@github.com:ethereum/asyncio-run-in-process.gitcdasyncio-run-in-process
virtualenv-ppython3venv
.venv/bin/activate
pipinstall-e.[dev]Testing SetupDuring development, you might like to have tests run on every file save.Show flake8 errors on file change:# Test flake8when-changed-v-s-r-1asyncio_run_in_process/tests/-c"clear; flake8 asyncio_run_in_process tests && echo 'flake8 success' || echo 'error'"Run multi-process tests in one command, but without color:# in the project root:pytest--numprocesses=4--looponfail--maxfail=1# the same thing, succinctly:pytest-n4-f--maxfail=1Run in one thread, with color and desktop notifications:cdvenv
ptw--onfail"notify-send -t 5000 'Test failure ⚠⚠⚠⚠⚠' 'python 3 test on asyncio-run-in-process failed'"../tests../asyncio_run_in_processRelease setupFor Debian-like systems:apt install pandocTo release a new version:makereleasebump=$$VERSION_PART_TO_BUMP$$How to bumpversionThe version format for this repo is{major}.{minor}.{patch}for stable, and{major}.{minor}.{patch}-{stage}.{devnum}for unstable (stagecan be alpha or beta).To issue the next version in line, specify which part to bump,
likemake release bump=minorormake release bump=devnum. This is typically done from the
master branch, except when releasing a beta (in which case the beta is released from master,
and the previous stable branch is released from said branch). To include changes made with each
release, update "docs/releases.rst" with the changes, and apply commit directly to master
before release.If you are in a beta version,make release bump=stagewill switch to a stable.To issue an unstable version when the current version is stable, specify the
new version explicitly, likemake release bump="--new-version 4.0.0-alpha.1 devnum"
Package: asyncio-sse
SSE===Simple asyncio/aiohttp wrapper for Server-Sent Events.Usage-----Sending events:```pythonimport asyncioimport sseclass Handler(sse.Handler):@asyncio.coroutinedef handle_request(self):yield from asyncio.sleep(2)self.send('foo')yield from asyncio.sleep(2)self.send('bar', event='wakeup')start_server = sse.serve(Handler, 'localhost', 8888)asyncio.get_event_loop().run_until_complete(start_server)asyncio.get_event_loop().run_forever()```Validating incoming requests:```pythonclass Handler(sse.Handler):def validate_sse(self):super().validate_sse()# use self.request / self.payloadif not self.request.path.startswith('/live'):raise sse.SseException()```Sending JSON data:```pythonclass Handler(sse.Handler):@asyncio.coroutinedef handle_request(self):self.send({'foo': 'bar'})```Sending IDs / event names / retry information:```pythonclass Handler(sse.Handler):@asyncio.coroutinedef handle_request(self):self.send('some data', id=12345, event='something', retry=10000)```
Package: asyncio-subprocess-run
asyncio-subprocess-runThis is asyncio drop-in replacement forsubprocess.run, which is expected to be inasyncio.subprocess.run, but it isn't.For documentation seehttps://docs.python.org/3/library/subprocess.html#subprocess.runInstallpip3installasyncio-subprocess-runUsagefromasyncio_subprocess_runimportrunasyncdefget_uid():returnint((awaitrun(['id','-u'],check=True,text=True,capture_output=True)).stdout.strip())
Package: asyncio-task-logger
asyncio-task-loggerAllows logging on long-running tasks that throw an exception but are still loaded into memory. By default, a task's future doesn't spit out exceptions until it gets garbage collected or completed. This is a problem for long-running tasks.Where this code came fromThis solution was created byQuantlane, but as they didn't seem to be hosting it on PyPI and it would be convenient for me (and probably others) to have it on PyPI, I created this package.Link to the original article on Quantlane's website
Package: asyncio-taskpool
asyncio-taskpoolDynamically manage pools of asyncio tasksFull documentation available atRtD.ContentsContentsSummaryUsageInstallationDependenciesTestingLicenseSummaryAtask poolis an object with a simple interface for aggregating and dynamically managing asynchronous tasks.With an interface that is intentionally similar to themultiprocessing.Poolclass from the standard library, theTaskPoolprovides you such methods asapply,map, andstarmapto execute coroutines concurrently asasyncio.Taskobjects. There is no limitation imposed on what kind of tasks can be run or in what combination, when new ones can be added, or when they can be cancelled.For a more streamlined use-case, theSimpleTaskPoolprovides an even more intuitive and simple interface at the cost of flexibility.If you need control over a task pool at runtime, you can launch an asynchronousControlServerto be able to interface with the pool from an outside process or via a network, and stop/start tasks within the pool as you wish.UsageGenerally speaking, a task is added to a pool by providing it with a coroutine function reference as well as the arguments for that function. Here is what that could look like in the most simplified form:fromasyncio_taskpoolimportSimpleTaskPool...asyncdefwork(_foo,_bar):...asyncdefmain():pool=SimpleTaskPool(work,args=('xyz',420))pool.start(5)...pool.stop(3)...awaitpool.gather_and_close()Since one of the main goals ofasyncio-taskpoolis to be able to start/stop tasks dynamically or "on-the-fly",mostof the associated methods are non-blockingmostof the time. A notable exception is thegather_and_closemethod for awaiting the return of all tasks in the pool. (It is essentially a glorified wrapper around theasyncio.gatherfunction.)For working and fully documented demo scripts seeUSAGE.md.Installationpipinstallasyncio-taskpoolDependenciesPython Version 3.8+, tested on LinuxTestingInstallcoveragewithpip, then execute thecov.shshell script to run all unit tests and save the coverage report.Licenseasyncio-taskpoolis licensed under theGNU LGPL version 3.0specifically.The full license texts for theGNU GPLv3.0and theGNU LGPLv3.0are included in this repository. If not, seehttps://www.gnu.org/licenses/.© 2023 Daniil Fajnberg
Package: asyncio-task-queues
asyncio-task-queuesasyncio-task-queuesis an asyncio-compatible, simple distributed task queue system written in pythonNOTE: Still in very early stages.Documentation:https://benfiola.github.io/asyncio-task-queues/Source Code:https://github.com/benfiola/async-task-queuesFeaturesNativeasyncioimplementationCo-operative multi-taskingTask cancellationProvides integrations into popular frameworksFastAPIAPIRouterClickGroupFlaskBlueprintExtensible architectureAbstractBrokerinterface for unique broker implementationsMiddlewarefor in-flight modificationsEvent Systemfor monitoringStrongly-typedParamSpec/TypeVar-backed task definitionsEnum-backed Queue typehints and warningsProtocol-based event callbacksQuickstartfromenumimportEnumfromasyncio_task_queuesimportApp,Schedule,redis# define queuesclassQueue(str,Enum):Default="default"Other="other"# create broker and appredis_url="redis://:password@localhost:6379/0"broker=redis.Broker(redis_url)app=App(__name__,broker=broker,queue_default=Queue.Default)# define a scheduled task@app.scheduled_task(Schedule.cron("* * * * *"))asyncdefasync_task(val:str):print(f"{val}")# run a workerasyncdefworker():awaitasyncio.run_worker({Queue.Default,Queue.Other})# enqueue jobs as a clientasyncdefclient():task=app.create_task(async_task).with_args(val=1)awaitapp.enqueue(task)
Package: asyncio-tcp-messages
A library for developing applications with a message-based protocol on top of TCP based on asyncio.Opens the possibility of adding controllers that are responsible for specific commands, the ability to define and validate command arguments.First, you need to create an instance of the App classimport asyncio
from asyncio_tcp_messages import App

app = App()

#Your code

if __name__ == '__main__':
    asyncio.run(app.run())Here are some usage examples. You can use pydantic BaseModel subclasses for data validation.import asyncio
from asyncio_tcp_messages import App
import pydantic

app = App()


class Person(pydantic.BaseModel):
    name: str = pydantic.Field(..., min_length=2, max_length=250, description="The person's name must be at least 2 "
                                                                              "and at most 250 characters")
    age: int = pydantic.Field(..., ge=0, lt=200, description="The person's age must be greater or equal to zero "
                                                             "and lesser than 250")
    funs: list[str] = pydantic.Field(default_factory=list, title="The activities person likes to do")
    salary: int = pydantic.Field(None, gt=0, description="The person's salary must be greater than zero")

    def __str__(self) -> str:
        return f'{self.name} is {self.age} years old with {self.salary}$ salary and favourite activities: {self.funs}'


@app.command(name='sum')
async def custom_sum(user_id: int, arg1: int, arg2: int) -> str:
    return str(arg1 + arg2)


@app.command()
async def add_person(user_id: int, person: Person):
    people.append(person)


@app.command()
async def get_person(user_id: int, name: str) -> str:
    return '\n'.join(str(person) for person in people if person.name == name)


if __name__ == '__main__':
    asyncio.run(app.run())
Package: asyncio-tcp-messages-team-2
Как использоватьУстановка:pip install asyncio_tcp_messages_team_2Пример сервера:В начале объявляем класс MySocketLib с ip и портом. После чего регистрируем функции, которые вам нужны, для
регистраций команды нужно указать декоратор @app.command (Если хотите получить адрес клиента, укажите первым
аргументом addr с тайп хитом tuple пример def get_addr(addr: tuple))import asynciofrom asyncio_tcp_messages_team_2.main import MySocketLibapp = MySocketLib('127.0.0.1', 8889)ter = {}@app.command
async def set_data(key: str, val: int):
await ter[key] = val@app.command
async def get_data(key: str):
return ter[key]asyncio.run(app.run())Пример клиента:import asyncioasync def tcp_client():
reader, writer = await asyncio.open_connection('127.0.0.1', 8889)while True:
     message = input("Send: ") + "\n"
     if not message:
         break
     writer.write(message.encode())
     await writer.drain()
     data = await reader.readline()
     print(data.decode())
 print('Close the connection')
 writer.close()async def main():
await asyncio.gather(tcp_client())ifname== 'main':
asyncio.run(main())Пример работы:set_data --key key val --val 21 12ok
get_data --key key --val 21
12
Package: asyncio-telnet
Python Telnet Utility: asyncio-poweredTheasyncio-telnetlibrary designed for convenient interaction with Telnet devices in both synchronous and asynchronous modes, making the process straightforward and flexible in various usage scenarios.Support for Asynchrony and Synchrony: Harness the power of asyncio for efficient and non-blocking communication with Telnet servers. With this library, you have the option to choose between asynchronous and synchronous modes, depending on the requirements of your project.Ease of Use: The library provides a user-friendly interface for both synchronous and asynchronous cases, making it adaptable to different project needs.Telnet Protocol Handling: Transparently handles the intricacies of the Telnet protocol, allowing you to focus on the logic of your application.Flexible Integration: Easily integrate Telnet functionality into your Python applications with a simple API.InstallationYou can install the library using pip. Make sure you have Python 3.6 or later installed.pip install asyncio-telnetUsageExample: Asynchronous Telnet Connection with Default Timeoutimportasynciofromasyncio_telnetimportTelnetasyncdefmain():tn=Telnet()awaittn.open('example.com')awaittn.write(b'Vladimir\r\n')response=awaittn.read_until_eof()awaittn.close()returnresponseif__name__=='__main__':result=asyncio.run(main())print(result)# Example of successful execution:# b'\n***************** User Access Login ********************\r\n\r\nUser:'Example: Synchronous Telnet Connectionfromasyncio_telnetimportTelnetdefmain():tn=Telnet(sync_mode=True)tn.open('example.com')response=tn.read_until_eof()tn.close()returnresponseif__name__=='__main__':result=main()print(result)# Example of successful execution:# b'\n***************** User Access Login ********************\r\n\r\nUser:'Example: Asynchronous Telnet Connection with Custom Timeout.By default, the timeout is set to 30 seconds.importasynciofromasyncio_telnetimportTelnetasyncdefmain():tn=Telnet(timeout=5)try:awaittn.open('example.com')response=awaittn.read_until_eof()awaittn.close()returnresponseexceptValueErrorase:print(f"Example of a timeout occurrence:{e}")if__name__=='__main__':asyncio.run(main())# Example response:# Example of a timeout occurrence: Timeout connecting to example.com:23Example: Asynchronous Telnet Connection with Write Operationimportasynciofromasyncio_telnetimportTelnetasyncdefmain():tn=Telnet()awaittn.open('example.com')awaittn.write(b'Vladimir\r\n')response=awaittn.read_until_eof()awaittn.close()returnresponseif__name__=='__main__':result=asyncio.run(main())print(result)# Example of successful execution:# b'\n***************** User Access Login ********************\r\n\r\nUser:Vladimir\r\nPassword:'Feel free to check thedocumentationandexamplesfor more detailed information.
Package: asyncio-throttle
asyncio-throttleSimple, easy-to-use throttler for asyncio.Exampleimporttimeimportrandomimportasynciofromasyncio_throttleimportThrottlerasyncdefworker(no,throttler,n):for_inrange(n):awaitasyncio.sleep(random.random()*2)asyncwiththrottler:print(time.time(),'Worker #%d: Bang!'%no)asyncdefmain():throttler=Throttler(rate_limit=5)tasks=[loop.create_task(worker(no,throttler,10))fornoinrange(5)]awaitasyncio.wait(tasks)loop=asyncio.get_event_loop()loop.run_until_complete(main())loop.close()Here I limited work rate to 5/sec while there are 5 workers.
And the result:1508273760.3462772 Worker #2: Bang!
1508273760.590009 Worker #3: Bang!
1508273760.856431 Worker #0: Bang!
1508273761.0110679 Worker #2: Bang!
1508273761.086856 Worker #4: Bang!
1508273761.350699 Worker #3: Bang!
1508273761.5906 Worker #1: Bang!
1508273761.8655958 Worker #4: Bang!
1508273762.224158 Worker #0: Bang!
1508273762.600234 Worker #2: Bang!
1508273762.694332 Worker #2: Bang!
1508273762.726774 Worker #0: Bang!
1508273762.944273 Worker #4: Bang!Installation$pipinstallasyncio-throttleIt requires Python 3.6 or later.Usageasyncio_throttle.Throttlerintroduces simple APIs:flush()andacquire(). But you will not be interested in those because you can
just use it withinwithstatement and it looks nicer.First, create a throttler given desired rate limit. For example if you
want to limit rate to 500/min, you can make it as:fromasyncio_throttleimportThrottlerthrottler=Throttler(rate_limit=500,period=60)Then whenever you want to do some jobs which should have limited
rate(e.g. sending request to server), Put it inasync withstatement:asyncwiththrottler:send_a_request()It's that easy.asyncio_throttlercan be easily integrated withaiohttptoo:asyncdefworker(throttler,session):whileTrue:asyncwiththrottler:asyncwithsession.get('http://example.com')asresp:do_some_job_with(awaitresp.text())awaitasyncio.sleep(0.05)
Package: asynciotimemachine
asyncio Time MachineMonkey-patches asyncio.AbstractEventLoop so as to make it think it lives in the future.Free software: MIT licenseDocumentation:https://asynciotimemachine.readthedocs.io.CreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.History0.2.1 (2021-09-14)Support use as a context manager, to restore the time method at exit.Use the main asyncio event loop by default.0.2.0 (2021-09-14)Drop support for Python 3.4/3.5; add 3.7/3.8/3.9.Update the dev requirements.0.1.0 (2017-07-24)First release on PyPI.
Package: asyncio-time-travel
Asyncio Time Travel LoopIntroAsyncio Time Travel Loop allows you to test asyncio code that waits or sleeps,
without actually waiting or sleeping.At the same time, you don't have to bother thinking about how the time
advances. Your code should work exactly the same with TimeTravelLoop as it works
with a normal asyncio events loop.Example: Assume that you have a code that waits 1000 seconds, and you want to
tests that code. Instead of actually waiting 1000 seconds, you could use
TimeTravelLoop:importasynciofromasyncio_time_travelimportTimeTravelLoopSLEEP_TIME=1000tloop=TimeTravelLoop()asyncdefinner_coro():# Sleep for a long time:awaitasyncio.sleep(SLEEP_TIME,loop=tloop)tloop.run_until_complete(inner_coro())This code completes immediately.See some of thetestsfor more advanced examples of what TimeTravelLoop can do.InstallationRun:pipinstallasyncio-time-travelYou can also find the package athttps://pypi.python.org/pypi/asyncio-time-travel.TestsRun (Inside asyncio_time_travel dir):pytestIf you haven't yet heard ofpytest, it's your lucky day :)How does this work?TimeTravelLoop source is based on the source code of
asyncio.test_utils.TestLoop.For each _run_once iteration of the loop, the following is done:Loop events are executed.Time is advanced to the closest scheduled event.Using this method your code never waits, and at the same time the events
execute in the correct order.LimitationsTimeTravelLoop is meant to be used with your tests, not for production code. In
particular, if your loop interacts with external events, bending time is not a
good idea (Time will advance differently outside of your loop).Further workThe code might have bugs. If you find any issues, don't hesitate to fork or
open an issue.It might be possible to integrate this code into asyncio.test_utils in some
way.
Package: asyncio-tokenized-lock
Asyncio Tokenized LockAsyncio Tokenized Lock is a Python library that provides a token-based locking mechanism for managing asynchronous locks in an asyncio environment. It introduces two main classes,LockManagerandTokenizedLock, to facilitate the coordination of asynchronous tasks with associated tokens.FeaturesTokenized Locking:Locks are associated with tokens, allowing for fine-grained control over asynchronous operations.Asynchronous Support:Built on asyncio, enabling efficient coordination of asynchronous tasks.Context Manager Interface:TokenizedLockcan be used as an asynchronous context manager for clean and concise lock management.Timeout Support:The library supports timeouts for lock acquisition.Installationpipinstallasyncio-tokenized-lockUsage (Examples)Basic Usagefromasyncio_tokenized_lock.lockimportLockManager,TokenizedLockmanager=LockManager[str]()lock=manager.register("example_token")# Acquire and release the lockasyncwithlock:# Perform operations while holding the lockpassTimeoutContext Managerfromasyncio_tokenized_lock.lockimportLockManager,TokenizedLockmanager=LockManager[str]()token="example_token"lock=manager.register(token)lock.ctx_timeout=1.0# Set the timeout to 1 secondtry:# Acquire the lock with a timeout using context managerasyncwithlock:# Perform operations while holding the lockpassexceptasyncio.TimeoutError:...Inlinetry:awaitlock.acquire(timeout=1.0)# Perform operations while holding the lockexceptasyncio.TimeoutError:print("Lock acquisition timed out")Queue Concurrencyimportasyncioimportuuidimportloggingfromasyncio_tokenized_lock.lockimportLockManager,TokenizedLocklog=logging.getLogger("my-module")asyncdefconsume_queue_safely(concurrency:int=5,queue_size:int=100):manager=LockManager[str]()queue=asyncio.Queue()put_tasks=[asyncio.ensure_future(queue.put(item=uuid.uuid4()))for_inrange(queue_size)]asyncdefsafe_consume(queue:asyncio.Queue):whilenotqueue.empty():item=awaitqueue.get()lock=manager.register(item)iflock.locked:continueasyncwithlock:# Perform operations with the locked itemyielditem# Worker class to consume from the queue safely@dataclassclassWorker:id:strqueue:asyncio.Queueasyncdefconsume(self):whileTrue:asyncforiteminsafe_consume(self.queue):# Perform operations with the itemlog.info(f"[WORKER-{self.id}] Item{item}processed")breakworkers=[Worker(id=str(i),queue=queue)foriinrange(concurrency)]consume_tasks=[asyncio.ensure_future(w.consume())forwinworkers]# Wait for tasks to completeawaitasyncio.wait(put_tasks)awaitasyncio.wait(consume_tasks)TestingpoetryrunpytestRun the provided test suite to ensure the correct behavior of theLockManagerandTokenizedLockclasses in different scenarios.ContributingContributions are welcome! Feel free to open issues, submit pull requests, or suggest improvements.LicenseThis library is licensed under the MIT License - see theLICENSEfile for details.
Package: asyncio-tools
asyncio_toolsUseful utilities for working with asyncio.gatherProvides a convenient wrapper aroundasyncio.gather.fromasyncio_toolsimportgather,CompoundExceptionasyncdefgood():return'OK'asyncdefbad():raiseValueError()asyncdefmain():response=awaitgather(good(),bad(),good())# Check if a particular exception was raised.ValueErrorinresponse.exception_types# >>> True# To get all exceptions:print(response.exceptions)# >>> [ValueError()]# To get all instances of a particular exception:response.exceptions_of_type(ValueError)# >>> [ValueError()]# To get the number of exceptions:print(response.exception_count)# >>> 1# You can still access all of the results:print(response.all)# >>> ['OK', ValueError(), 'OK']# And can access all successes (i.e. non-exceptions):print(response.successes)# >>> ['OK', 'OK']# To get the number of successes:print(response.success_count)# >>> 2try:# To combines all of the exceptions into a single one, which merges the# messages.raiseresponse.compound_exception()exceptCompoundExceptionascompound_exception:print("Caught it")ifValueErrorincompound_exception.exception_types:print("Caught a ValueError")Read some background on whygatheris useful:https://www.piccolo-orm.com/blog/exception-handling-in-asyncio/https://www.piccolo-orm.com/blog/asyncio-gather/