Evented
Read the documentation!
Async event sources that turn file changes, webhooks, emails and cron schedules into typed events.
evented gives you a small set of asyncio event sources behind one interface, and an
EventManager that runs them and passes every event to your callbacks. Events are pydantic
models with a to_prompt() method, so they can go straight into an LLM agent.
Sources are configured with pydantic models (evented_config), so they can be loaded from
YAML/JSON and validated.
Installation
pip install evented # core (config models, manager, event types)
pip install "evented[all]" # + watchfiles, fastapi/uvicorn, aioimaplib, croniter
Requires Python 3.13+. The backends of the sources are optional dependencies; the all extra
installs all of them.
Quickstart
import asyncio
from evented import EventData, EventManager
async def on_event(event: EventData) -> None:
print(f"[{event.source}] {event.to_prompt()}")
async def main() -> None:
async with EventManager(event_callbacks=[on_event]) as manager:
await manager.add_file_watch("./src", extensions=[".py", ".md"], name="src")
await manager.add_timed_event("*/5 * * * *", "Run the health check", name="cron")
@manager.track("compute")
async def compute(x: int) -> int:
return x * 2
await compute(21) # prints "[compute] 42"
await asyncio.sleep(60) # edit a file in ./src meanwhile
asyncio.run(main())
From configuration
EventConfig is a discriminated union over all config types (key: type):
import asyncio
from pydantic import TypeAdapter
from evented import EventConfig, EventSource
raw = {"type": "time", "name": "daily", "schedule": "0 9 * * 1-5", "prompt": "Morning report"}
config = TypeAdapter(EventConfig).validate_python(raw) # -> TimeEventConfig
async def main() -> None:
async with EventSource.from_config(config) as source:
async for event in source.events():
print(event.to_prompt())
asyncio.run(main())
You can also pass a list of configs to the manager: EventManager(configs=[...]).
Event sources
Config (type) |
Source |
Backend |
Event |
FileWatchConfig (file) |
FileSystemEventSource |
watchfiles |
FileEventData |
WebhookConfig (webhook) |
WebhookEventSource |
FastAPI + uvicorn |
WebhookEventData |
EmailConfig (email) |
EmailEventSource |
aioimaplib (IMAP) |
EmailEventData |
TimeEventConfig (time) |
TimeEventSource |
croniter |
TimeEventData |
Features
- One interface for every source: each source is an async context manager with an
events() async generator, so you can use it without the manager.
EventManager: runs several sources at once, calls sync or async callbacks, and has
shortcuts like add_file_watch(), add_webhook(), add_email_watch() and
add_timed_event().
- Function tracking:
@manager.track() emits a FunctionResultEventData for each call,
with arguments, duration and success/error status in metadata.
- Prompt templates:
await event.format(config) renders an event with the source's Jinja
template (timestamp and metadata can be turned off).
- Lightweight config package:
evented_config holds only the pydantic models, so you can
import it in config schemas without pulling in the runtime.