Metadata-Version: 2.4
Name: matrix-planner
Version: 0.1.0
Summary: Lightweight async task scheduler
Project-URL: Homepage, https://github.com/matrixd0t/matrix-planner
Project-URL: Repository, https://github.com/matrixd0t/matrix-planner
Author: dotmatrix
License: MIT License
        
        Copyright (c) 2026
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.13
Requires-Dist: croniter>=6.2.3
Description-Content-Type: text/markdown

# matrix-planner

Lightweight async task scheduler for Python 3.13+. Single dependency: `croniter`.

```python
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

```python
# 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

```python
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.
