How to use the dynaconf.settings.get 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 / 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",
}


for key, value in assertions.items():
    found = settings.get(key)
    assert found == getattr(settings, key)
    assert (
github rochacbruno / dynaconf / example / multiple_folders / app.py View on Github external
from dynaconf import settings

print("development")
print(settings.VAR1)
print(settings.VAR2)


assertions = {"VAR1": "var1_dev", "VAR2": "var2_dev"}

for key, value in assertions.items():
    found = settings.get(key)
    assert found == getattr(settings, key)
    assert (
        found == value
    ), "expected: {key}: [{value}] found: [{found}]".format(**locals())


print("production")
print(settings.from_env("production").VAR1)
print(settings.from_env("production").VAR2)

assertions = {"VAR1": "var1_prod", "VAR2": "var2_prod"}

for key, value in assertions.items():
    found = settings.from_env("production").get(key)
    assert found == getattr(settings.from_env("production"), key)
    assert (
github rochacbruno / dynaconf / example / yaml_example / settings_file / app.py View on Github external
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
settings.setenv()
print(settings.HOST)
print(settings.get("INEXISTENT"))  # None

print(settings.WORKS)
github 5783354 / awokado / awokado / db.py View on Github external
DATABASE_URL = database.db_url
DATABASE_PASSWORD = database.DATABASE_PASSWORD
DATABASE_HOST = database.DATABASE_HOST
DATABASE_USER = database.DATABASE_USER
DATABASE_PORT = database.DATABASE_PORT
DATABASE_DB = database.DATABASE_DB

clavis.configure(DATABASE_URL)

persistent_engine = sa.create_engine(
    DATABASE_URL,
    encoding="utf-8",
    echo=settings.get("DB_ECHO", False),
    poolclass=QueuePool,
    pool_size=settings.get("DB_CONN_POOL_SIZE", 10),
    max_overflow=settings.get("DB_CONN_MAX_OVERFLOW", 5),
)
github rochacbruno / dynaconf / example / envs / app.py View on Github external
print("WORKS:", settings.WORKS)


with settings.using_env("staging"):
    print("# 6 using {}: env values for context:".format(settings.current_env))
    assert settings.current_env == "STAGING"
    print("HOST::", settings.HOST)
    print("PORT:", settings.PORT)
    print("USERNAME:", settings.USERNAME)
    print("PASSWORD:", settings.PASSWORD)
    print("LEVELS:", settings.LEVELS)
    print("TEST_LOADERS:", settings.TEST_LOADERS)
    print("MONEY:", settings.MONEY)
    print("AGE:", settings.AGE)
    print("ENABLED:", settings.ENABLED)
    print("ENVIRONMENT:", settings.get("ENVIRONMENT"))
    print("WORKS:", settings.WORKS)

print("# 7 back to default {}: env:".format(settings.current_env))
assert settings.current_env == "DEVELOPMENT"
print("HOST::", settings.HOST)
print("PORT:", settings.PORT)
print("USERNAME:", settings.USERNAME)
print("PASSWORD:", settings.PASSWORD)
print("LEVELS:", settings.LEVELS)
print("TEST_LOADERS:", settings.TEST_LOADERS)
print("MONEY:", settings.MONEY)
print("AGE:", settings.AGE)
print("ENABLED:", settings.ENABLED)
print("ENVIRONMENT:", settings.get("ENVIRONMENT"))
print("WORKS:", settings.WORKS)
github 5783354 / awokado / awokado / settings.py View on Github external
(
        "Access-Control-Allow-Headers",
        "Content-Type, X-File-Size, X-File-Name, Authorization",
    ),
    ("Access-Control-Allow-Credentials", "true"),
    ("Access-Control-Allow-Methods", "POST, PATCH, GET, OPTIONS, DELETE"),
    ("Access-Control-Max-Age", "3600"),
]

AWOKADO_AUTH_BEARER_SECRET = settings.get(
    "AWOKADO_AUTH_BEARER_SECRET", "YourSecretTokenHere"
)
###############################################################################
# DB Settings
###############################################################################
DATABASE_PASSWORD = settings.get("DATABASE_PASSWORD", "postgres")
DATABASE_HOST = settings.get("DATABASE_HOST", "postgres")
DATABASE_USER = settings.get("DATABASE_USER", "postgres")
DATABASE_PORT = settings.get("DATABASE_PORT", 5432)
DATABASE_DB = settings.get("DATABASE_DB", "test")

###############################################################################
# AWS S3 Settings
###############################################################################
AWOKADO_AWS_S3_DEBUG_PROFILING_ACCESS_KEY = settings.get(
    "AWOKADO_AWS_S3_DEBUG_PROFILING_ACCESS_KEY", ""
)
AWOKADO_AWS_S3_DEBUG_PROFILING_SECRET_KEY = settings.get(
    "AWOKADO_AWS_S3_DEBUG_PROFILING_ACCESS_KEY", ""
)
AWOKADO_AWS_S3_DEBUG_PROFILING_BUCKET_NAME = settings.get(
    "AWOKADO_AWS_S3_DEBUG_PROFILING_ACCESS_KEY", ""
github rochacbruno / dynaconf / example / toml_example / app.py View on Github external
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
settings.setenv()
print(settings.HOST)
print(settings.get("INEXISTENT"))  # None

print(settings.WORKS)


assertions = {
    "HOST": "dev_server.com from toml",
    "PORT": 5000,
    "USERNAME": "admin",
    "PASSWORD": "Secret",
    "LEVELS": ["debug", "info", "warning"],
    "MONEY": 500.5,
    "AGE": 42,
    "ENABLED": True,
    "WORKS": "toml_example in dev env",
    "CUSTOM": "this is custom from [development]",
    "TEST_LOADERS": {"dev": "test_dev", "prod": "test_prod"},
github 5783354 / awokado / awokado / utils.py View on Github external
resp.content_type = "application/json"
    resp.append_header("Vary", "Accept")
    resp.status = exception.status

    # Setup CORS
    origin = req.headers.get("HTTP_ORIGIN")
    origin2 = req.headers.get("ORIGIN")
    origin = origin2 or origin
    headers = {}

    if settings.get("AWOKADO_DEBUG") or (
        origin and origin in settings.ORIGIN_HOSTS
    ):
        headers["Access-Control-Allow-Origin"] = origin

    headers_to_set = settings.get(
        "AWOKADO_ACCESS_CONTROL_HEADERS", DEFAULT_ACCESS_CONTROL_HEADERS
    )
    for k, v in headers_to_set:
        headers[k] = v

    resp.set_headers(headers)
github rochacbruno / dynaconf / example / issues / 166_renamed_global_env / app.py View on Github external
from dynaconf import settings

assert settings.ENVVAR_PREFIX_FOR_DYNACONF == "GREATAPP"
assert settings.GLOBAL_ENV_FOR_DYNACONF == "GREATAPP"
assert settings.INT == 1
assert settings.FLOAT == 42.2
assert settings.LIST == ["a", "b"]
assert settings.BOOL is False
assert settings.DICT.NAME == "dynaconf"

for key in ["INT", "FLOAT", "LIST", "BOOL", "DICT", "DICT.NAME", "NOWAY"]:
    print(settings.get(key, None))  # noqa