Skip to content

oberos/python_config_loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Python Config Loader

This snippet allow to load JSON file directly to pydantic model.

Getting started

Requires Pydantic.
Put config folder in your project.
Modify Main model in config.py according to your needs
Run config.py file to generate config.json template
Fill config.json with your key: value pairs.

Usage

{
    "some_key1": "some_value1",
    "some_key2": "some_value2",
    "some_key3": [1, 2, 3],
    "some_key4": {
        "sub_key1": "some_sub_value1",
        "sub_key2": "some_sub_value2"
    },
    "some_key5": ""
}
from config import load_config


config = load_config()
print(config)
print(config.some_key1)
print(config.some_key2)
print(config.some_key3)
print(config.some_key4)
print(config.some_key4.sub_key1)

Outputs

some_key1='some_value1' some_key2='some_value2' some_key3=[1, 2, 3] some_key4=Sub(sub_key1='some_sub_value1', sub_key2='some_sub_value2')
some_value1
some_value2
[1, 2, 3]
sub_key1='some_sub_value1' sub_key2='some_sub_value2'
some_sub_value1

About

Load JSON config into pydantic model

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages