Python library for loading config from environment variables.
Project description
Overview
Python library for loading config from environment variables. Suitable for implementing the config requirements of a 12-factor app: https://12factor.net/config
Getting Started
Installation
To install use pip:
$> pip install envpy
- Requirements before installation:
python3
pip3
Usage
"""Basic usage script for envpy"""
import envpy
CONFIG = envpy.get_config({
# This will raise an error if it cannot be found in the environment
# because no default has been set.
'SECRET_KEY': envpy.Schema(value_type=str),
# This has a default value and as such won't raise an error if it cannot
# be found in the environment. However, the value type is set to 'int'
# which means that an error will be raised if a value is present in the
# environment but cannot be parsed as an integer.
'NUM_WORKERS': envpy.Schema(value_type=int, default=4),
})
if __name__ == '__main__':
print('Secret Key:', config['SECRET_KEY'])
print('Number of workers:', config['NUM_WORKERS'])
Value Types
str
No parsing is applied and the string is returned directly from the environment.
int
The value will be parsed as an integer. Must match: ^[0-9]+$.
float
The value will be parsed as a float. Must match: ^[0-9]+.[0-9]+$.
bool
- The value will be parsed as a boolean. Must be one of the following:
“1” (True)
“0” (False)
“true” (True, case insensitive)
“false” (False, case insensitive)
Development
Installation
This project makes use of virtual environments to provision your development environment. Once the following requirements have been met further installation is managed automatically by the Makefile.
- Requirements before provisioning:
python3
pip3
virtualenv
make
Usage
The following commands will create a virtual environment (if not already present) for the application and will install the necessary dependencies there before running the requested command.
Run the package:
$> make
Run the unit tests:
$> make test
Run the linter:
$> make lint
Rebuild your virtual environment:
$> make rebuild_venv
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for envpy-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56b5a1e7aa7352a89becded843b126cf11173cdbb7f09ab5bff228f5a18f0089 |
|
MD5 | 683ec7db7160c040f3281850f44c139b |
|
BLAKE2b-256 | a0c0d519dd6d82309b344d82cfae4b5ee2cac961d0372d149168a432c41ee128 |