How to use the dynaconf.settings.using_env function in dynaconf

To help you get started, weā€™ve selected a few dynaconf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rochacbruno / dynaconf / example / yaml_example / settings_file / app.py View on Github external
# 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
github rochacbruno / dynaconf / example / yaml_example / yaml_as_extra_config / app.py View on Github external
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",
}
github rochacbruno / dynaconf / example / vault / write.py View on Github external
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"})
github rochacbruno / dynaconf / example / redis_example / redis_example.py View on Github external
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)
github rochacbruno / dynaconf / example / common-encoding / program.py View on Github external
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"
github rochacbruno / dynaconf / example / common / program.py View on Github external
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"
github rochacbruno / dynaconf / example / redis_example / write.py View on Github external
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"})