Skip to content

A short and handy python script to handle environment inside the project.

Notifications You must be signed in to change notification settings

bhrzk/PythonConfigManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Config Manager

A simple and handy python script to handle configurations for a python project.

How does it work?

Well, it's easy. You set your configurations as environment variables and let the script know what are those and the rest will be handled. Right now there are two types of environment supported:

1- Required: These are the ones which if the module cannot find it will return an error and terminate the project from running.

2- Optional: These are the ones you set default value so if the module finds them ins environment will override the default otherwise the default value uses.

Example:

Initialization:

configs.py:

    from configs import Configs

    required_envs = ["required_test_env"]

    optional_envs = {
        "optional_env_test1": "1",
        "optional_env_test2": "2"
    }

    Configs = Config(required_envs,optional_envs)
    Configs.load_initial_env("./..env")

Simple use get:

    from configs import Configs    

    print(Configs["optional_env_test1"])
    # >>> 1

    # Set configs in runtime
    Configs["runtime_config"] = "hello"
    print(Configs["runtime_config"])
    # >>> hello

    # Change a config in runtime
    Configs["runtime_config"] = "bye"
    print(Configs["runtime_config"])
    # >>> bye

    # Delete a config
    del Configs["runtime_config"]

About

A short and handy python script to handle environment inside the project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages