Make your functions return something meaningful and safe!
Project description
returns
Make your functions return something meaningful and safe!
Features
- Provides primitives to write declarative business logic
- Fully typed with annotations and checked with
mypy, allowing you to write type-safe code as well - Pythonic and pleasant to write and to read (!)
Installation
pip install returns
What's inside?
We have several the most iconic monads inside:
- Result, Failure, and Success (also known as
Either,Left, andRight) - Maybe, Some, and Nothing
We also care about code readability and developer experience, so we have included some useful features to make your life easier:
Example
from returns.do_notation import do_notation
from returns.either import Result, Success, Failure
class CreateAccountAndUser(object):
"""Creates new Account-User pair."""
@do_notation
def __call__(self, username: str, email: str) -> Result['User', str]:
"""Can return a Success(user) or Failure(str_reason)."""
user_schema = self._validate_user(username, email).unwrap()
account = self._create_account(user_schema).unwrap()
return self._create_user(account)
# Protected methods
# ...
We are covering what's going on in this example in the docs.
Inspirations
This module is heavily based on:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file returns-0.3.0.tar.gz.
File metadata
- Download URL: returns-0.3.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.11 CPython/3.6.6 Darwin/18.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3899f29bbecd16794eb491fdfa0d98ef7453ea8de867f24bcae680ba23ef2c9d
|
|
| MD5 |
d9a28c66cb8e14492da14e468ac38d7c
|
|
| BLAKE2b-256 |
28fa896d164f5bdaae305ca198b3d68c7f9c625dd4c7c28a8dc391a384607822
|
File details
Details for the file returns-0.3.0-py3-none-any.whl.
File metadata
- Download URL: returns-0.3.0-py3-none-any.whl
- Upload date:
- Size: 29.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.11 CPython/3.6.6 Darwin/18.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
881f759a45cdaa92a52ef183bc1a051163b05389de1b2d30f19d63690e999aa0
|
|
| MD5 |
98e115b681de32c7f5e3d0d16c48e845
|
|
| BLAKE2b-256 |
251ec01ebf5a97f6e44fa0f4902329059ce4f0af441824a5498d07d5a161a3b8
|