文档:https://github.com/sloria/environs
安装
pip install environs
代码示例
# -*- coding: utf-8 -*- from environs import Env env = Env() # read .env file, if it exists env.read_env() env.str('FLASK_APP') # app.py env.bool('FLASK_DEBUG') # True
.env文件
# .env FLASK_APP = app.py FLASK_ENV = development FLASK_DEBUG = 1
支持的类型
env.str env.bool env.int env.float env.decimal env.list (accepts optional subcast keyword argument) env.dict (accepts optional subcast keyword argument) env.json env.datetime env.date env.timedelta (assumes value is an integer in seconds) env.url env.uuid env.log_level env.path (casts to a pathlib.Path)