Skip to main content

Envargs

https://travis-ci.org/cknv/envargs.svg?branch=master https://coveralls.io/repos/github/cknv/envargs/badge.svg?branch=master

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.

Metadata

Release files for envargs 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for envargs 0.2.1
File Size Uploaded
envargs-0.2.1.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for envargs 0.2.1
File Interpreter ABI Platform
envargs-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / envargs-0.2.1.tar.gz

Download URL envargs-0.2.1.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
86feca1c12b86b66143ad9f5e7098c53ebecb99b72a7b457a4e1a4c5c947672a
BLAKE2b-256 checksum
How to use checksums
a3aa13e89c4518c39e2fe18027d236aa22a297fb7956b2ecdc8a1314f710e9a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / envargs-0.2.1-py3-none-any.whl

Download URL envargs-0.2.1-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5579d8307adcea29e14aa0b7c0d1402f8a0b102b04bd8aa593a571f53ea672ea
BLAKE2b-256 checksum
How to use checksums
1e6ff4ad204152e995dc9e510ea641d48e5888a755a71063f5b33d8aeb50dc62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page