类型安全环境变量分析。

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如何将异步类的结果放入mainActivity EditText   java LDAP目录管理器服务提供,OutOfMemory   java Cassandra NoHostAvailableException,但仍存在活动节点   springboot应用程序的java启动线程   如果poll不一定返回第一项,那么java是ConcurrentLinkedQueue的好选择吗?   解析XML时JSON中出现java意外字符串   当'key'是两个整数时,如何输出Java HashMap键?   java为什么不显示在jsp页面中   java使用流式API转换映射列表中的值   JavaJPA+Spring:基于在持久化实体之前接收到的值,将外键列映射到ID   java如何使用selenium读取pdf文件   Canny之后的java对象提取   DSpace没有列出集合,java。lang.NumberFormatException:null   java我可以为数据库表主键设置一个最大值吗?   java如何定义Javadoc链接,可以通过单击   @java/spring中的SessionAttribute是否丢失数据?