python-dependency-injector/examples/providers/configuration/configuration_alias.py

37 lines
931 B
Python
Raw Normal View History

"""`Configuration` provider alias example."""
from dependency_injector import containers, providers
from environs import Env
class Container(containers.DeclarativeContainer):
config = providers.Configuration()
2021-09-30 22:32:21 +03:00
if __name__ == "__main__":
env = Env()
container = Container()
with container.config.some_plugin_name as plugin:
plugin.some_interval_ms.override(
env.int(
2021-09-30 22:32:21 +03:00
"SOME_INTERVAL_MS",
default=30000,
),
)
with plugin.kafka as kafka:
kafka.bootstrap_servers.override(
env.list(
2021-09-30 22:32:21 +03:00
"KAFKA_BOOTSTRAP_SERVERS",
default=["kafka1", "kafka2"],
),
)
kafka.security_protocol.override(
env.str(
2021-09-30 22:32:21 +03:00
"KAFKA_SECURITY_PROTOCOL",
default="SASL_SSL",
),
)