Metadata-Version: 1.1
Name: env-utils
Version: 1.1.0
Summary: Utility functions to make it easier to work with os.environ
Home-page: https://github.com/yunojuno/python-env-utils
Author: Hugo Rodger-Brown
Author-email: hugo@yunojuno.com
License: Copyright (c) 2015, Hugo Rodger-Brown
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Description: .. image:: https://travis-ci.org/yunojuno/python-env-utils.svg?branch=master
            :target: https://travis-ci.org/yunojuno/python-env-utils
        
        .. image:: https://badge.fury.io/py/env_utils.svg
            :target: https://badge.fury.io/py/env_utils
        
        .. image:: https://codecov.io/gh/yunojuno/python-env-utils/branch/master/graph/badge.svg
            :target: https://codecov.io/gh/yunojuno/python-env-utils
        
        env utils
        =========
        
        This library extends the standard library's ``getenv`` function, allowing
        you to coerce the return value into a type.
        
        And that's it.
        
        It's been released as a library because every project we have includes the
        same requirements - read in environment variables, coerce them into the
        correct type.
        
        The problem is that environment variables are always stored as strings, but
        Python will evaluate any string (even "") as True if cast to a boolean. This
        is almost never the desired behaviour. If you set an environment variable to
        "", "0" or "False", you want it to be False.
        
        .. code:: python
        
            >>> os.environ['foo'] = "0"
            >>> val = os.getenv('foo')
            >>> val
            "0"
            >>> bool(val)
            True
        
        ``env_utils.get_env`` will coerce the value into the type you require. The package contains basic helper functions that coerce booleans, integers, decimals, floats, dates, lists and dictionaries.
        
        .. code:: python
        
            # FOO=0
            >>> env_utils.get_env('FOO')
            "0"
            >>> env_utils.get_bool('FOO')
            False
            >>> env_utils.get_int('FOO')
            0
        
            # FOO=foo,bar
            >>> env_utils.get_list('FOO', separator=',')
            ['foo', 'bar']
        
            # FOO='{"foo": true}'
            >>> env_utils.get_dict('FOO')
            {'foo': True}
        
            # FOO=2016-11-23
            >>> env_utils.get_date('FOO')
            datetime.date(2016, 11, 23)
        
        You can supply any function you like to coerce the value, e.g.:
        
        .. code:: python
        
            >>> import os
            >>> os.getenv('FOO_NAME')
            'bob'
            >>> class Foo(object):
            ...     def __init__(self, name):
            ...         self.name = name
            >>> coerce = lambda x: Foo(x)
            >>> import env_utils
            >>> foo = env_utils.get_env('FOO_NAME', coerce=coerce)
            >>> foo.name
            >>> 'bob'
        
        
        Installation
        ------------
        
        The library is available at pypi as 'env_utils', and can installed using pip::
        
            $ pip install env_utils
        
        Tests
        -----
        
        The tests can be run using ``tox``:
        
        .. code:: shell
        
            $ tox
        
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
