--- id: janus version: "2.0.0" license: Apache 2 license_treatment: permissive maintenance: active --- # janus — Mixed sync-async queue to interoperate between asyncio tasks and classic threads License: permissive · Maintenance: active · Downloads: 6.7M/mo ## What it is and what it does Janus is a queue implementation that bridges synchronous (threaded) and asynchronous (asyncio) code by exposing the same queue object through two separate interfaces: sync_q for classic Python threads and async_q for asyncio tasks. It implements Queue, LifoQueue, and PriorityQueue variants, each compatible with their standard library counterparts on the sync side and asyncio queue design on the async side. The library is built on thread-safe primitives and is production-stable, actively maintained to support current Python versions. It's designed specifically for the use case of passing data between a threaded executor and asyncio code running in the same process. The main constraint is that you must explicitly close the queue with aclose() when done, and it performs best only when actually bridging sync and async code—for purely synchronous or purely asynchronous scenarios, the standard library queues are faster. Use it for: - Pass work items from a thread pool to asyncio tasks without manual synchronization. - Collect results from blocking I/O operations in threads and consume them asynchronously. - Integrate legacy synchronous libraries into an asyncio-based application. - Coordinate between a background worker thread and an asyncio event loop. - Implement a producer-consumer pattern where one side is threaded and the other is async. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides a thread-safe queue with both synchronous and asynchronous interfaces for passing data between classic threaded code and asyncio tasks. Yes, if you need to communicate between threaded and asyncio code in the same process. The library is stable, well-maintained, has no external dependencies, and solves a real coordination problem. Install it only if you actually have both sync and async code to bridge; for purely sync or purely async scenarios, use the standard library queues instead. ## Install pip install janus uv add janus poetry add janus ## Installing janus Before you install: Low friction: pure Python wheel with no runtime dependencies. Actively maintained with recent commits and stable production status. License in practice: Apache 2 permissive license allows commercial and private use with minimal restrictions. Quickstart: import asyncio import janus async def main(): queue = janus.Queue() loop = asyncio.get_running_loop() loop.run_in_executor(None, lambda: queue.sync_q.put(None)) val = await queue.async_q.get() await queue.aclose() asyncio.run(main()) Must call aclose() when done to properly clean up internal tasks; requires Python 3.9 or later. Verify before relying: - Whether the performance penalty for sync-only or async-only use cases is acceptable for your workload. - Whether culsans (mentioned as an experimental alternative) offers the features or performance your application needs. ## Package facts - License: Apache 2 (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 6.7M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags sync async queue, thread asyncio communication, mixed sync-async queue, asyncio thread bridge, queue between threads and tasks, asyncio, threading, queue [View on SkillFed](https://skillfed.io/packages/janus) · [View on PyPI](https://pypi.org/project/janus/)