Drop-in collections.deque replacement with async methods
Project description
aiodeque
A drop-in collections.deque replacement with async methods for producer/consumer coordination.
Why aiodeque?
asyncio.Queue only does FIFO. aiodeque gives you a double-ended queue with async waiting on both ends:
- Pop from right or left, append to right or left
- Waiters block when the deque is empty (pop) or full (append with
maxlen) - Fully compatible with
collections.deque— all sync methods work as-is
Requirements
- Python >= 3.14
- No runtime dependencies
Installation
pip install aiodeque
uv add aiodeque
Quick Start
import asyncio
from aiodeque import deque
async def main():
d: deque[int] = deque(maxlen=5)
async def producer():
for i in range(10):
await d.aappend(i)
async def consumer():
for _ in range(10):
item = await d.apopleft()
print(item)
await asyncio.gather(producer(), consumer())
asyncio.run(main())
Async API
| Method | Blocks when… |
|---|---|
await d.apop() |
deque is empty |
await d.apopleft() |
deque is empty |
await d.aappend(item) |
deque is full (maxlen set) |
await d.aappendleft(item) |
deque is full (maxlen set) |
await d.aextend(iterable) |
deque is full for each item |
await d.aextendleft(iterable) |
deque is full for each item |
await d.ainsert(i, item) |
deque is full (maxlen set) |
All other collections.deque methods (.append(), .pop(), .rotate(), etc.) are inherited and work unchanged.
Behavior Notes
- Sync mutations do not wake async waiters — if you call
d.append()directly, tasks waiting inapopleft()will not be notified. Use async methods when coordinating between producers and consumers. - Cancellation safe — cancelling an
awaitremoves the waiter cleanly; no item is lost and the next waiter is woken up if appropriate. - FIFO waiter ordering — waiters are served in the order they started waiting.
- Lazy initialization — internal waiter queues are only allocated on first async use; sync-only usage has no overhead.
vs asyncio.Queue
| Feature | asyncio.Queue |
aiodeque |
|---|---|---|
| FIFO get/put | Yes | Yes (apopleft / aappend) |
| Pop from right | No | Yes (apop) |
| Append to left | No | Yes (aappendleft) |
| Insert at index | No | Yes (ainsert) |
| Rotate / slice | No | Yes (inherited from deque) |
maxsize / maxlen |
Yes | Yes |
task_done / join |
Yes | No |
| Sync access | No | Yes (all collections.deque methods) |
| Type-parameterized | No | Yes (deque[T]) |
Contributing
See CONTRIBUTING.md for development setup and contribution guidelines.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiodeque-0.1.0.tar.gz.
File metadata
- Download URL: aiodeque-0.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f86b4f7dda8fda59edacd888e6283d2ef6f81aa227caeeddee83629dffc8287
|
|
| MD5 |
ac6cce19d4a0c26df8bc0ac41f1a22c3
|
|
| BLAKE2b-256 |
632724aae89d06a8c7910f978963d5015ec10376c43af93951a5d63569d8c625
|
Provenance
The following attestation bundles were made for aiodeque-0.1.0.tar.gz:
Publisher:
publish.yml on cutient/aiodeque
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiodeque-0.1.0.tar.gz -
Subject digest:
1f86b4f7dda8fda59edacd888e6283d2ef6f81aa227caeeddee83629dffc8287 - Sigstore transparency entry: 1151316719
- Sigstore integration time:
-
Permalink:
cutient/aiodeque@caac0769440475c13295a54362c19896d5b80d7a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cutient
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@caac0769440475c13295a54362c19896d5b80d7a -
Trigger Event:
push
-
Statement type:
File details
Details for the file aiodeque-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aiodeque-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b56e4499e47fca650b5f3635c1620d284914d8727d0e17c6b82c79faa86e5b54
|
|
| MD5 |
3bfe6f8e525b9294332b88eb3b4d05cc
|
|
| BLAKE2b-256 |
09a4fb378c63c3b4ba3962d0c11721a7b518dc5918d65fca3559145914a4813d
|
Provenance
The following attestation bundles were made for aiodeque-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on cutient/aiodeque
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiodeque-0.1.0-py3-none-any.whl -
Subject digest:
b56e4499e47fca650b5f3635c1620d284914d8727d0e17c6b82c79faa86e5b54 - Sigstore transparency entry: 1151316819
- Sigstore integration time:
-
Permalink:
cutient/aiodeque@caac0769440475c13295a54362c19896d5b80d7a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cutient
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@caac0769440475c13295a54362c19896d5b80d7a -
Trigger Event:
push
-
Statement type: