{"id":15009577,"url":"https://github.com/python-trio/async_generator","last_synced_at":"2025-09-22T21:58:39.995Z","repository":{"id":41883631,"uuid":"60112633","full_name":"python-trio/async_generator","owner":"python-trio","description":"Making it easy to write async iterators in Python 3.5","archived":false,"fork":false,"pushed_at":"2020-08-24T19:49:32.000Z","size":154,"stargazers_count":94,"open_issues_count":9,"forks_count":24,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-04-14T09:04:51.013Z","etag":null,"topics":["backports","generators","polyfill","python","python-3-5"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/python-trio.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-31T18:14:56.000Z","updated_at":"2024-01-03T14:13:45.000Z","dependencies_parsed_at":"2022-09-16T13:20:51.115Z","dependency_job_id":null,"html_url":"https://github.com/python-trio/async_generator","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Fasync_generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Fasync_generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Fasync_generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Fasync_generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/python-trio","download_url":"https://codeload.github.com/python-trio/async_generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247324680,"owners_count":20920694,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backports","generators","polyfill","python","python-3-5"],"created_at":"2024-09-24T19:26:42.519Z","updated_at":"2025-09-22T21:58:34.934Z","avatar_url":"https://github.com/python-trio.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. 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\u003chttps://www.python.org/dev/peps/pep-0525/\u003e`__. (What's an async\ngenerator? `Check out my 5-minute lightning talk demo from PyCon 2016\n\u003chttps://youtu.be/PulzIT8KYLk?t=24m30s\u003e`__.) 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  \u003chttps://trio.readthedocs.io/en/latest/code-of-conduct.html\u003e`__ in\n  all project spaces.\n\n\nHow come some of those links talk about \"trio\"?\n===============================================\n\n`Trio \u003chttps://trio.readthedocs.io\u003e`__ is a new async concurrency\nlibrary for Python that's obsessed with usability and correctness – 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-trio%2Fasync_generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpython-trio%2Fasync_generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-trio%2Fasync_generator/lists"}