Scheduler, synchronisation, selector, and asyncio helpers for tealet
Project description
tealetio
tealetio: async without the async.
Where tealet gives you stack-slicing primitives, tealetio turns them into a
runtime framework with a familiar shape. It adds scheduler, task,
synchronisation, selector, runner, and asyncio coexistence APIs for ordinary
tealet code.
In effect, async operations can work without the async keyword: tealet-powered
stack slicing lets ordinary-looking functions block, resume, and compose through
the scheduler.
The top-level package is meant to feel direct: import the common classes and
helpers from tealetio, just as you would from asyncio. Submodules remain
available when you want to name the implementation home explicitly.
from tealetio import Event, Scheduler, gather, run, wait_for
Installation
For the usual scheduler and synchronisation APIs, install the base package:
python -m pip install tealetio
Need to run async methods efficiently from tealetio? Install the optional
asyncio extra. It pulls in asynkit, which tealetio uses to optimise the
asyncio bridge where available:
python -m pip install 'tealetio[asyncio]'
Quick Start
Need a scheduler for synchronous tealet code? Use run() and ask for the
running scheduler inside your entry point:
from tealetio import Event, get_running_scheduler, run
def main() -> str:
scheduler = get_running_scheduler()
event = Event()
seen: list[str] = []
def worker() -> None:
seen.append("waiting")
event.swait()
seen.append("done")
task = scheduler.spawn(worker)
scheduler.call_soon(event.set)
task.wait()
return ", ".join(seen)
assert run(main) == "waiting, done"
Already inside an asyncio program? Use AsyncRunner to host tealet work without
leaving the asyncio world:
import asyncio
from tealetio import AsyncRunner, Event, get_running_scheduler
async def main() -> list[str]:
async with AsyncRunner() as runner:
def entry() -> list[str]:
scheduler = get_running_scheduler()
event = Event()
seen: list[str] = []
def worker() -> None:
seen.append("waiting")
event.swait()
seen.append("done")
task = scheduler.spawn(worker)
scheduler.call_soon(event.set)
task.wait()
return seen
return await runner.run(entry)
assert asyncio.run(main()) == ["waiting", "done"]
Public API
The common API is available directly from tealetio:
- schedulers and runners:
Scheduler,SelectorScheduler,AsyncScheduler,Runner,AsyncRunner,run,run_async - tasks and futures:
Future,Task,spawn,create_task,get_current,CancelledError,shield - wait helpers:
gather,wait,wait_for,as_completed,ensure_future,to_thread - synchronisation primitives:
Event,Lock,Semaphore,Condition,Barrier,Queue - rendezvous communication:
Channel - asyncio coexistence helpers:
asyncio_get_current,run_in_asyncio,run_asyncio_in_tealet,TealetSelectorEventLoop
If you prefer explicit homes, submodules such as tealetio.scheduler,
tealetio.tasks, tealetio.locks, tealetio.runner, tealetio.selector, and
tealetio.asyncio define the same objects.
Asyncio Model
The design intentionally follows asyncio where the mapping is useful. In
effect, you already know much of the shape: the learning curve stays small, and
interop with asyncio-hosted programs stays straightforward. Some names differ to
match tealet execution: Scheduler fills the role normally held by an event
loop, and spawn(...) is the native tealet-facing equivalent of
create_task(...). The package root also exports create_task(...) as a
familiar alias.
Synchronisation primitives are asyncio-compatible where practical and add
s-prefixed methods for tealet-blocking operations, such as Event.swait(),
Lock.sacquire(), and Queue.sget(). tealetio also reuses asyncio
exceptions where that preserves familiar behaviour and compatibility.
Channel is inspired by Stackless Python channels. It provides rendezvous-style
communication between tasks, with selectable sender/receiver preference models,
and can also be used for inter-thread communication through scheduler-safe
wakeup paths.
Notice one important runtime difference: exception delivery. Exceptions such as
CancelledError are delivered immediately by switching to the target tealet,
instead of being kept as pending exceptions. This avoids races where multiple
pending exceptions can accumulate, and removes the need to track pending
cancellations separately. These deviations are intentional, but the exact API
shape remains subject to change before a stable release.
Status
tealetio is pre-1.0 software. APIs are usable for experimentation and in-repo
testing, but may change before a stable release.
Documentation
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 tealetio-0.1.0rc1.tar.gz.
File metadata
- Download URL: tealetio-0.1.0rc1.tar.gz
- Upload date:
- Size: 31.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85b4468a86a744b5117e40d4904f75e8f8a9c2fafa0337f8755738d4f343ed0e
|
|
| MD5 |
3f97df4fc0d4da51bdb0ecaa98f24624
|
|
| BLAKE2b-256 |
c69844cd9b11a58b426e381e05856e29427c39ba0baba20342c64be4ae7de56f
|
Provenance
The following attestation bundles were made for tealetio-0.1.0rc1.tar.gz:
Publisher:
tealetio-release-publish.yml on kristjanvalur/pytealet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tealetio-0.1.0rc1.tar.gz -
Subject digest:
85b4468a86a744b5117e40d4904f75e8f8a9c2fafa0337f8755738d4f343ed0e - Sigstore transparency entry: 1959414898
- Sigstore integration time:
-
Permalink:
kristjanvalur/pytealet@f2bbbce99242a27029b2617d797eea5bd4b6b2f9 -
Branch / Tag:
refs/tags/tealetio-v0.1.0rc1 - Owner: https://github.com/kristjanvalur
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
tealetio-release-publish.yml@f2bbbce99242a27029b2617d797eea5bd4b6b2f9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tealetio-0.1.0rc1-py3-none-any.whl.
File metadata
- Download URL: tealetio-0.1.0rc1-py3-none-any.whl
- Upload date:
- Size: 35.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a069440f2938e009abd7f40bee4bdf809b9b3f5c8698a23cd8ad201c6913e576
|
|
| MD5 |
22ab3ef5e17491d587bf7ee725b2a433
|
|
| BLAKE2b-256 |
29c29e48e8f0dd7b918cf1607af0e852024750f4c009e7205b18394429de26d5
|
Provenance
The following attestation bundles were made for tealetio-0.1.0rc1-py3-none-any.whl:
Publisher:
tealetio-release-publish.yml on kristjanvalur/pytealet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tealetio-0.1.0rc1-py3-none-any.whl -
Subject digest:
a069440f2938e009abd7f40bee4bdf809b9b3f5c8698a23cd8ad201c6913e576 - Sigstore transparency entry: 1959415162
- Sigstore integration time:
-
Permalink:
kristjanvalur/pytealet@f2bbbce99242a27029b2617d797eea5bd4b6b2f9 -
Branch / Tag:
refs/tags/tealetio-v0.1.0rc1 - Owner: https://github.com/kristjanvalur
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
tealetio-release-publish.yml@f2bbbce99242a27029b2617d797eea5bd4b6b2f9 -
Trigger Event:
release
-
Statement type: