Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Python
  3. returns

returns

BSD-2-ClausePython0.27.0

A Python library for functional programming with typed, safe, and meaningful function returns using monadic containers.

Visit WebsiteGitHubGitHub
4.3k stars147 forks0 contributors

What is returns?

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.

Target Audience

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.

Value Proposition

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.

Overview

Make your functions return something meaningful, typed, and safe!

Use Cases

Best For

  • Eliminating None values and null-related errors in Python codebases
  • Replacing exception-based error handling with Railway Oriented Programming
  • Implementing typed functional dependency injection in Django or other frameworks
  • Writing async code with safe error handling and better composition
  • Separating pure business logic from impure I/O operations
  • Building declarative and type-safe pipelines for complex business workflows

Not Ideal For

  • Projects with tight deadlines or rapid prototyping where the overhead of learning functional patterns and refactoring code is prohibitive
  • Codebases deeply integrated with libraries that rely on traditional exception handling (e.g., many web frameworks' error middleware)
  • Small scripts or one-off tasks where the added complexity of monadic containers and type safety provides little benefit
  • Teams not using type hints or static type checking (mypy), as Returns' safety guarantees depend heavily on these

Pros & Cons

Pros

Eliminates Null Errors

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.

Full Type Safety

Integrates seamlessly with mypy and PEP561 for rigorous type checking, including emulated Higher Kinded Types, ensuring compile-time safety for complex functional patterns.

Functional Dependency Injection

The RequiresContext container enables typed, explicit dependency injection without cluttering function signatures, demonstrated in the Django example for configurable game logic.

Separates Pure and Impure Code

IO and IOResult containers clearly mark impure operations (like I/O), enforcing better architecture and testability, as illustrated in the refactored HTTP request example.

Cons

Complex Setup Requirements

Requires configuring a custom mypy plugin and specific type-checker settings, which adds initial overhead and may conflict with existing tooling in some projects.

Verbose Code Style

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.

Ecosystem Friction

Integrating with third-party libraries that expect exceptions or None values requires additional wrapping layers, increasing boilerplate and maintenance effort.

Frequently Asked Questions

Quick Stats

Stars4,266
Forks147
Contributors0
Open Issues67
Last commit2 days ago
CreatedSince 2019

Tags

#functional-programming#mypy-stubs#async-programming#dependency-injection#type-safety#python3#python#mypy#error-handling#fp#mypy-plugins#monads

Built With

M
Mypy
P
Python

Links & Resources

Website

Included in

Python290.8kTyping2.0k
Auto-fetched 1 day ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub