Skip to main content

Json config files with a statically defined structure.

Project description

staticconfig

Json config files with a staticly defined structure.

This is common code which I used accross many projects.

Usage

A config file's structure is defined by subclassing Config and filling the constructor with attribute assignments.

Then a file is loaded with the from_json classmethod:

  • If the file exists, it returns an instance of the config class.
  • If the file does not exist, it creates one and raises a ConfigError.

The class Namespace provides syntactic sugar around dicts.

Example

from staticconfig import Namespace, Config


class MyConfig(Config):

  def __init__(self):
    super().__init__()

    self.option1 = "default1"
    self.option2 = 0
    self.option3 = Namespace()
    self.option3.suboption1 = True
    self.option3.suboption2 = ["en", "de"]


# If the file doesn't exists this will create it with the default values and raise a ConfigError
config = MyConfig.from_json("config.json")

The produced config file:

{
  "option1": "default1",
  "option2": 0,
  "option3": {
    "suboption1": true,
    "suboption2": [
      "en",
      "de"
    ]
  }
}

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

staticconfig-0.0.6.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

staticconfig-0.0.6-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file staticconfig-0.0.6.tar.gz.

File metadata

  • Download URL: staticconfig-0.0.6.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for staticconfig-0.0.6.tar.gz
Algorithm Hash digest
SHA256 0a5381917c1b077e6ff8b1d34eb8183b849ae6abee3a015df1b0c32fee61cfca
MD5 706ee11f91bd3d14b4f845fd983101c4
BLAKE2b-256 345e07e9e5332c54b53d8728fa6729a9a1204d8e53de62bf0a492927a345d2f5

See more details on using hashes here.

File details

Details for the file staticconfig-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: staticconfig-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for staticconfig-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f36d52c9501e2fcfbf06bcb4ab20b40f017de10ac12a6b66ec047b99a8ccd957
MD5 b743f53d4dbd441011ab0826fba4fd1d
BLAKE2b-256 d4545bcd009bfa934bd186b42bf571b7af0eda4b2d191cefc0a76d9b8d993d71

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