METADATA 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. Metadata-Version: 2.1
  2. Name: async-generator
  3. Version: 1.10
  4. Summary: Async generators and context managers for Python 3.5+
  5. Home-page: https://github.com/python-trio/async_generator
  6. Author: Nathaniel J. Smith
  7. Author-email: njs@pobox.com
  8. License: MIT -or- Apache License 2.0
  9. Keywords: async
  10. Platform: UNKNOWN
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: Intended Audience :: Developers
  13. Classifier: License :: OSI Approved :: MIT License
  14. Classifier: License :: OSI Approved :: Apache Software License
  15. Classifier: Programming Language :: Python :: Implementation :: CPython
  16. Classifier: Programming Language :: Python :: Implementation :: PyPy
  17. Classifier: Programming Language :: Python :: 3 :: Only
  18. Classifier: Programming Language :: Python :: 3.5
  19. Classifier: Programming Language :: Python :: 3.6
  20. Classifier: Framework :: AsyncIO
  21. Requires-Python: >=3.5
  22. .. image:: https://img.shields.io/badge/chat-join%20now-blue.svg
  23. :target: https://gitter.im/python-trio/general
  24. :alt: Join chatroom
  25. .. image:: https://img.shields.io/badge/docs-read%20now-blue.svg
  26. :target: https://async-generator.readthedocs.io/en/latest/?badge=latest
  27. :alt: Documentation Status
  28. .. image:: https://travis-ci.org/python-trio/async_generator.svg?branch=master
  29. :target: https://travis-ci.org/python-trio/async_generator
  30. :alt: Automated test status
  31. .. image:: https://ci.appveyor.com/api/projects/status/af4eyed8o8tc3t0r/branch/master?svg=true
  32. :target: https://ci.appveyor.com/project/python-trio/trio/history
  33. :alt: Automated test status (Windows)
  34. .. image:: https://codecov.io/gh/python-trio/async_generator/branch/master/graph/badge.svg
  35. :target: https://codecov.io/gh/python-trio/async_generator
  36. :alt: Test coverage
  37. The async_generator library
  38. ===========================
  39. Python 3.6 added `async generators
  40. <https://www.python.org/dev/peps/pep-0525/>`__. (What's an async
  41. generator? `Check out my 5-minute lightning talk demo from PyCon 2016
  42. <https://youtu.be/PulzIT8KYLk?t=24m30s>`__.) Python 3.7 adds some more
  43. tools to make them usable, like ``contextlib.asynccontextmanager``.
  44. This library gives you all that back to Python 3.5.
  45. For example, this code only works in Python 3.6+:
  46. .. code-block:: python3
  47. async def load_json_lines(stream_reader):
  48. async for line in stream_reader:
  49. yield json.loads(line)
  50. But this code does the same thing, and works on Python 3.5+:
  51. .. code-block:: python3
  52. from async_generator import async_generator, yield_
  53. @async_generator
  54. async def load_json_lines(stream_reader):
  55. async for line in stream_reader:
  56. await yield_(json.loads(line))
  57. Or in Python 3.7, you can write:
  58. .. code-block:: python3
  59. from contextlib import asynccontextmanager
  60. @asynccontextmanager
  61. async def background_server():
  62. async with trio.open_nursery() as nursery:
  63. value = await nursery.start(my_server)
  64. try:
  65. yield value
  66. finally:
  67. # Kill the server when the scope exits
  68. nursery.cancel_scope.cancel()
  69. This is the same, but back to 3.5:
  70. .. code-block:: python3
  71. from async_generator import async_generator, yield_, asynccontextmanager
  72. @asynccontextmanager
  73. @async_generator
  74. async def background_server():
  75. async with trio.open_nursery() as nursery:
  76. value = await nursery.start(my_server)
  77. try:
  78. await yield_(value)
  79. finally:
  80. # Kill the server when the scope exits
  81. nursery.cancel_scope.cancel()
  82. (And if you're on 3.6, you can use ``@asynccontextmanager`` with
  83. native generators.)
  84. Let's do this
  85. =============
  86. * Install: ``python3 -m pip install -U async_generator`` (or on Windows,
  87. maybe ``py -3 -m pip install -U async_generator``
  88. * Manual: https://async-generator.readthedocs.io/
  89. * Bug tracker and source code: https://github.com/python-trio/async_generator
  90. * Real-time chat: https://gitter.im/python-trio/general
  91. * License: MIT or Apache 2, your choice
  92. * Contributor guide: https://trio.readthedocs.io/en/latest/contributing.html
  93. * Code of conduct: Contributors are requested to follow our `code of
  94. conduct
  95. <https://trio.readthedocs.io/en/latest/code-of-conduct.html>`__ in
  96. all project spaces.
  97. How come some of those links talk about "trio"?
  98. ===============================================
  99. `Trio <https://trio.readthedocs.io>`__ is a new async concurrency
  100. library for Python that's obsessed with usability and correctness – we
  101. want to make it *easy* to get things *right*. The ``async_generator``
  102. library is maintained by the Trio project as part of that mission, and
  103. because Trio uses ``async_generator`` internally.
  104. You can use ``async_generator`` with any async library. It works great
  105. with ``asyncio``, or Twisted, or whatever you like. (But we think Trio
  106. is pretty sweet.)