How to use the environs.Env function in environs

To help you get started, we’ve selected a few environs 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 sloria / environs / tests / test_environs.py View on Github external
def test_env_isolation(set_env):
    set_env({"FOO": "foo"})
    env1 = environs.Env()

    @env1.parser_for("foo")
    def foo(value):
        return value

    env2 = environs.Env()

    # env1 has a parser for foo, but env2 does not
    assert env1.foo("FOO") == "foo"
    with pytest.raises(AttributeError):
        env2.foo("FOO")
github sloria / environs / tests / test_environs.py View on Github external
def env(self):
        return environs.Env(eager=False)
github Python3WebSpider / AdslProxy / adslproxy / settings.py View on Github external
# coding=utf-8
from environs import Env

env = Env()

# 拨号间隔,单位秒
DIAL_CYCLE = env.int('DIAL_CYCLE', 100)
# 拨号出错重试间隔
DIAL_ERROR_CYCLE = env.int('DIAL_ERROR_CYCLE', 5)
# 拨号命令
DIAL_BASH = env.str('DIAL_BASH', 'adsl-stop;adsl-start')
# 拨号网卡
DIAL_IFNAME = env.str('DIAL_IFNAME', 'ppp0')

# 客户端唯一标识
CLIENT_NAME = env.str('CLIENT_NAME', 'adsl1')

# Redis数据库IP
REDIS_HOST = env.str('REDIS_HOST', 'localhost')
# Redis数据库密码, 如无则填None
github sloria / environs / examples / simple_example.py View on Github external
from environs import Env


os.environ["GITHUB_USER"] = "sloria"
os.environ["API_KEY"] = "123abc"
os.environ["SHIP_DATE"] = "1984-06-25"
os.environ["ENABLE_LOGIN"] = "true"
os.environ["MAX_CONNECTIONS"] = "42"
os.environ["GITHUB_REPOS"] = "webargs,konch,ped"
os.environ["COORDINATES"] = "23.3,50.0"
os.environ["MYAPP_HOST"] = "lolcathost"
os.environ["MYAPP_PORT"] = "3000"


env = Env()
# reading an environment variable
gh_user = env("GITHUB_USER")  # => 'sloria'
# casting
api_key = env.str("API_KEY")  # => '123abc'
date = env.date("SHIP_DATE")  # => datetime.date(1984, 6, 25)
# providing a default value
enable_login = env.bool("ENABLE_LOGIN", False)  # => True
enable_feature_x = env.bool("ENABLE_FEATURE_X", False)  # => False
# parsing lists
gh_repos = env.list("GITHUB_REPOS")  # => ['webargs', 'konch', 'ped']
coords = env.list("COORDINATES", subcast=float)  # => [23.3, 50.0]

with env.prefixed("MYAPP_"):
    host = env("HOST", "localhost")
    port = env.int("PORT", 5000)
github cookiecutter-flask / cookiecutter-flask / {{cookiecutter.app_name}} / {{cookiecutter.app_name}} / settings.py View on Github external
# -*- coding: utf-8 -*-
"""Application configuration.

Most configuration is set via environment variables.

For local development, use a .env file to set
environment variables.
"""
from environs import Env

env = Env()
env.read_env()

ENV = env.str("FLASK_ENV", default="production")
DEBUG = ENV == "development"
SQLALCHEMY_DATABASE_URI = env.str("DATABASE_URL")
SECRET_KEY = env.str("SECRET_KEY")
SEND_FILE_MAX_AGE_DEFAULT = env.int("SEND_FILE_MAX_AGE_DEFAULT")
BCRYPT_LOG_ROUNDS = env.int("BCRYPT_LOG_ROUNDS", default=13)
DEBUG_TB_ENABLED = DEBUG
DEBUG_TB_INTERCEPT_REDIRECTS = False
CACHE_TYPE = "simple"  # Can be "memcached", "redis", etc.
SQLALCHEMY_TRACK_MODIFICATIONS = False
github sloria / environs / examples / validation_example.py View on Github external
import os

from environs import Env, EnvError
from marshmallow.validate import OneOf, Email, Length


os.environ["TTL"] = "-2"
os.environ["NODE_ENV"] = "invalid"
os.environ["EMAIL"] = "^_^"


env = Env()

# simple validator
try:
    env.int("TTL", validate=lambda n: n > 0)
except EnvError as err:
    print(err)

# marshmallow validator
try:
    env.str(
        "NODE_ENV", validate=OneOf(["production", "development"], error="NODE_ENV must be one of: {choices}")
    )
except EnvError as err:
    print(err)
github FoxDev / pste / pste / settings.py View on Github external
#  along with pste.  If not, see .

import subprocess

from environs import Env

PLAINTEXT_TYPES = [
    'txt', 'php', 'rb', 'sh', 'py',
    'conf', 'c', 'cpp', 'java', 'rs',
    'html', 'htm', 'js', 'xml', 'sql',
    'lua', 'cs', 'pl', 'md', 'ini',
    'shtml', 'yaml', 'cfg', 'go', 'fish',
    'yml', 'bash'
]

env = Env()
env.read_env()

APP_NAME = env.str('APP_NAME', 'pste')
APP_VERSION = subprocess.check_output(['git', 'describe', '--abbrev=0']).decode('UTF-8').strip()
SECRET_KEY = env.str('SECRET_KEY')
SQLALCHEMY_DATABASE_URI = env.str('DATABASE_URI')
SQLALCHEMY_TRACK_MODIFICATIONS = False

ENABLE_REGISTRATION = env.bool('ENABLE_REGISTRATION', False)

with env.prefixed('MAIL_'):
    MAIL_SERVER = env.str('SERVER')
    MAIL_PORT = env.int('PORT')
    MAIL_USE_TLS = env.bool('USE_TLS')
    MAIL_USERNAME = env.str('USERNAME')
    MAIL_PASSWORD = env.str('PASSWORD')
github sloria / environs / examples / django_example.py View on Github external
"""Example of using environs within a Django settings module.

Requires dj-database-url: pip install dj-database-url

To run this example:

    DEBUG=true SECRET_KEY=myprecious python examples/django_example.py
"""
import os
from pprint import pprint

import environs

env = environs.Env()
env.read_env()

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

# Override in .env for local development
DEBUG = TEMPLATE_DEBUG = env.bool("DEBUG", default=False)

# NOTE: Error will be raised if SECRET_KEY is unset
SECRET_KEY = env.str("SECRET_KEY")

DATABASES = {
    "default": env.dj_db_url(
        "DATABASE_URL", default="sqlite:///" + os.path.join(BASE_DIR, "db.sqlite3"), ssl_require=not DEBUG
    )
}
github pmariglia / showdown / run.py View on Github external
def parse_configs():
    env = Env()
    env.read_env()

    config.battle_bot_module = env("BATTLE_BOT", 'safest')
    config.log_to_file = env.bool("LOG_TO_FILE", config.log_to_file)
    config.save_replay = env.bool("SAVE_REPLAY", config.save_replay)
    config.use_relative_weights = env.bool("USE_RELATIVE_WEIGHTS", config.use_relative_weights)
    config.gambit_exe_path = env("GAMBIT_PATH", config.gambit_exe_path)
    config.search_depth = int(env("MAX_SEARCH_DEPTH", config.search_depth))
    config.greeting_message = env("GREETING_MESSAGE", config.greeting_message)
    config.battle_ending_message = env("BATTLE_OVER_MESSAGE", config.battle_ending_message)
    config.websocket_uri = env("WEBSOCKET_URI", "sim.smogon.com:8000")
    config.username = env("PS_USERNAME")
    config.password = env("PS_PASSWORD", "")
    config.bot_mode = env("BOT_MODE")
    config.team_name = env("TEAM_NAME", None)
    config.pokemon_mode = env("POKEMON_MODE", constants.DEFAULT_MODE)