clout package

Submodules

clout.exceptions module

exception clout.exceptions.CloutException[source]

Bases: Exception

Base exception for Clout exceptions.

exception clout.exceptions.MissingInput(group, string, found)[source]

Bases: clout.exceptions.CloutException

Raised for missing command-line arguments.

exception clout.exceptions.ValidationError[source]

Bases: clout.exceptions.CloutException

Raised for invalid command-line arguments.

Module contents

class clout.Command(type, *args, name=None, app_name=None, callback=<function Command.<lambda>>, params=None, context_settings=None, epilog=None, **kwargs)[source]

Bases: click.core.Command

A click.Command built from an attr.dataclass() or dataclasses.dataclass().

build()[source]

Return an instance of self.type, built from the command line arguments.

main(**kwargs)[source]

Run the command and exit the program afterwards.

Upcalls directly to click.MultiCommand.main().

clout.load_env(type: Type[CT_co], prefix: str = '')[source]

Load environment variables for a class into a dict.

For example, define a class

import attr


@attr.dataclass
class Database:
    host: str
    port: int

Load the environment variables into a dict, setting the prefix for our app.

d = clout.load_env(Database, prefix='MYAPP')
assert d == {'host': 'example.com', 'port': 1234}

Run the app with environment variables set.

export MYAPP_HOST=example.com
export MYAPP_PORT=1234
class clout.DeepChainMap(*maps)[source]

Bases: collections.ChainMap

Combine multiple dicts into a deep mapping.

Lookups that fail in the first dict will be checked in the next one.

>>> import clout
>>> maps = [{"a": {}}, {"a": {"b": {}}}, {"a": {"b": {"c": 1337}}}]
>>> dcm = clout.DeepChainMap(*maps)
>>> dcm["a"]["b"]["c"]
1337