
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Load small app configurations from environment variables, command line arguments and config files, according to a pydantic model.
[!WARNING] This project is under development and not yet feature complete or tested.
[!WARNING] This project is BETA and will be experimental for the forseable future. Interfaces and functionality are likely to change, and the project itself may be scrapped. DO NOT use this software in any project/software that is operational.
Conflator is a configuration-handling library for Python. It is designed to simplify the handling of configuration from multiple sources, such as environment variables, command line arguments, and configuration files. As an application or library developer, you specify your configuration schema with a Pydantic model, and conflator will handle the rest.
Conflator loads configuration in the following order:
-f filename
or --set value.deeper=foo
)...and then validates the merged configuration against the Pydantic model.
Conflator is available on PyPI:
pip install conflator
Or using poetry:
poetry add conflator
EnvVar
and CLIArg
for environment variable and command-line argument support, respectively.from pydantic import Field
from conflator import EnvVar, CLIArg, ConfigModel
from annotated_types import Annotated
class AppConfig(ConfigModel):
host: str = "localhost"
port: Annotated[int, EnvVar("PORT"), CLIArg("--port")] = 5432
user: Annotated[str, EnvVar("USER"), CLIArg("--user"), Field(description="Your username")] = "foo"
from conflator import Conflator
config = Conflator(app_name="my_app", model=AppConfig).load()
print(f"User: {config.user}")
Try setting MY_APP_USER in the environment to see the value change, or use the --user
flag to override the value.
your-app -f ./config/base.yaml -f ./config/production.yaml
from annotated_types import Annotated
from conflator import EnvVar, CLIArg, ConfigModel
class DeeperConfig(ConfigModel):
nested: Annotated[str, EnvVar("NESTED"), CLIArg("--nested")] = "default"
class Config(ConfigModel):
host: str = "localhost"
port: int = 543
deeper: DeeperConfig = DeeperConfig()
config = Conflator(app_name="my_app", model=AppConfig).schema() # uses pydantic's schema method behind the scenes
CLI arguments and environment variables are defined per model type, not per model instance. This means that you cannot have different CLI arguments or environment variables for different instances of the same model. Some support for this may be added in the future.
Including ConfigModel's from other packages, to nest their configuration with yours, is possible. However, there is no way to resolve conflicts between CLI arguments and environment variable naming between two different config schemas. Some support for this may be added in the future.
FAQs
Load small app configurations from environment variables, command line arguments and config files, according to a pydantic model.
We found that conflator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.