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 details)

Uploaded Source

Built Distribution

const_utils-0.0.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file const_utils-0.0.1.tar.gz.

File metadata

  • Download URL: const_utils-0.0.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.0

File hashes

Hashes for const_utils-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f8f7a932c1f3f3bfb152f3d69c2c50400428615a8e534e62f0021bfec5521d43
MD5 8a5ab2c29e8847ecd498f734433001bf
BLAKE2b-256 ae43150e7fd983a32d7dbd24d2c6df55c41e6e3022127a6af25c1f5e3fc44617

See more details on using hashes here.

File details

Details for the file const_utils-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: const_utils-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.0

File hashes

Hashes for const_utils-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f5f87a9068b60486eba9e44182d7f5165f655c15e743e514704cd5c4483e499
MD5 1e7ac6a621c75e37dac07d1eec239b7f
BLAKE2b-256 fe83d7baa046bab289d0e4e0f35b46d6d489bee970e128115949ec596720d666

See more details on using hashes here.

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