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. If not present in the environment and no default is specified, an
empty string is returned.
**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=None)``::
Pulls an environment variable out of the environment returning it as a
boolean. The strings ``'True'`` and ``'true'`` are the default *truthy*
values. If not present in the environment and no default is specified,
``None`` is returned.
**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. If not present
and no default specified, an empty list is returned.
**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``)
* ``excavator.env_int(name, separator=',', required=False, default='')``::
Pulls an environment variable out of the environment and casts it to an integer.
If the name is not present in the environment and no default is specified
then a ``ValueError`` will be raised. Similarly, if the environment value is
not castable to an integer, a ``ValueError`` will be raised.
**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_timestamp(name, required=False, default='')``::
Pulls an environment variable out of the environment and parses it to a
``datetime.datetime`` object. The environment variable is expected to be a
timestamp in the form of a float.
If the name is not present in the environment and no default is specified
then a ``ValueError`` will be raised.
**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_iso8601(name, required=False, default='')``::
Pulls an environment variable out of the environment and parses it to a
``datetime.datetime`` object. The environment variable is expected to be an
iso8601 formatted string.
If the name is not present in the environment and no default is specified
then a ``ValueError`` will be raised.
**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``)
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. If not present in the environment and no default is specified, an
empty string is returned.
**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=None)``::
Pulls an environment variable out of the environment returning it as a
boolean. The strings ``'True'`` and ``'true'`` are the default *truthy*
values. If not present in the environment and no default is specified,
``None`` is returned.
**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. If not present
and no default specified, an empty list is returned.
**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``)
* ``excavator.env_int(name, separator=',', required=False, default='')``::
Pulls an environment variable out of the environment and casts it to an integer.
If the name is not present in the environment and no default is specified
then a ``ValueError`` will be raised. Similarly, if the environment value is
not castable to an integer, a ``ValueError`` will be raised.
**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_timestamp(name, required=False, default='')``::
Pulls an environment variable out of the environment and parses it to a
``datetime.datetime`` object. The environment variable is expected to be a
timestamp in the form of a float.
If the name is not present in the environment and no default is specified
then a ``ValueError`` will be raised.
**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_iso8601(name, required=False, default='')``::
Pulls an environment variable out of the environment and parses it to a
``datetime.datetime`` object. The environment variable is expected to be an
iso8601 formatted string.
If the name is not present in the environment and no default is specified
then a ``ValueError`` will be raised.
**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``)
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.3.0.tar.gz
(5.0 kB
view details)
Built Distribution
File details
Details for the file env-excavator-1.3.0.tar.gz
.
File metadata
- Download URL: env-excavator-1.3.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94156817af1f381d33e47d500c7eca4c377c7e804336f5b8b1f05130e873ec5f |
|
MD5 | 6c5a0444642e1ffe5c366b9c70efd65f |
|
BLAKE2b-256 | b799fc1d4a2a396e824766d17229d230d687e094471c7bc22a5e7666818c69da |
File details
Details for the file env_excavator-1.3.0-py2.py3-none-any.whl
.
File metadata
- Download URL: env_excavator-1.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f518f4fd33ad2830bf55ab091998e8a16ebd3da95f558d345c38b2740e1e57b |
|
MD5 | a0b26c6c979d4237753875d7aaa38aa8 |
|
BLAKE2b-256 | 1caca4052c51721dcc5092e06f06444abf0a749dd588e82c25c5549226e7ebf1 |