Skip to main content

A simple configuration files manager package

Project description

ConfigDmanager

Installation

A simple pip install will do :

python -m pip install ConfigDmanager

Use

  • Suppose we have two Configuration files ( of json type ) :

    • ParentConfig.json :

      {
      "__name": "ParentConfig",
      "param1": "Value 1"
      }
      
    • MainConfig.json :

      • The __parent parameter specifies the path to another configuration file that will give us default values ( Think of it as inheritance ).
      • The text contained between brackets will be reinterpreted in runtime :

      in the example below {param1} will be reinterpreted as "Value 1"

      • The use of environment variables for sensitive data like passwords is also possible : through this text {os_environ[password]}
      • You can also read the content of a text file with a simple : {read_file[file_path]} as shown in the example below.
      {
        "__name": "MainConfig",
        "__parent": "demo.ParentConfig",
        "param2": "Value 2 and {param1}",
        "user_info": {"user": "username", "password": "{os_environ[password]}"},
        "long_text": "{read_file[./demo.py]}"
      }
      
  • To import those configuration using configDmanager, use this demo code :

from configDmanager import import_config


class RandomClass:
    def __init__(self, param1, param2, user_info, long_text):
        print(f"param1: {param1}")
        print(f"param2: {param2}")
        print(f'my user: {user_info.user}')
        print(f'my user: {user_info.password}')
        print(f'my long text: "{long_text[:40]}"')


config = import_config('MainConfig')

print("## Object 1")
obj = RandomClass(**config)


# You can also select specific keys
print("## Object 2")
another_obj = RandomClass(param2='Another Value', long_text="Not so long", **config[['param1', 'user_info']])

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

ConfigDmanager-0.1.6.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

ConfigDmanager-0.1.6-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file ConfigDmanager-0.1.6.tar.gz.

File metadata

  • Download URL: ConfigDmanager-0.1.6.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for ConfigDmanager-0.1.6.tar.gz
Algorithm Hash digest
SHA256 094cf8f1a4606454022ec293735b0a623ae369fab215f3305af5547a182cb5f7
MD5 3a613401c122b0ae88b69e8eea9a8134
BLAKE2b-256 f4ad1a2900d8023a28ec9d2d0de9d22c3ef2fcc5f22a5c8ba2b55caeeddc6cb4

See more details on using hashes here.

File details

Details for the file ConfigDmanager-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: ConfigDmanager-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for ConfigDmanager-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 54ba72a0a674be12dc66b3445ea9c97c95087dd8bb335473fafaadce0c2e7650
MD5 0258ba4001dd81bbe26be24d1aacfbe2
BLAKE2b-256 7775409c8fcdd2830ab20b8903a50a7cca739c0a0c590faf0a188f355f1e8802

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