Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork26
Making it easy to write async iterators in Python 3.5
License
Unknown and 2 other licenses found
Licenses found
python-trio/async_generator
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Python 3.6 addedasync generators. (What's an asyncgenerator?Check out my 5-minute lightning talk demo from PyCon 2016.) Python 3.7 adds some moretools to make them usable, likecontextlib.asynccontextmanager
.
This library gives you all that back to Python 3.5.
For example, this code only works in Python 3.6+:
asyncdefload_json_lines(stream_reader):asyncforlineinstream_reader:yieldjson.loads(line)
But this code does the same thing, and works on Python 3.5+:
fromasync_generatorimportasync_generator,yield_@async_generatorasyncdefload_json_lines(stream_reader):asyncforlineinstream_reader:awaityield_(json.loads(line))
Or in Python 3.7, you can write:
fromcontextlibimportasynccontextmanager@asynccontextmanagerasyncdefbackground_server():asyncwithtrio.open_nursery()asnursery:value=awaitnursery.start(my_server)try:yieldvaluefinally:# Kill the server when the scope exitsnursery.cancel_scope.cancel()
This is the same, but back to 3.5:
fromasync_generatorimportasync_generator,yield_,asynccontextmanager@asynccontextmanager@async_generatorasyncdefbackground_server():asyncwithtrio.open_nursery()asnursery:value=awaitnursery.start(my_server)try:awaityield_(value)finally:# Kill the server when the scope exitsnursery.cancel_scope.cancel()
(And if you're on 3.6, you can use@asynccontextmanager
withnative generators.)
- Install:
python3 -m pip install -U async_generator
(or on Windows,maybepy -3 -m pip install -U async_generator
- Manual:https://async-generator.readthedocs.io/
- Bug tracker and source code:https://github.com/python-trio/async_generator
- Real-time chat:https://gitter.im/python-trio/general
- License: MIT or Apache 2, your choice
- Contributor guide:https://trio.readthedocs.io/en/latest/contributing.html
- Code of conduct: Contributors are requested to follow ourcode ofconduct inall project spaces.
Trio is a new async concurrencylibrary for Python that's obsessed with usability and correctness – wewant to make iteasy to get thingsright. Theasync_generator
library is maintained by the Trio project as part of that mission, andbecause Trio usesasync_generator
internally.
You can useasync_generator
with any async library. It works greatwithasyncio
, or Twisted, or whatever you like. (But we think Triois pretty sweet.)
About
Making it easy to write async iterators in Python 3.5
Topics
Resources
License
Unknown and 2 other licenses found
Licenses found
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.