Skip to main content

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"
    ]
  }
}

Release files for staticconfig 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for staticconfig 0.0.6
File Size Uploaded
staticconfig-0.0.6.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for staticconfig 0.0.6
File Interpreter ABI Platform
staticconfig-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 7.4 kB

Release files / staticconfig-0.0.6.tar.gz

Download URL staticconfig-0.0.6.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0a5381917c1b077e6ff8b1d34eb8183b849ae6abee3a015df1b0c32fee61cfca
BLAKE2b-256 checksum
How to use checksums
345e07e9e5332c54b53d8728fa6729a9a1204d8e53de62bf0a492927a345d2f5
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / staticconfig-0.0.6-py3-none-any.whl

Download URL staticconfig-0.0.6-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f36d52c9501e2fcfbf06bcb4ab20b40f017de10ac12a6b66ec047b99a8ccd957
BLAKE2b-256 checksum
How to use checksums
d4545bcd009bfa934bd186b42bf571b7af0eda4b2d191cefc0a76d9b8d993d71
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page