Skip to main content

Make your functions return something meaningful and safe!

Project description

returns

wemake.services Build Status Coverage Status Documentation Status Python Version wemake-python-styleguide

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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

returns-0.3.0.tar.gz (9.3 kB view hashes)

Uploaded Source

Built Distribution

returns-0.3.0-py3-none-any.whl (29.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page