Skip to content

Configuration management library with value substitution for Python

License

Notifications You must be signed in to change notification settings

fskoras/subconfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SubConfig

Configuration management library with value substitution for python

Basic Usage

sample.json

{"Marco": "Polo"}

sample.py

from subconfig import SubConfig

sc = SubConfig(files=["sample.json"])

print(sc["Marco"])

Output:

Polo

Value Substitution

substitute.json

{
  "name": "Jane",
  "surname": "Doe",
  "full_name": "${name} ${surname}"
}

substitute.py

from subconfig import SubConfig

sc = SubConfig(files=["substitute.json"])

print(sc["full_name"])

Output:

Jane Doe

Nested value access

Structured configuration values can be addressed using dot notation

nested.json

{
  "books": [{"title":  "Little Red Riding Hood"}],
  "favorite_book": "${books.0.title}"
}

nested.py

from subconfig import SubConfig

sc = SubConfig(["nested.json"])

print(sc["books.0.title"])

# Dot notation works for value substitution as well
print(sc["favorite_book"])

Output:

Little Red Riding Hood
Little Red Riding Hood