Python library for loading config from environment variables.
Project description
envpy
=====
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:
.. code-block:: guess
$> pip install envpy
Requirements before installation:
- python3
- pip3
Usage
`````
.. code-block:: python
"""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:
.. code-block:: guess
$> make
Run the unit tests:
.. code-block:: guess
$> make test
Run the linter:
.. code-block:: guess
$> make lint
Rebuild your virtual environment:
.. code-block:: guess
$> make rebuild_venv
=====
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:
.. code-block:: guess
$> pip install envpy
Requirements before installation:
- python3
- pip3
Usage
`````
.. code-block:: python
"""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:
.. code-block:: guess
$> make
Run the unit tests:
.. code-block:: guess
$> make test
Run the linter:
.. code-block:: guess
$> make lint
Rebuild your virtual environment:
.. code-block:: guess
$> 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
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for envpy-0.0.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 364a4e3c02ad153eda76564c7fc3a7b4441f81340d7ae8f0310b657e9fc6279c |
|
MD5 | 9b3cc7614b36d8a749f43b16d222f387 |
|
BLAKE2b-256 | a9f8775f6151468897473606d71561be5755e41435bb9d92cf5febd85178010f |