Tools for exconverting environment variables to native python objects
Project description
=============================
env-excavator
=============================
.. image:: https://badge.fury.io/py/env-excavator.png
:target: https://badge.fury.io/py/env-excavator
.. image:: https://travis-ci.org/simpleenergy/env-excavator.png?branch=master
:target: https://travis-ci.org/simpleenergy/env-excavator
Tools for exconverting environment variables to native python objects
Quickstart
----------
Install env-excavator::
pip install env-excavator
Example use it in a project::
>>> import os
>>> import excavator
>>> os.environ['FROM_EMAIL'] = 'admin@example.com'
>>> excavator.env_string('FROM_EMAIL')
... 'admin@example.com'
>>> os.environ['DEBUG'] = 'True'
>>> DEBUG = excavator.env_bool('DEBUG')
... True
>>> os.environ['ALLOWED_HOSTS'] = '.example.com,.example.net'
>>> excavator.env_list('ALLOWED_HOSTS')
['.example.com', '.example.net']
API
---
* ``excavator.env_string(name, required=False, default='')``::
Pulls an environment variable out of the environment returning it as a string.
**name** - the name of the environment variable be pulled
**required** - Whether the environment variable is required. If ``True`` and
the variable is not present, a ``KeyError`` is raised.
**default** - The value to return if the environment variable is not present.
(providing a default alongside setting ``required=True`` will raise a
``ValueError``)
* ``excavator.env_bool(name, truthy_values=('True', 'true'), required=False, default='')``::
Pulls an environment variable out of the environment returning it as a
boolean. The strings ``'True'`` and ``'true'`` are the default *truthy*
values.
**name** - the name of the environment variable be pulled
**truthy_values** - An iterable of values that should be considered truthy.
**required** - Whether the environment variable is required. If ``True`` and
the variable is not present, a ``KeyError`` is raised.
**default** - The value to return if the environment variable is not present.
(providing a default alongside setting ``required=True`` will raise a
``ValueError``)
* ``excavator.env_list(name, separator=',', required=False, default='')``::
Pulls an environment variable out of the environment, splitting it on a
separator, and returning it as a list. Extra whitespace on the list values
is stripped. List values that evaluate as falsy are removed.
**name** - the name of the environment variable be pulled
**separator** - The separator that the string should be split on.
**required** - Whether the environment variable is required. If ``True`` and
the variable is not present, a ``KeyError`` is raised.
**default** - The value to return if the environment variable is not present.
(providing a default alongside setting ``required=True`` will raise a
``ValueError``)
env-excavator
=============================
.. image:: https://badge.fury.io/py/env-excavator.png
:target: https://badge.fury.io/py/env-excavator
.. image:: https://travis-ci.org/simpleenergy/env-excavator.png?branch=master
:target: https://travis-ci.org/simpleenergy/env-excavator
Tools for exconverting environment variables to native python objects
Quickstart
----------
Install env-excavator::
pip install env-excavator
Example use it in a project::
>>> import os
>>> import excavator
>>> os.environ['FROM_EMAIL'] = 'admin@example.com'
>>> excavator.env_string('FROM_EMAIL')
... 'admin@example.com'
>>> os.environ['DEBUG'] = 'True'
>>> DEBUG = excavator.env_bool('DEBUG')
... True
>>> os.environ['ALLOWED_HOSTS'] = '.example.com,.example.net'
>>> excavator.env_list('ALLOWED_HOSTS')
['.example.com', '.example.net']
API
---
* ``excavator.env_string(name, required=False, default='')``::
Pulls an environment variable out of the environment returning it as a string.
**name** - the name of the environment variable be pulled
**required** - Whether the environment variable is required. If ``True`` and
the variable is not present, a ``KeyError`` is raised.
**default** - The value to return if the environment variable is not present.
(providing a default alongside setting ``required=True`` will raise a
``ValueError``)
* ``excavator.env_bool(name, truthy_values=('True', 'true'), required=False, default='')``::
Pulls an environment variable out of the environment returning it as a
boolean. The strings ``'True'`` and ``'true'`` are the default *truthy*
values.
**name** - the name of the environment variable be pulled
**truthy_values** - An iterable of values that should be considered truthy.
**required** - Whether the environment variable is required. If ``True`` and
the variable is not present, a ``KeyError`` is raised.
**default** - The value to return if the environment variable is not present.
(providing a default alongside setting ``required=True`` will raise a
``ValueError``)
* ``excavator.env_list(name, separator=',', required=False, default='')``::
Pulls an environment variable out of the environment, splitting it on a
separator, and returning it as a list. Extra whitespace on the list values
is stripped. List values that evaluate as falsy are removed.
**name** - the name of the environment variable be pulled
**separator** - The separator that the string should be split on.
**required** - Whether the environment variable is required. If ``True`` and
the variable is not present, a ``KeyError`` is raised.
**default** - The value to return if the environment variable is not present.
(providing a default alongside setting ``required=True`` will raise a
``ValueError``)
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
env-excavator-1.2.0.tar.gz
(4.2 kB
view details)
Built Distribution
File details
Details for the file env-excavator-1.2.0.tar.gz
.
File metadata
- Download URL: env-excavator-1.2.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f85c102f9963be349714b94fb692b60bcd5d690b45d71366ffc9ecba2098dd3c |
|
MD5 | 63cf9b45e16d48580e80d402c8d748c0 |
|
BLAKE2b-256 | 45a042563965636ef0a8a55db3651a0e2ae572076329ff9092f2574cfcd1f392 |
File details
Details for the file env_excavator-1.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: env_excavator-1.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2055111bea06ca11810ca7ed9cc50e93580c82a359bb82fe302a1f2cb7453d20 |
|
MD5 | 69ef98ef73e83d521c098abcec21a285 |
|
BLAKE2b-256 | 9082a0dddee46c40f9f1b7f48252301643ff7df3573af476c1fe60190cbea3a0 |