Skip to content

Dog-Egg/configat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ConfigAt

codecov

A simple recursive loader.

Loader syntax: @<loader_name>[-loader_name...]:<loader_variable>

Installation

pip install git+https://github.com/Dog-Egg/configat.git

Usage

config.py

import configat 

DB_PASSWORD = configat.resolve("@env:DB_PASSWORD")
print(DB_PASSWORD)
$ export DB_PASSWORD=my_password

$ python config.py
my_password

No need to change the code. To load the password from a file, simply change the DB_PASSWORD environment.

$ echo "my_secret_password" > $(pwd)/db_password
$ export DB_PASSWORD=@file-strip:$(pwd)/db_password # A series loader is used here

$ python config.py
my_secret_password

Default Loaders

  • env - Load from a environment variable.
  • file - Load from a file.
  • strip - It is usually used together with other loaders, strip the whitespace characters on both sides of the content.
  • json - Load from a JSON string.

Type Casting

import configat

PORT = configat.resolve("@env:PORT", cast=int)

Configat Docgen

configat provides a document generator to extract the config expressions from the code. It is useful to generate documentation for the config.

Installation

pip install "configat[docgen] @ git+https://github.com/Dog-Egg/configat.git"

Usage

python -m configat.docgen .

Output Example:

Config Required Help
@env:VAR1 Yes help text
@env:VAR2 No
@file:/run/file Yes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages