Skip to main content

Effective constant management tools

Project description

Const-Utils

const-utils is a small-yet-effective library that offers some tools for working with Python constants. Its main feature is the Constant Class, which includes utilities for accessing constants, stored within a container class.

Defining constant classes is available by using ConstClassMeta (as a metaclass), or the standard BaseConstClass (by inheritance).

Examples

Creating a constant class

class CountryConsts(BaseConstClass):
    US = 'United States of America'
    UK = 'United Kingdom'

Access options

Access from the class itself

>>> CountryConsts.as_dict()  # {'US': 'United States of America', 'UK': 'United Kingdom'}
>>> CountryConsts['US']  # 'United States of America
>>> Country.const_names  # ['US, 'UK']
>>> Country.const_values  # ['United States of America', 'United Kingdom']

Access global/local constants

>>> # Access current global/local constants (depends on kwarg `local`)
>>> # as a dictionary of names to values
>>> access_namespace_consts(local=False)

Storing class constants to a namespace

>>> # Store constants in a module
>>> CountryConsts.apply_to_module('some_module_name', override=True)
>>> # Store constants as globals
>>> CountryConsts.apply()
>>> # Store constants as locals
>>> CountryConsts.apply(local=True)

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

const_utils-0.0.1.tar.gz (6.2 kB view hashes)

Uploaded Source

Built Distribution

const_utils-0.0.1-py3-none-any.whl (6.0 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