A Python package that wraps results in typed containers so callers avoid exceptions and unchecked None.
Overview
Returns brings railway-oriented and functional patterns into Python codebases. It supplies containers and helpers for writing declarative business logic with static typing checked by mypy, including an optional mypy plugin.
Maybe replaces scattered None checks with Some and Nothing. Result and IOResult model success and failure without throwing in pure or impure code. IO and IOResult separate pure logic from side effects such as network calls. Future and FutureResult extend the same ideas to async coroutines so sync and async code can be composed more safely.
RequiresContext offers typed functional dependency injection: dependencies pass through a context object instead of long parameter lists or hard-coded framework settings. Developers can define custom containers while reusing the same composition tools, including do-notation style flows.
The package installs via pip, works with ordinary functions and coroutines, and suits web or service code that wants explicit error paths and clearer architecture in a framework-agnostic way.
Key features
- Maybe for optional values
- Result and safe decorator
- IO and IOResult purity markers
- Future and FutureResult async
- RequiresContext dependency injection
- Custom container interfaces
- Mypy plugin support
- Flow and bind composition
Use cases
- Exception-free API clients
- Typed Django or web logic
- Async pipeline composition
- None-free domain models
- Explicit dependency passing