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 ( found == value), "expected: {key}: [{value}] found: [{found}]".format( **locals()) assertions = { "HOST": "prod_server.com", "PORT": 5000, "ENVIRONMENT": "this is production", } for key, value in assertions.items(): found = settings.from_env("production").get(key) assert found == getattr(settings.from_env("production"), key) assert ( found == value), "expected: {key}: [{value}] found: [{found}]".format( **locals())
from __future__ import annotations from dynaconf import settings print(f"Current env: {settings.current_env}") print(f"Dev is: {settings.THISIS}") print(f"Production is: {settings.from_env('production').THISIS}") assert settings.THISIS == "development" assert settings.from_env("production").THISIS == "production"
from dynaconf import settings from dynaconf.loaders.vault_loader import list_envs print(settings.FOO) # noqa # >>> 'foo_is_default' with settings.using_env("dev"): assert settings.SECRET == "vault_works_in_dev", settings.SECRET assert settings.FOO == "foo_is_default", settings.FOO assert settings.SECRET == "vault_works_in_default" available_envs = list_envs(settings, "dynaconf/") assert set(available_envs) == set(["default", "dev", "prod"]), available_envs all_secrets = [] for env in available_envs: env_settings = settings.from_env(env) assert env_settings.from_env(env).SECRET == "vault_works_in_{0}".format( env) assert env_settings.FOO == "foo_is_default" all_secrets.append(env_settings.SECRET) print(available_envs) print(all_secrets)
def __init__(self): jwt_env = settings.from_env('jwt') self.serial = serial(secret_key=jwt_env['secret-key'], salt=jwt_env['salt'], expires_in=jwt_env['expires'])
def __init__(self): jwt_env = settings.from_env('jwt') with open(jwt_env['private_key']) as f: self.private_key = f.read() with open(jwt_env['public_key']) as f: self.public_key = f.read()
import time import logging import brlapi import errno import atexit from flask import Flask, request, Response from jsonrpcserver import method, dispatch from flask_cors import CORS from dynaconf import settings logging.basicConfig() logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) conf = settings.from_env('braille-python-server').to_dict() HOSTNAME = conf['HOSTNAME'] PORT = conf['PORT'] _Display = None # PACmate 40 DISPLAY_SIZE = 40 app = Flask(__name__) CORS(app, supports_credentials=True) @method def show(text): if text.strip() == '': if _Display: