Lightweight async task scheduler
Project description
matrix-planner
Lightweight async task scheduler for Python 3.13+. Single dependency: croniter.
import asyncio
from matrix_planner import Planner, every
planner = Planner()
@planner.task(every("10s"))
def heartbeat() -> None:
print("tick")
@planner.task(
every("30s"),
max_retries=3,
backoff=lambda a: 2 ** a, # 2, 4, 8… seconds between retries
timeout="15s", # cancel and log if execution exceeds 15s
)
async def fetch() -> None:
...
planner.run_forever()
Key features
| Feature | API |
|---|---|
| Fixed-interval schedule | every("10s"), every(timedelta(minutes=5)) |
| Cron schedule | cron("*/5 * * * *") |
| One-shot schedule | once(datetime(2026, 12, 31)) |
| Decorator registration | @planner.task(every("2s")) |
| Manual registration | planner.add(Task(func=..., schedule=...)) |
| Retry policy | max_retries=N, backoff=float | Callable[[int], float] |
| Per-execution timeout | timeout="15s" | timedelta | float |
| Error callback | on_error=my_handler |
| Sync + async functions | sync dispatched via run_in_executor |
| Direct task invocation | task() bypasses scheduler (useful in tests) |
anchor="start" |
first tick interval after creation, steady cadence |
anchor="end" |
interval measured from end of each execution |
Schedules
# Every 10 seconds (first tick after 10s from now)
s = every("10s")
# Every 5 minutes, anchored to end of execution
s = every("5m", anchor="end")
# Cron expression (fires at 09:00 every weekday)
s = cron("0 9 * * 1-5")
# Cron with timezone
s = cron("0 9 * * *", tz=timezone.utc)
# Fire once at a specific datetime
s = once(datetime(2026, 12, 31, 23, 59))
Task parameters
Task(
func=my_fn,
schedule=every("10s"),
name="my-task", # defaults to func.__name__
args=(1, 2),
kwargs={"key": "val"},
max_retries=2,
backoff=1.0, # fixed delay, or lambda a: 2 ** a
timeout="15s", # None = no limit
on_error=lambda e: ..., # called instead of logging on failure
)
Requirements
Python 3.13+. Single dependency: croniter>=6.2.3.
Install: uv add matrix-planner or pip install matrix-planner.
Written with love by dotmatrix.
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
matrix_planner-0.1.0.tar.gz
(8.8 kB
view details)
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 matrix_planner-0.1.0.tar.gz.
File metadata
- Download URL: matrix_planner-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
610a22135a44595f37420fbfe26eb9857f366d20da590012cf7047236fb9e63b
|
|
| MD5 |
a9001a1e7ac2f4581ddc5f4687dbf67c
|
|
| BLAKE2b-256 |
7e491dbf340ad013134fd27120a4410783e235b0dfe70e3374ff98ae39b2a1ae
|
File details
Details for the file matrix_planner-0.1.0-py3-none-any.whl.
File metadata
- Download URL: matrix_planner-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a3f40b784c06d8038d766ac93ec04a16345b7477bd8fbfc16c868fe38a60e23
|
|
| MD5 |
14f36ccad708b31d20998a2d927fdd30
|
|
| BLAKE2b-256 |
0715b6dd9d1c3712887932663d02ec205cc940da2a4021ae0374840541fe1ea8
|