{"id":13533252,"url":"https://github.com/aio-libs/janus","last_synced_at":"2025-04-01T21:32:05.918Z","repository":{"id":33431068,"uuid":"37076376","full_name":"aio-libs/janus","owner":"aio-libs","description":"Thread-safe asyncio-aware queue for Python","archived":false,"fork":false,"pushed_at":"2025-03-17T04:09:00.000Z","size":641,"stargazers_count":855,"open_issues_count":3,"forks_count":53,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-03-17T11:04:18.070Z","etag":null,"topics":["asyncio","mypy","queue","threadsafe"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aio-libs.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"asvetlov","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":"gh/asvetlov","custom":null}},"created_at":"2015-06-08T15:45:28.000Z","updated_at":"2025-03-17T04:09:04.000Z","dependencies_parsed_at":"2023-12-04T05:35:34.522Z","dependency_job_id":"e4c21507-80b9-405f-9179-234e288321b6","html_url":"https://github.com/aio-libs/janus","commit_stats":{"total_commits":690,"total_committers":20,"mean_commits":34.5,"dds":0.6202898550724638,"last_synced_commit":"02299a488c48de80196db33d55ce841819a85e99"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Fjanus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Fjanus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Fjanus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Fjanus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aio-libs","download_url":"https://codeload.github.com/aio-libs/janus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246713314,"owners_count":20821873,"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":["asyncio","mypy","queue","threadsafe"],"created_at":"2024-08-01T07:01:18.037Z","updated_at":"2025-04-01T21:32:05.908Z","avatar_url":"https://github.com/aio-libs.png","language":"Python","readme":"=======\n janus\n=======\n.. image:: https://github.com/aio-libs/janus/actions/workflows/ci.yml/badge.svg\n    :target: https://github.com/aio-libs/janus/actions/workflows/ci.yml\n.. image:: https://codecov.io/gh/aio-libs/janus/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/aio-libs/janus\n.. image:: https://img.shields.io/pypi/v/janus.svg\n    :target: https://pypi.python.org/pypi/janus\n.. image:: https://badges.gitter.im/Join%20Chat.svg\n    :target: https://gitter.im/aio-libs/Lobby\n    :alt: Chat on Gitter\n\n\n\nMixed sync-async queue, supposed to be used for communicating between\nclassic synchronous (threaded) code and asynchronous (in terms of\n`asyncio \u003chttps://docs.python.org/3/library/asyncio.html\u003e`_) one.\n\nLike `Janus god \u003chttps://en.wikipedia.org/wiki/Janus\u003e`_ the queue\nobject from the library has two faces: synchronous and asynchronous\ninterface.\n\nSynchronous is fully compatible with `standard queue\n\u003chttps://docs.python.org/3/library/queue.html\u003e`_, asynchronous one\nfollows `asyncio queue design\n\u003chttps://docs.python.org/3/library/asyncio-queue.html\u003e`_.\n\nUsage\n=====\n\nThree queues are available:\n\n* ``Queue``\n* ``LifoQueue``\n* ``PriorityQueue``\n\nEach has two properties: ``sync_q`` and ``async_q``.\n\nUse the first to get synchronous interface and the second to get asynchronous\none.\n\n\nExample\n-------\n\n.. code:: python\n\n    import asyncio\n    import janus\n\n\n    def threaded(sync_q: janus.SyncQueue[int]) -\u003e None:\n        for i in range(100):\n            sync_q.put(i)\n        sync_q.join()\n\n\n    async def async_coro(async_q: janus.AsyncQueue[int]) -\u003e None:\n        for i in range(100):\n            val = await async_q.get()\n            assert val == i\n            async_q.task_done()\n\n\n    async def main() -\u003e None:\n        queue: janus.Queue[int] = janus.Queue()\n        loop = asyncio.get_running_loop()\n        fut = loop.run_in_executor(None, threaded, queue.sync_q)\n        await async_coro(queue.async_q)\n        await fut\n        await queue.aclose()\n\n\n    asyncio.run(main())\n\n\nLimitations\n===========\n\nThis library is built using a classic thread-safe design. The design is\ntime-tested, but has some limitations.\n\n* Once you are done working with a queue, you must properly close it using\n  ``aclose()``. This is because this library creates new tasks to notify other\n  threads. If you do not properly close the queue,\n  `asyncio may generate error messages\n  \u003chttps://github.com/aio-libs/janus/issues/574\u003e`_.\n* The library has quite good performance only when used as intended, that is,\n  for communication between synchronous code and asynchronous one.\n  For sync-only and async-only cases, use queues from\n  `queue \u003chttps://docs.python.org/3/library/queue.html\u003e`_ and\n  `asyncio queue \u003chttps://docs.python.org/3/library/asyncio-queue.html\u003e`_ modules,\n  otherwise `the slowdown can be significant\n  \u003chttps://github.com/aio-libs/janus/issues/419\u003e`_.\n* You cannot use queues for communicating between two different event loops\n  because, like all asyncio primitives, they bind to the current one.\n\nDevelopment status is production/stable. The ``janus`` library is maintained to\nsupport the latest versions of Python and fixes, but no major changes will be\nmade. If your application is performance-sensitive, or if you need any new\nfeatures such as ``anyio`` support, try the experimental\n`culsans \u003chttps://github.com/x42005e1f/culsans\u003e`_ library as an alternative.\n\n\nCommunication channels\n======================\n\nGitHub Discussions: https://github.com/aio-libs/janus/discussions\n\nFeel free to post your questions and ideas here.\n\n*gitter chat* https://gitter.im/aio-libs/Lobby\n\n\nLicense\n=======\n\n``janus`` library is offered under Apache 2 license.\n\nThanks\n======\n\nThe library development is sponsored by DataRobot (https://datarobot.com)\n","funding_links":["https://github.com/sponsors/asvetlov","https://thanks.dev/gh/asvetlov"],"categories":["Python","Data Structures"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Fjanus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faio-libs%2Fjanus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Fjanus/lists"}