Configuration Management for Python.
$ pip install confoid
import confoid
new_settings = confoid.Config("application.yml")
Multiple files can be provided in order
and will merge with the previous configuration.
import confoid
config_files = ["application.yml", "application.development.yml"]
new_settings = confoid.Config(
config_files,
base_dir="config",
)
import confoid
new_settings = confoid.Config("application.yml", current_env="development")
# this will load application.yml and application.{current_env}.yml
settings.username == "admin" # dot notation with multi nesting support
settings['password'] == "secret123" # dict like access
settings.get("nonexisting", "default value") # Default values just like a dict
settings.databases.name == "mydb" # Nested key traversing
application.yml
default:
prefix:
otp: "user-otp"
auth: "auth-tokens"
type: inmemory
redis:
url:
application.development.yml
default:
type: redis
redis:
url: redis://saviof.com
encoding: "utf8"
Will resolve to the following final config
default:
prefix:
otp: "user-otp"
auth: "auth-tokens"
type: redis
redis:
url: redis://saviof.com
encoding: "utf8"
All fields can use environment variables with a fallback default value
password: ${TEST_SERVICE_DEFAULT_PASSWORD:test}
from confoid import Validator
config_files = ["application.yml", "application.development.yml"]
new_settings = confoid.Config(
config_files,
base_dir="config",
validators=[
Validator("default", "default.redis.password", must_exist=True)
Validator("otp.length", gte=6, lte=20)
Validator("default.type", values=["inmemory", "redis"])
]
)