Python optimized for AItype safetycorrectness
Building blocks for Python apps in the agentic era.
Harden it, one line at a time
With Effecton33 lines
import effecton as E
class TooLate(E.EffectonError): ...
class Closed(E.EffectonError): ...
@E.gen
def greet(
name: str,
) -> E.EffectGen[str, TooLate | Closed]:
now = yield from E.now()
if now.weekday() == 6:
yield from E.fail(Closed())
if now.hour >= 22:
yield from E.fail(TooLate())
return f"hello {name}"
program = (
greet("ada")
.retry( # typesafe retries
E.Schedule.spaced(minutes=1),
until=lambda e: isinstance(e, Closed),
)
.with_span( # observability built in
"greet"
)
)
E.run_main(program)Add a guarantee
Without Effecton9 lines
import httpx
async def fetch_profile(
client: httpx.AsyncClient, user_id: int
) -> str:
response = await client.get(f"/users/{user_id}")
response.raise_for_status()
return response.textWith Effecton17 lines
import effecton as E
type FetchError = (
E.HttpClient.TransportError | E.HttpClient.StatusError
)
@E.gen
def fetch_profile(
user_id: int,
) -> E.EffectGen[str, FetchError, E.HttpClient.Protocol]:
http = yield from E.require(E.HttpClient.Protocol)
response = yield from http.get(f"/users/{user_id}")
ok = yield from E.HttpClient.filter_status_ok(response)
return ok.textE.Effect describes your program
Success · Receipt
What it produces
The value a successful run hands back. Use, yield from charge(order) and possible errors automatically propagate. Just like with async / await code.
Error · CardDeclined | CardExpired
How it can fail
Every expected failure, as a union of plain classes. Implement granular, type-safe error handling with catch(CardExpired).
Requirements · PaymentGateway
What it needs
The services the program depends on. Inject Live dependencies in your production code and mocks in tests. Type checker knows when you forget to do so.
Agent-era ready Python
Type safe to the limit
Every function says what it returns, how it can fail and what it needs, right in its signature. You and your agent sees the whole interface.
Unsloppable code
Agents love building from reusable building blocks. Small, typed, composable primitives are easy for a model to reason about.
Your agent already knows Effecton
Just point it to the docs. Your agent is already effecton expert.
Building blocks to build whatever you want
Building blocks
- HTTP clientsync and async, on httpx
- File systemsync and async
- In-memory file systemthe Test double
- Pretty loggerlevels, colour, annotations
- Clocka test clock you can wind
- TracerOpenTelemetry spans
- Randomseedable in tests
- Processcwd and home
- Schedulespaced, exponential, jittered
What they add up to
Web APIs
Typed handlers with built-in retries and tracing
Command-line tools
Testable side effects, structured errors
ML pipelines
Reliable steps that retry, time out, and log themselves