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.3.tar.gz (5.2 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.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fieldconfig-0.1.3.tar.gz
  • Upload date:
  • Size: 5.2 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.3.tar.gz
Algorithm Hash digest
SHA256 15e574d9b9975a0fa2d160f2ce94d013fa7f7adb2914978dcae30b69f004413e
MD5 ae006b50abb315acfdf6bc546a527a0f
BLAKE2b-256 a3c7711b5b4936186727cb28bfc61d457cb7b7eba6df6334e5a13f0205a5d1e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fieldconfig-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6edbf5c060132755fceca65cb6569c5d4b8111d0c25978111928ee3a5c8dc025
MD5 4b3a1f18750714c2a95cfb422c926081
BLAKE2b-256 a804d0d6cbf794872784414f5a0405a96bb3ba4d99aaa91fd3c215f21ae5b1d0

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