Skip to main content

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.

**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.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

env_excavator-1.1.0-py2.py3-none-any.whl (4.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file env-excavator-1.1.0.tar.gz.

File metadata

File hashes

Hashes for env-excavator-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a367174f722c6a415a35872ad9ca51a5431043a11aee2e22b1fc23f3027e0d83
MD5 c29e09ba7020bba9b411b29a1fba0b6a
BLAKE2b-256 59944d3f65706d7dc77518673f95b0150bc52207b0f41589c711123ae4fcdc93

See more details on using hashes here.

File details

Details for the file env_excavator-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for env_excavator-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1b91c2474dc282d59b0290276c0e28fa6aa90fc7b51bff5597ae81e00aa97d32
MD5 af0bf985c50b328b6461040427c60078
BLAKE2b-256 60d04136683e90098c04e243d118333e4e64207d993d90ec95d6886b95891b72

See more details on using hashes here.

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