typed-concurrency
View typed-concurrency on PyPI
Typed structured concurrency with Go-ish ergonomics on top of asyncio.
uv add typed-concurrency
from typed_concurrency import Channel, Group, go, process, thread
Python 3.11 or newer is required. There are no dependencies beyond
typed-errs, which supplies the explicit
Option value used when a channel closes.
Tasks and groups
go() is deliberately boring: it creates an asyncio.Task[T] without losing
the coroutine's result type.
user = go(fetch_user())
config = go(fetch_config())
# Other async work happens here.
name: str = await user
settings: Config = await config
Group is a compact wrapper around asyncio.TaskGroup; it keeps the standard
structured-concurrency cancellation and exception behaviour.
async with Group() as group:
users = group.go(fetch_users())
config = group.go(fetch_config())
# Both tasks have completed here.
print(users.result())
print(config.result())
When a result is intentionally irrelevant, << makes that clear:
async with Group() as group:
group << report_progress()
group << refresh_cache()
Channels
Channel[T] is a buffered async queue with close semantics. recv() and
await channel return Option[T]: queued values are Some(value), and a
closed, drained channel returns Nothing(). This avoids a nullable receive
protocol while keeping normal closure distinct from an error.
from typed_concurrency import Channel, recv
from typed_errs import Some
channel = Channel[int](16)
await channel.send(42)
received = await channel.recv()
if isinstance(received, Some):
print(received.value)
await channel.close()
Channels are async iterable, which is usually the pleasant producer/consumer form:
async def producer(channel: Channel[int]) -> None:
for value in range(10):
await channel.send(value)
await channel.close()
async def consumer(channel: Channel[int]) -> None:
async for value in channel:
print(value)
async with Group() as group:
channel = Channel[int](10)
group << producer(channel)
group << consumer(channel)
await (channel << value) sends and await (channel >> recv) receives. The
compact await channel receive form is also available. They are sugar over
send() and recv(), which remain the canonical API.
from typed_concurrency import recv
await (channel << 42)
value = await (channel >> recv)
capacity=0 follows asyncio.Queue and means an unbounded buffer. It is not a
Go-style rendezvous channel.
Blocking and CPU work
thread() runs a blocking callable using asyncio.to_thread(). process()
runs pickle-compatible CPU-bound work in a shared process pool.
data = await thread(read_file, path)
result = await process(expensive_parse, data)
Use process() only for substantial CPU work: process startup and argument
serialization have a real cost.
Examples and development
Run the small end-to-end example with uv run python examples/basic.py.
Ecosystem
- typed-errs provides the
Optionvalues used by channel receives after normal closure. - python-crimes provides the complementary pipe, deferred-cleanup, and matching helpers.
- typed-file-io supplies typed file
I/O that combines naturally with
thread()for blocking reads and writes.
Dependencies
Use and contributions
This is a personal library, but it is not private or locked to my projects. You may use it in general Python work and in 42 projects under the MIT license; just follow the rules that apply to your campus and assignment.
Contributions are welcome: open an issue or send a pull request. I do not care whether a contribution is written by hand, AI-assisted, or generated another way; I care about whether it is correct, tested, understandable, and a good fit. Because this is opinionated personal infrastructure, pull requests are reviewed selectively and are likely to be rejected unless they clearly improve the library without making it harder to maintain.
Development and release
Run mise run check for linting, type checks, tests, and a package build.
Every push to master publishes a unique 0.0.<CI run> ZeroVer version through
PyPI Trusted Publishing. mise run publish remains available for manual
publishing.
License
MIT
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 typed_concurrency-0.0.4.tar.gz.
File metadata
- Download URL: typed_concurrency-0.0.4.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd3a68bb4dcc1b7aa378416139b555668c1f48e1586d697eba6ec58c3d7c0ec7
|
|
| MD5 |
61ac432d5d66ae9543bab90a39fddef4
|
|
| BLAKE2b-256 |
e938ca76f02e0958bcd622a66debd5177f1ae71327971042c67b5c40bb08bd7e
|
Provenance
The following attestation bundles were made for typed_concurrency-0.0.4.tar.gz:
Publisher:
release.yml on 0xveya/typed-concurrency
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typed_concurrency-0.0.4.tar.gz -
Subject digest:
fd3a68bb4dcc1b7aa378416139b555668c1f48e1586d697eba6ec58c3d7c0ec7 - Sigstore transparency entry: 2427560362
- Sigstore integration time:
-
Permalink:
0xveya/typed-concurrency@a8009b9685e39fdd87c013477191004fb60c8822 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/0xveya
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a8009b9685e39fdd87c013477191004fb60c8822 -
Trigger Event:
push
-
Statement type:
File details
Details for the file typed_concurrency-0.0.4-py3-none-any.whl.
File metadata
- Download URL: typed_concurrency-0.0.4-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e9a808ad665a4ab2689b82457e290cf73f1ad343e161395b43596ec158cb324
|
|
| MD5 |
d222a2d8c1081185113290e1931d2bdf
|
|
| BLAKE2b-256 |
6652dd8b745d0513f0268c861b65a0bf0a456d927a0ab8fe6a4a4b23b2687a35
|
Provenance
The following attestation bundles were made for typed_concurrency-0.0.4-py3-none-any.whl:
Publisher:
release.yml on 0xveya/typed-concurrency
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typed_concurrency-0.0.4-py3-none-any.whl -
Subject digest:
4e9a808ad665a4ab2689b82457e290cf73f1ad343e161395b43596ec158cb324 - Sigstore transparency entry: 2427560438
- Sigstore integration time:
-
Permalink:
0xveya/typed-concurrency@a8009b9685e39fdd87c013477191004fb60c8822 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/0xveya
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a8009b9685e39fdd87c013477191004fb60c8822 -
Trigger Event:
push
-
Statement type: