Skip to main content

Configuration Managment in Python

Project description

##ConfigField ####Configuration Managment for Python Inspired by ml_collections

#####Features

  • Dot-Based Access to Fields
  • Type-Safety
  • Field Value Validation
  • Intermediate Attribute Creation
  • Freezing
from fieldconfig import Config
from fieldconfig import Field
from fieldconfig.field import ValidationError

cfg = Config()
cfg.str = "John"
cfg.nest = Config()
cfg.nest.pos_int = Field(1, validator=lambda x: x > 0)
cfg.nest.tup = Field(None, ftype=tuple)
cfg["nest.tup"] = [1, 2]

print(cfg.to_dict())  # {'str': 'John', 'nest': {'pos_int': 1, 'tup': (1, 2)}}

try:
    cfg.str = 1
except TypeError as e:
    print(e)  # Cannot cast 1 from type float to type str

try:
    cfg.nest.pos_int = -1
except ValidationError as e:
    print(e)  # The provided value -1 (int) does not meet the criteria: lambda x: x > 0

cfg.freeze()
try:
    cfg.str = "Doe"
except ValueError as e:
    print(e)  # Config is frozen


cfg = Config(create_intermediate_attributes=True)
cfg.branch.twig.nleafs = 3
print(cfg.to_dict())  # {'branch': {'twig': {'nleafs': 3}}}
cfg.disable_intermediate_attribute_creation()
try:
    cfg.ranch.twig.color = "green"
except AttributeError as e:
    print(e)
    # Cannot add key ranch because the config has intermediate attribute
    # creation disabled. Did you mean "branch" instead of "ranch"?

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

fieldconfig-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fieldconfig-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file fieldconfig-0.1.0.tar.gz.

File metadata

  • Download URL: fieldconfig-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.1 CPython/3.12.2 Linux/6.5.0-21-generic

File hashes

Hashes for fieldconfig-0.1.0.tar.gz
Algorithm Hash digest
SHA256 192c6ce7e1316e93afb779eb4b92c4778937b96b9a22b384485c7c0640119a76
MD5 d8e9cdd9435c58024ca3b3e7e8d381d0
BLAKE2b-256 b66ca1fcf0bb7dfdceeea0dc3ab6f4da6a117365d6c3a7180c02dc6bf0030be3

See more details on using hashes here.

File details

Details for the file fieldconfig-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fieldconfig-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.1 CPython/3.12.2 Linux/6.5.0-21-generic

File hashes

Hashes for fieldconfig-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c774829ff3a411b1717b90d33fa76a419b3222c5c54a00a4ca9256b676e377f0
MD5 9c37724aef0a1445f077b5d59ba939f1
BLAKE2b-256 0f6c2bfc41f55aa4205131226c6d6d205b23c1495c73b9a1eced2451f3ff246f

See more details on using hashes here.

Supported by

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