Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# using [default] + [development] + [global] values
print("* All values")
print(settings.HOST)
print(settings.PORT)
print(settings.USERNAME)
print(settings.PASSWORD)
print(settings.LEVELS)
print(settings.TEST_LOADERS)
print(settings.MONEY)
print(settings.AGE)
print(settings.ENABLED)
print(settings.CUSTOM)
print("* Switiching to production")
# using [production] env values for context
with settings.using_env("PRODUCTION"):
print(settings.CUSTOM)
print(settings.HOST)
print("* Switiching to development")
# back to default [development] env
print(settings.get("CUSTOM"))
print(settings.HOST)
print("* Switiching to production")
# set env to [production]:
settings.setenv("production")
print(settings.HOST)
print(settings.CUSTOM)
print("* Switiching to development")
# back to [development] env again
from dynaconf import settings
print(settings.YAML)
print(settings.HOST)
print(settings.PORT)
# using production values for context
with settings.using_env("PRODUCTION"):
print(settings.ENVIRONMENT)
print(settings.HOST)
# back to development env
print(settings.get("ENVIRONMENT"))
print(settings.HOST)
print(settings.WORKS)
assertions = {
"HOST": "dev_server.com",
"PORT": 5000,
"ENVIRONMENT": "this is development",
"WORKS": "yaml_as_extra_config",
}
from dynaconf import settings
from dynaconf.loaders import vault_loader
vault_loader.write(settings, {"SECRET": "vault_works"})
with settings.using_env("dev"):
vault_loader.write(settings, {"SECRET": "vault_works_in_dev"})
from dynaconf import settings
print(settings.FOO) # noqa
# >>> 'foo_is_default'
with settings.using_env("development"):
assert settings.SECRET == "redis_works_in_development", settings.SECRET
assert settings.FOO == "foo_is_default"
available_envs = ["default", "development", "production"]
all_secrets = []
for env in available_envs:
env_settings = settings.from_env(env)
assert env_settings.SECRET == "redis_works_in_{0}".format(
env
), env_settings.SECRET
assert env_settings.FOO == "foo_is_default", env_settings.FOO
all_secrets.append(env_settings.SECRET)
print(available_envs)
print(all_secrets)
print(
"Dynaconf can switch environments programatically with context managers."
)
print("Dynaconf has extensions for Flask and Django.")
print("Dynaconf can read values from yaml, ini, json and py files.")
print("Dynaconf can load sensitive values from vaultproject.io.")
print(
"Dynaconf can load dynamic fresh values from Redis server "
"(useful for feature flagging)."
)
print("#" * 79)
print(settings.dynaconf_banner)
print("Learn more at http://github.com/rochacbruno/dynaconf")
with settings.using_env("testing"):
assert settings.SERVER == "testserver.com"
assert settings.SERVER == "customserver.com"
print(
"Dynaconf can switch environments programatically with context managers."
)
print("Dynaconf has extensions for Flask and Django.")
print("Dynaconf can read values from yaml, ini, json and py files.")
print("Dynaconf can load sensitive values from vaultproject.io.")
print(
"Dynaconf can load dynamic fresh values from Redis server "
"(useful for feature flagging)."
)
print("#" * 79)
print(settings.dynaconf_banner)
print("Learn more at http://github.com/rochacbruno/dynaconf")
with settings.using_env("testing"):
assert settings.SERVER == "testserver.com"
assert settings.SERVER == "customserver.com"
from dynaconf import settings
from dynaconf.loaders import redis_loader
redis_loader.write(settings, {"SECRET": "redis_works"})
with settings.using_env("dev"):
redis_loader.write(settings, {"SECRET": "redis_works_in_dev"})