Parsing and validation of environment variables
Project description
Simple means of parsing and validating environment variables. Heavily inspired by the earlier versions of webargs, which also explains the name to some extend.
Installing
$ pip install envargs
Using
from envargs import Var, parse_env
required_vars = {
'A_INT': Var(
use=int,
validate=lambda x: x >= 0,
),
'A_LIST': Var(
use=lambda x: x.split(','),
validate=(
lambda x: len(x) == 2,
lambda x: x[0] == 'first element',
),
),
'A_STR': Var(
use=str,
load_from='SOME_OTHER_NAME',
validate=bool,
),
}
parsed = parse_env(required_vars)
Say you want to configure your Flask app using this:
app.config.from_mapping(parsed)
Why reinvent the wheel again?
To be fair there are many good packages out there to parse environment variables, quite a few of them in python too. So this package can easily be seen as redundant. However, with separation of parsing and validation into two separate functions, you gain more power to control what is actually accepted, not to mention that it makes it possible to inline a few more things, as you can most often get away with using builtin functions for most parsing and validation, and when that is not enough, lambdas or partials can do the rest.
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
Built Distribution
File details
Details for the file envargs-0.2.1.tar.gz
.
File metadata
- Download URL: envargs-0.2.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86feca1c12b86b66143ad9f5e7098c53ebecb99b72a7b457a4e1a4c5c947672a |
|
MD5 | a4b9d2a6cfe89365b79f42930c422648 |
|
BLAKE2b-256 | a3aa13e89c4518c39e2fe18027d236aa22a297fb7956b2ecdc8a1314f710e9a3 |
File details
Details for the file envargs-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: envargs-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5579d8307adcea29e14aa0b7c0d1402f8a0b102b04bd8aa593a571f53ea672ea |
|
MD5 | ad6429982c9e3d5b835e226b1c8f96a7 |
|
BLAKE2b-256 | 1e6ff4ad204152e995dc9e510ea641d48e5888a755a71063f5b33d8aeb50dc62 |