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-safe
  • 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.1.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.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fieldconfig-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 2240bf6ef1ff7170467506a49dcce1a32e5be7e1219de97052cac806722a24d3
MD5 a8c7443362f04e58ed5b60ee2b8e6cb7
BLAKE2b-256 46b51af2e8b2ab301484443d3330783d4b7995d4d821f75282061abe787c7a65

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fieldconfig-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e5229c997cf606bc18c3ecf1cd469ee3c167264ca1904e4b81a4d3ccdaac14e
MD5 440a95abd3e4bd2250e9c89ba927d635
BLAKE2b-256 562b4c36361975e4986dc553e2c22cdb040e83ddd83d95b5fc9935cd19cd77d7

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