Skip to main content

A simple config parser for python

Project description

sokconfig

Just a simple util for my personal use. This aims to make it easier to load settings.

Example

import ast

from sokconfig.settings import Settings
from sokconfig.values import IntValue, ListValue


class Config(Settings):
    a = IntValue(5, min_value=0, max_value=10, post_mutator=lambda x: x + 1)
    b = IntValue(2, min_value=0, max_value=10, extra_validator=lambda x: x % 2 == 0, name="TestValueB")
    c = IntValue(None, pre_mutator=int)
    d = ListValue(None, pre_mutator=ast.literal_eval)
    e = ListValue([], element_type=int)


Config.fill_empty_names()

t = {"a": 1, "TestValueB": 4, "c": "3", "d": "[1,2,3]"}
print(Config.get_values())
Config.set_values(t)
Config.e.append(4)
Config.validate_values()
print(Config.get_values())
{'a': IntValue(value=6, min_value=0, max_value=10), 'b': IntValue(value=2, min_value=0, max_value=10), 'c': IntValue(value=None, min_value=None, max_value=None), 'd': ListValue(value=None), 'e': ListValue(value=[])}
{'a': IntValue(value=2, min_value=0, max_value=10), 'b': IntValue(value=4, min_value=0, max_value=10), 'c': IntValue(value=3, min_value=None, max_value=None), 'd': ListValue(value=[1, 2, 3]), 'e': ListValue(value=[4])}

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

sokconfig-1.0.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

sokconfig-1.0.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file sokconfig-1.0.0.tar.gz.

File metadata

  • Download URL: sokconfig-1.0.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.9 Windows/10

File hashes

Hashes for sokconfig-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a27ab14757223942f4b16e1e90eba20acbe06f97809b5f6fc20d507a7ce20289
MD5 1c047a9910dad6a2a81a278143eac8c5
BLAKE2b-256 18fdc17c911e980b78b70eb2fab9254abc6cbe97fe04907f86eeb0aded5e666a

See more details on using hashes here.

File details

Details for the file sokconfig-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sokconfig-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.9 Windows/10

File hashes

Hashes for sokconfig-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3e910ffe92f2f9e2e8810202d8f579fdf8da791516265bed810ec5a477f83de
MD5 aee82e2490edc01aff1988f5fa5f2069
BLAKE2b-256 1fb75c9106606fc66b2e7b269a21796415e2a120239f742173e0d764d8da0045

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