API

cbs

Main interface for cbs.

Re-exports cbs.cast, and everything from cbs.env and cbs.settings.

cbs.settings

class cbs.settings.BaseSettings

Base class for env switchable settings configuration.

getattr_factory()

Returns a function to be used as __getattr__ in a module.

Returns:

function suitable for module-level __getattr__

classmethod use(env='DJANGO_MODE')

Helper for accessing sub-classes via env var name.

Gets a sub-class instance using get_settings_instance, and returns the results of calling getattr__factory and dir_factory on it.

Parameters:

env (str) – Envirionment variable to get settings mode name from.

Returns:

functions suitable for module-level __getattr__ and __dir__

cbs.env

class cbs.env.env(*args, **kwargs)

property to make environment variable based settings simpler.

Parameters:
  • default (Any) – default value If it’s a string, it will be passed to the cast function When used as a decorator, this is the method.

  • key (str) – Override environment variable name (Defaults to class attribute name)

  • prefix (str) – Prefix to key when looking up os.environ

  • cast (func) – Function to cast str values.

classmethod bool(*args, **kwargs)

Helper for bool-cast settings.

Uses cast.as_bool()

classmethod dburl(*args, **kwargs)

Helper for DB-Url cast settings.

Uses urls.parse_dburl()

classmethod int(*args, **kwargs)

Helper for int-cast settings.

Uses int

classmethod list(*args, **kwargs)

Helper for list-cast settings.

Uses cast.as_list()

classmethod tuple(*args, **kwargs)

Helper for tuple-cast settings.

Uses cast.as_tuple()

cbs.cast

Type-casting helper functions.

cbs.cast.as_bool(value: str) bool

Smart cast value to bool

Parameters:

value (str) – Value to cast. Value will be stripped and .lower(). True values: ("y", "yes", "on", "t", "true", "1") False values: ("n", "no", "off", "f", "false", "0") All other values raise a ValueError

cbs.cast.as_list(value: str) list

Smart cast value to list by splitting the input on “,”.

cbs.cast.as_tuple(value: str) tuple

Smart cast value to tuple by splitting the input on “,”.

cbs.urls

URL style config parsing.

Inspired by dj_database_url

cbs.urls.parse_dburl(url: str) dict

A light-weight implementation of dj_database_url

Parameters:

url (str) – A db-url format string

Returns:

A Django DATABASES compatible configuration dict. Unknown keys in the querystring will be placed verbatim in the OPTIONS sub-dict.