Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

envpy-0.1.0-py2.py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page