Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

oberos/python_config_loader

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
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

 
 
 

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.