类型安全环境变量分析。

myenv的Python项目详细描述


MyENV: Environment Variable Parsing using Type annotations

myenv使用类型注释解析您的环境变量。 这允许您将应用程序/服务配置为 12factor.net/config,保存时 你的代码类型安全。

项目/回购:

MIT LicenseSupported Python VersionsPyCalVer v201902.0007PyPI VersionPyPI Downloads

代码质量/ci:

Build StatusType Checked with mypyCode CoverageCode Style: sjfmt

Namerolesinceuntil
Manuel Barkhau (mbarkhau@gmail.com)author/maintainer2018-09-

Environment Variables and Configuration

In order of priority, configuration is parsed from

  1. Environment variables
  2. Configuration files
  3. Defaults defined in source code

Declaration

The ^{} module provides a convenient way to do this parsing. As far as your application code is concerned, it is enough to declare a subclass of ^{}. Instances of this subclass are populated from config files and the environment.

^{pr 1}$

For each annoatated member of ^{} declare the 1. name, 2. type and 3. an optional default variable. Members without a default must be set by an environment variable or configuration file, otherwise a ^{} will be raised.

Parsing

To use the above configuration class, simply instanciate it.

^{pr 2}$

In case you're worried about the instantiation of ^{}, it will return a singleton instance, so the ^{} and configuration files are parsed only once.

Config Files

When parsing configs, the following paths are parsed if they exist. By default the configs are loaded from ^{}, but you can override the location of configuration files by setting the environment variable ^{}.

  • ^{}
  • ^{}

Any variables defined in these files will be set, unless it was already set in the environ or a previous config file.

This approach allows you to satisfy typical use cases in which a service is hosted:

  1. Development Machine
  2. Stage/Production Environment

You can put use case specifc configuration files in your project source tree, such as:

  • ^{}
  • ^{}
  • ^{}

To parse the appropriate config file, all you have to do is set a single environment variable ^{}. If ^{} is not set, it will fall back to ^{}.

The ^{} config files are flat text files, with one KEY=value mapping per line. The only lines which are parsed, are lines which begin with an all upper case token, followed by an ^{} character:

^{pr 3}$

For sensitive configuration parameters, such as passwords and authentication tokens, you may prefer to write config files outside of your source tree, or to provide them always and only via environment variables.

Changelog for https://gitlab.com/mbarkhau/myenv

V201902.0007

  • 打包更新
  • 更好的测试和mypy覆盖率

V201812.0005-β

V201809.0001-β

  • 初始版本

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何创建比较器   java将所有接口读入列表   java Android Studio在Webview中隐藏特定URL的操作栏   java如何在春季从云存储中生成URL文件而无需持续时间   icalendar如何使用Java以日历格式发送ics电子邮件附件?   如果textfield包含数字,则在运行时进行java检查   java util日志属性中何时需要“.level”?   java在一个字符串中显示json   跨平台日志系统的java Log4j替代方案   coldfusion在Lucee上安装Cassandra Java驱动程序   SpringWebMVC4Java配置不工作   windows使用java程序添加环境变量,并且能够在我从计算机打开“环境”选项卡时看到   java未设置变量和方法   mysql在java中通过查询更改数据库的现有行   java如何使用递归方法查找所有可能的数字   java如何使非原语类成员不可变   java将信息从输入按钮传递到标签