Configuration via environment
Project description
viaenv - Configuration via Environment for Python
viaenv
uses variable annotation
to populate values from environment variables.
Example
from datetime import timedelta
from viaenv import populate_from_env
class config:
port: int = 8080
log_file: str = '/var/log/server.log'
timeout: timedelta = timedelta(milliseconds=100)
populate_from_env(
config, prefix='SRV',
# If you don't pass env, populate_from_env will use os.environ
env={'SRV_PORT': '9000', 'SRV_TIMEOUT': '300ms'})
print(config.port) # 9000
print(cfg.timeout == timedelta(milliseconds=300) # True
Supported Types
bool
:y
,yes
,t
,true
,on
,1
->True
,n
,no
,f
,false
,off
,0
->False
date
:2019-05-18
datetime
:2019-05-18T13:43:12
dict
:{"x": 1, "y": 2}
(JSON format)float
:1.3
,1e7
int
:12
,0x12
,0o12
,0b12
list
:[1, 2, 3]
(JSON format)str
: Anything goestime
:13:43:12
timedelta
:10us
,20ms
,30s
,17m
,2h
,7d
,1h20m
You can add your types by calling register_type_parser(typ, parser)
where
typ
is a type (e.g. float
) and parser
is a one argument function that
will get the value as a string.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
viaenv-0.2.0.tar.gz
(4.7 kB
view details)
File details
Details for the file viaenv-0.2.0.tar.gz
.
File metadata
- Download URL: viaenv-0.2.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 314e0fc0ea0d410f41e0e02a2e3e411b1a0c20dd605591c5e7dbd477a868346b |
|
MD5 | 3c478e07f22bbeae4ab2d9130396c00a |
|
BLAKE2b-256 | 54500bbbf9c0130a672356020a3e283da83117ff2c6dc07ce374c3e639439add |