A Python library for functional programming with typed, safe, and meaningful function returns using monadic containers.
Returns is a Python library that introduces functional programming patterns through monadic containers to make function returns typed, safe, and meaningful. It solves problems like null references, exception handling, and impure code by providing containers like Maybe, Result, IO, and Future, enabling developers to write declarative and error-resistant business logic.
Python developers building maintainable applications who want to adopt functional programming principles, improve type safety, eliminate exceptions, and separate pure from impure code. It's especially useful for teams focusing on robust architecture and predictable error handling.
Developers choose Returns because it offers a comprehensive, type-safe way to handle side effects, errors, and null values without exceptions, leading to more readable and composable code. Its integration with `mypy` and support for Higher Kinded Types provide strong guarantees that are rare in Python ecosystems.
Make your functions return something meaningful, typed, and safe!
The Maybe container replaces None with Some and Nothing types, preventing null-related errors entirely, as shown in the README's refactored example that avoids nested if checks for None values.
Integrates seamlessly with mypy and PEP561 for rigorous type checking, including emulated Higher Kinded Types, ensuring compile-time safety for complex functional patterns.
The RequiresContext container enables typed, explicit dependency injection without cluttering function signatures, demonstrated in the Django example for configurable game logic.
IO and IOResult containers clearly mark impure operations (like I/O), enforcing better architecture and testability, as illustrated in the refactored HTTP request example.
Requires configuring a custom mypy plugin and specific type-checker settings, which adds initial overhead and may conflict with existing tooling in some projects.
Adopting monadic containers often leads to more verbose code compared to Python's idiomatic exception handling or optional types, potentially reducing readability for teams unfamiliar with FP.
Integrating with third-party libraries that expect exceptions or None values requires additional wrapping layers, increasing boilerplate and maintenance effort.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.