async_generator


Nameasync_generator JSON
Version 1.10 PyPI version JSON
download
home_pagehttps://github.com/python-trio/async_generator
SummaryAsync generators and context managers for Python 3.5+
upload_time2018-08-01 03:36:21
maintainer
docs_urlNone
authorNathaniel J. Smith
requires_python>=3.5
licenseMIT -or- Apache License 2.0
keywords async
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            .. image:: https://img.shields.io/badge/chat-join%20now-blue.svg
   :target: https://gitter.im/python-trio/general
   :alt: Join chatroom

.. image:: https://img.shields.io/badge/docs-read%20now-blue.svg
   :target: https://async-generator.readthedocs.io/en/latest/?badge=latest
   :alt: Documentation Status

.. image:: https://travis-ci.org/python-trio/async_generator.svg?branch=master
   :target: https://travis-ci.org/python-trio/async_generator
   :alt: Automated test status

.. image:: https://ci.appveyor.com/api/projects/status/af4eyed8o8tc3t0r/branch/master?svg=true
   :target: https://ci.appveyor.com/project/python-trio/trio/history
   :alt: Automated test status (Windows)

.. image:: https://codecov.io/gh/python-trio/async_generator/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/python-trio/async_generator
   :alt: Test coverage

The async_generator library
===========================

Python 3.6 added `async generators
<https://www.python.org/dev/peps/pep-0525/>`__. (What's an async
generator? `Check out my 5-minute lightning talk demo from PyCon 2016
<https://youtu.be/PulzIT8KYLk?t=24m30s>`__.) Python 3.7 adds some more
tools to make them usable, like ``contextlib.asynccontextmanager``.

This library gives you all that back to Python 3.5.

For example, this code only works in Python 3.6+:

.. code-block:: python3

   async def load_json_lines(stream_reader):
       async for line in stream_reader:
           yield json.loads(line)

But this code does the same thing, and works on Python 3.5+:

.. code-block:: python3

   from async_generator import async_generator, yield_

   @async_generator
   async def load_json_lines(stream_reader):
       async for line in stream_reader:
           await yield_(json.loads(line))

Or in Python 3.7, you can write:

.. code-block:: python3

   from contextlib import asynccontextmanager

   @asynccontextmanager
   async def background_server():
       async with trio.open_nursery() as nursery:
           value = await nursery.start(my_server)
           try:
               yield value
           finally:
               # Kill the server when the scope exits
               nursery.cancel_scope.cancel()

This is the same, but back to 3.5:

.. code-block:: python3

   from async_generator import async_generator, yield_, asynccontextmanager

   @asynccontextmanager
   @async_generator
   async def background_server():
       async with trio.open_nursery() as nursery:
           value = await nursery.start(my_server)
           try:
               await yield_(value)
           finally:
               # Kill the server when the scope exits
               nursery.cancel_scope.cancel()

(And if you're on 3.6, you can use ``@asynccontextmanager`` with
native generators.)


Let's do this
=============

* Install: ``python3 -m pip install -U async_generator`` (or on Windows,
  maybe ``py -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 our `code of
  conduct
  <https://trio.readthedocs.io/en/latest/code-of-conduct.html>`__ in
  all project spaces.


How come some of those links talk about "trio"?
===============================================

`Trio <https://trio.readthedocs.io>`__ is a new async concurrency
library for Python that's obsessed with usability and correctness – we
want to make it *easy* to get things *right*. The ``async_generator``
library is maintained by the Trio project as part of that mission, and
because Trio uses ``async_generator`` internally.

You can use ``async_generator`` with any async library. It works great
with ``asyncio``, or Twisted, or whatever you like. (But we think Trio
is pretty sweet.)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/python-trio/async_generator",
    "name": "async_generator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "async",
    "author": "Nathaniel J. Smith",
    "author_email": "njs@pobox.com",
    "download_url": "https://files.pythonhosted.org/packages/ce/b6/6fa6b3b598a03cba5e80f829e0dadbb49d7645f523d209b2fb7ea0bbb02a/async_generator-1.10.tar.gz",
    "platform": "",
    "description": ".. image:: https://img.shields.io/badge/chat-join%20now-blue.svg\n   :target: https://gitter.im/python-trio/general\n   :alt: Join chatroom\n\n.. image:: https://img.shields.io/badge/docs-read%20now-blue.svg\n   :target: https://async-generator.readthedocs.io/en/latest/?badge=latest\n   :alt: Documentation Status\n\n.. image:: https://travis-ci.org/python-trio/async_generator.svg?branch=master\n   :target: https://travis-ci.org/python-trio/async_generator\n   :alt: Automated test status\n\n.. image:: https://ci.appveyor.com/api/projects/status/af4eyed8o8tc3t0r/branch/master?svg=true\n   :target: https://ci.appveyor.com/project/python-trio/trio/history\n   :alt: Automated test status (Windows)\n\n.. image:: https://codecov.io/gh/python-trio/async_generator/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/python-trio/async_generator\n   :alt: Test coverage\n\nThe async_generator library\n===========================\n\nPython 3.6 added `async generators\n<https://www.python.org/dev/peps/pep-0525/>`__. (What's an async\ngenerator? `Check out my 5-minute lightning talk demo from PyCon 2016\n<https://youtu.be/PulzIT8KYLk?t=24m30s>`__.) Python 3.7 adds some more\ntools to make them usable, like ``contextlib.asynccontextmanager``.\n\nThis library gives you all that back to Python 3.5.\n\nFor example, this code only works in Python 3.6+:\n\n.. code-block:: python3\n\n   async def load_json_lines(stream_reader):\n       async for line in stream_reader:\n           yield json.loads(line)\n\nBut this code does the same thing, and works on Python 3.5+:\n\n.. code-block:: python3\n\n   from async_generator import async_generator, yield_\n\n   @async_generator\n   async def load_json_lines(stream_reader):\n       async for line in stream_reader:\n           await yield_(json.loads(line))\n\nOr in Python 3.7, you can write:\n\n.. code-block:: python3\n\n   from contextlib import asynccontextmanager\n\n   @asynccontextmanager\n   async def background_server():\n       async with trio.open_nursery() as nursery:\n           value = await nursery.start(my_server)\n           try:\n               yield value\n           finally:\n               # Kill the server when the scope exits\n               nursery.cancel_scope.cancel()\n\nThis is the same, but back to 3.5:\n\n.. code-block:: python3\n\n   from async_generator import async_generator, yield_, asynccontextmanager\n\n   @asynccontextmanager\n   @async_generator\n   async def background_server():\n       async with trio.open_nursery() as nursery:\n           value = await nursery.start(my_server)\n           try:\n               await yield_(value)\n           finally:\n               # Kill the server when the scope exits\n               nursery.cancel_scope.cancel()\n\n(And if you're on 3.6, you can use ``@asynccontextmanager`` with\nnative generators.)\n\n\nLet's do this\n=============\n\n* Install: ``python3 -m pip install -U async_generator`` (or on Windows,\n  maybe ``py -3 -m pip install -U async_generator``\n\n* Manual: https://async-generator.readthedocs.io/\n\n* Bug tracker and source code: https://github.com/python-trio/async_generator\n\n* Real-time chat: https://gitter.im/python-trio/general\n\n* License: MIT or Apache 2, your choice\n\n* Contributor guide: https://trio.readthedocs.io/en/latest/contributing.html\n\n* Code of conduct: Contributors are requested to follow our `code of\n  conduct\n  <https://trio.readthedocs.io/en/latest/code-of-conduct.html>`__ in\n  all project spaces.\n\n\nHow come some of those links talk about \"trio\"?\n===============================================\n\n`Trio <https://trio.readthedocs.io>`__ is a new async concurrency\nlibrary for Python that's obsessed with usability and correctness \u2013 we\nwant to make it *easy* to get things *right*. The ``async_generator``\nlibrary is maintained by the Trio project as part of that mission, and\nbecause Trio uses ``async_generator`` internally.\n\nYou can use ``async_generator`` with any async library. It works great\nwith ``asyncio``, or Twisted, or whatever you like. (But we think Trio\nis pretty sweet.)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT -or- Apache License 2.0",
    "summary": "Async generators and context managers for Python 3.5+",
    "version": "1.10",
    "project_urls": {
        "Homepage": "https://github.com/python-trio/async_generator"
    },
    "split_keywords": [
        "async"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "715239d20e03abd0ac9159c162ec24b93fbcaa111e8400308f2465432495ca2b",
                "md5": "f42a694c403397d825208a4cf97379e6",
                "sha256": "01c7bf666359b4967d2cda0000cc2e4af16a0ae098cbffcb8472fb9e8ad6585b"
            },
            "downloads": -1,
            "filename": "async_generator-1.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f42a694c403397d825208a4cf97379e6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 18857,
            "upload_time": "2018-08-01T03:36:20",
            "upload_time_iso_8601": "2018-08-01T03:36:20.029960Z",
            "url": "https://files.pythonhosted.org/packages/71/52/39d20e03abd0ac9159c162ec24b93fbcaa111e8400308f2465432495ca2b/async_generator-1.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ceb66fa6b3b598a03cba5e80f829e0dadbb49d7645f523d209b2fb7ea0bbb02a",
                "md5": "078a29b4afb3d7f38c097a530f042a55",
                "sha256": "6ebb3d106c12920aaae42ccb6f787ef5eefdcdd166ea3d628fa8476abe712144"
            },
            "downloads": -1,
            "filename": "async_generator-1.10.tar.gz",
            "has_sig": false,
            "md5_digest": "078a29b4afb3d7f38c097a530f042a55",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 29870,
            "upload_time": "2018-08-01T03:36:21",
            "upload_time_iso_8601": "2018-08-01T03:36:21.690827Z",
            "url": "https://files.pythonhosted.org/packages/ce/b6/6fa6b3b598a03cba5e80f829e0dadbb49d7645f523d209b2fb7ea0bbb02a/async_generator-1.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2018-08-01 03:36:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "python-trio",
    "github_project": "async_generator",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "appveyor": true,
    "lcname": "async_generator"
}
        
Elapsed time: 0.26953s