Skip to main content

A supercharged dict used as configuration

Project description

Documentation

https://configdict.readthedocs.io

Installation

$ pip install configdict

CheckedDict

A dictionary based on a default prototype. A CheckedDict can only define key:value pairs which are already present in the default. It is possible to define a docstring for each key and different restrictions for the values regarding possible values, ranges and type. A CheckedDict is useful for configuration settings.

ConfigDict

Based on CheckedDict, a ConfigDict is a persistent, unique dictionary. It is saved under the config folder determined by the OS and it is updated with each modification. It is useful for implementing configuration of a module / library / app, where there is a default/initial state and the user needs to be able to configure global settings which must be persisted between sessions (similar to the settings in an application)

Example

config = ConfigDict("myproj.subproj")
config.addKey("keyA", 10, doc="documentaion of keyA")
config.addKey("keyB", 0.5, range=(0, 1))
config.addKey("keyC", "blue", choices=("blue", "red"),
              doc="documentation of keyC")
config.load()

Alternatively, a ConfigDict can be created all at once:

config = ConfigDict("myapp",
    default = {
        'font-size': 10.0,
        'font-family': "Monospace",
        'port' : 9100,
    },
    validator = {
        'font-size::range' : (8, 24),
        'port::range' : (9000, 65000),
        'font-family::choices' : {'Roboto', 'Monospace'},
    },
    docs = {
        'port': 'The port number to listen to',
        'font-size': 'The size of the font, in pixels'
    }
)

This will create the dictionary and load any persisted version. Any saved modifications will override the default values. Whenever the user changes any value (via config[key] = newvalue) the dictionary will be saved.

In all other respects a ConfigDict behaves like a normal dictionary.

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

configdict-2.13.5.tar.gz (36.9 kB view details)

Uploaded Source

Built Distribution

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

configdict-2.13.5-py3-none-any.whl (33.7 kB view details)

Uploaded Python 3

File details

Details for the file configdict-2.13.5.tar.gz.

File metadata

  • Download URL: configdict-2.13.5.tar.gz
  • Upload date:
  • Size: 36.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for configdict-2.13.5.tar.gz
Algorithm Hash digest
SHA256 f90fe6c2f46abec67c3596623a3e854b7b70a7fd872c8541dd917bc9d955a0e8
MD5 a8d8d33b48a0d12eafc4a8f9661efa97
BLAKE2b-256 6bc27dc923551e6c2c22ab19122e1ab6756d74261087d8a9c1efab00144716c2

See more details on using hashes here.

File details

Details for the file configdict-2.13.5-py3-none-any.whl.

File metadata

File hashes

Hashes for configdict-2.13.5-py3-none-any.whl
Algorithm Hash digest
SHA256 184a1266aec65a2a0a68da862913b599827800d6c0351e690ddc3031110cf57f
MD5 2063190974f7c2e2a1267e89d4a96f3c
BLAKE2b-256 12ed0a2ab253dfabb0fe9b3ec6b4deba9293ffeb7261498e1e6ee19554f5ce19

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