ezenv


Nameezenv JSON
Version 0.92 PyPI version JSON
download
home_pagehttps://github.com/mixmastamyk/env
SummaryA more convenient interface to environment variables.
upload_time2021-01-04 05:39:58
maintainer
docs_urlNone
authorMike Miller
requires_python
licenseLGPL
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
EZ-Environment
================

*"For easy access, baby!  …That's right.'"—Eazy-E*

Have you ever thought handling environment variables in Python should be easier?
It is now.


TL;DR:

.. code:: python

    >>> import env

    >>> env.SERVER_PORT.int
    8080

*"BAM!" —Emeril Lagasse*

The E.Z.E.nvironment module also has its own
`theme song <https://youtu.be/Igxl7YtS1vQ?t=1m08s>`_:

    *"We want Eazy!"*

    | *EAZY!*
    | *Everybody come on!*
    | *EAZY!*
    | *Who yall came to see?*
    | *EAZY!*
    | *A little louder come on!*
    | *EAZY!*
    | *Get those hands in the air!*
    | *EAZY!*
    | *Come on, come on say it!*
    | *EAZY!*
    | *A little louder come on!*
    | *EAZY!*
    | *Come on make some noise!*
    |
    | *A miracle of modern creation…*
    | *EZ E's on the set, hyped up with the bass*
    | *And a little bit of what ya love*
    | *From a brother who's smooth like a criminal*
    | *I mean subliminal…*


Background
---------------

It's always been a tad clumsy to access environment variables and combine them
with other strings in Python—\
compared to shell languages at least.
For example, look how easy it is in (ba)sh:

.. code:: shell

    ⏵ echo "Libraries: $PWD/lib"
    Libraries: /usr/local/lib

Unfortunately over in Python-land,
required, escaped quotes and brackets
serve mostly to complicate and add to visual clutter,
reducing speed of comprehension.

.. code:: python

    >>> from os import environ
    >>> from os.path import join

    >>> join(environ['PWD'], 'lib')
    '/usr/local/lib'

Even the new-fangled string interpolation doesn't help as much as might be
expected:

.. code:: python

    >>> print(f'Libraries: {environ["PWD"]}/lib')
    Libraries: /usr/local/lib


With that in mind, allow me to introduce the ``env`` module.
With it I've tried to whittle complexity down,
primarily through direct attribute access:

.. code:: python

    >>> import env

    >>> print('Term:', env.TERM)
    Term: xterm-256color

    >>> print(f'Libraries: {env.PWD}/lib')
    Libraries: /usr/local/lib

But wait, there's more!


Install
---------------

.. code:: shell

    ⏵ pip3 install --user ezenv  # env was taken :-/

 ☛ LGPL licensed. ☚


Environment and options
------------------------

On import the module loads the environment into its namespace,
thereby working like a dictionary with convenient attribute access.

So, no additional mapping instance has to be created or imported,
unless you'd like to configure the interface further.
The following options are available to customize:

.. code:: python

    >>> from env import Environment

    >>> env = Environment(
            environ=os.environ,
            sensitive=True|False,  # case: platform default
            writable=False,
            pathsep=os.pathsep,
        )

Param: environ
~~~~~~~~~~~~~~

A mapping of your own choosing may optionally be passed in as the first argument,
for testing and/or other purposes.
I've recently learned that
`os.environb <https://docs.python.org/3/library/os.html#os.environb>`_
(bytes interface) is a thing that could be passed,
for example.


.. ~ Noneify
.. ~ ~~~~~~~~~~~~

.. ~ Enabled by default,
.. ~ this one signals non-existent variables by returning None.
.. ~ It allows one to easily test for a variable and not have to worry about
.. ~ catching exceptions.
.. ~ If the variable is not set,
.. ~ None will be returned instead:

.. ~ .. code:: python

    .. ~ >>> if env.COLORTERM:   # is not None or ''
            .. ~ pass


.. ~ **Default Values**

.. ~ The one drawback to returning ``None`` is that there is no ``.get()`` method
.. ~ to return a default when the variable isn't found.
.. ~ That's easily rectified like so:

.. ~ .. code:: python

    .. ~ >>> env.FOO or 'bar'
    .. ~ 'bar'


.. ~ Blankify
.. ~ ~~~~~~~~~~~~

.. ~ Off by default,
.. ~ this option mimics the behavior of most command-line shells.
.. ~ Namely if the variable isn't found,
.. ~ it doesn't complain and returns an empty string instead.
.. ~ This can make some cases simpler,
.. ~ as fewer checks for errors are needed when checking contents::

    .. ~ if env.LANG.endswith('UTF-8'):
        .. ~ pass

.. ~ instead of the Noneify version::

    .. ~ if env.LANG and env.LANG.endswith('UTF-8'):
        .. ~ pass

.. ~ However,
.. ~ it may be a bug-magnet in the case the variable is misspelled,
.. ~ It is here if you need it for compatibility.
.. ~ Blankify takes precedence over Noneify if enabled.


Param: writable
~~~~~~~~~~~~~~~

By default the Environment object/module does not allow modification since
writing is rarely needed.
This default helps to remind us of that fact,
though the object can be easily be changed to writable if need be by enabling
this option.

Param: sensitivity 😢
~~~~~~~~~~~~~~~~~~~~~~

Variables are case-sensitive by default on Unix,
*insensitive* under Windows.

While case sensitivity can be disabled to use variable names in mixed or
lower-case,
be aware that variables and dictionary methods are in the same namespace,
which could potentially be problematic if they are not divided by case.
For this reason, using variable names such as "keys" and "items"
are not a good idea while in insensitive mode.
*shrug*

Workaround: use "get item" / dictionary-style syntax if needed:

.. code:: python

    env['keys']  # :-/

.. ~ varname = 'COLORTERM'
.. ~ env[varname]


Entry Objects
----------------

While using ``env`` at the interactive prompt,
you may be surprised that a variable value is not a simple string but rather
an extended string-like object called an "Entry."
This is most evident at the prompt since it prints a "representation"
form by default:

.. code:: python

    >>> env.PWD                         # a.k.a. repr()
    Entry('PWD', '/usr/local')

The reason behind this custom object is so that the variables can offer
additional functionality,
such as parsing or conversion of the value to another type,
while not crashing on a non-existent attribute access.

No matter however,
as we've seen in the previous sections,
just about any operation renders the string value as normal.
Attributes ``.name`` and ``.value`` are also available for belt &
suspenders types:

.. code:: python

    >>> print(env.PWD)
    /usr/local

    >>> env.PWD.name, env.PWD.value, str(env.PWD)
    ('PWD', '/tmp', '/tmp')

Remember the ``env`` object/module is also a standard dictionary,
while entry values are also strings,
so full Python functionality is available:

.. code:: python

    >>> for key, value in env.items():  # it's a dict*
            print(key, value)

    # USER fred…

    >>> env.USER.title()                # it's a str*
    'Fred'

    >>> env.TERM.partition('-')         # tip: a safer split
    ('xterm', '-', '256color')

*  Sung to the tune, *"It's a Sin,"* by the Pet Shop Boys.


Conversions & Parsing
-----------------------

Another handy feature of Entry objects is convenient type conversion and
parsing of values from strings.
Additional properties for this functionality are available.
For example:

.. code:: python

    >>> env.PI.float
    3.1416

    >>> env.STATUS.int
    5150

    >>> env.DATA.from_json
    {'one': 1, 'two': 2, 'three': 3}


Truthy Values
~~~~~~~~~~~~~~~~~~~~

Variable entries may contain boolean-*like* string values,
such as ``0, 1, yes, no, true, false``, etc.
To interpret them in a case-insensitive manner use the ``.truthy`` property:

.. code:: python

    >>> env.QT_ACCESSIBILITY
    Entry('QT_ACCESSIBILITY', '1')

    >>> env.QT_ACCESSIBILITY.truthy
    True

    >>> env = Environment(writable=True)
    >>> env.QT_ACCESSIBILITY = '0'          # set to '0'

    >>> env.QT_ACCESSIBILITY.truthy
    False


Standard Boolean Tests
++++++++++++++++++++++++

As always, standard tests or ``bool()`` on the entry can be done to check a
string.
Remember, such a test checks merely if the string is empty or not,
and would also return ``True`` on ``'0'`` or ``'false'``.


Paths
~~~~~~~~

Environment vars often contain a list of filesystem paths.
To split such path strings on ``os.pathsep``\
`🔗 <https://docs.python.org/3/library/os.html#os.pathsep>`_,
with optional conversion to ``pathlib.Path``\
`🔗² <https://docs.python.org/3/library/pathlib.html>`_
objects,
use one or more of the following:

.. code:: python

    >>> env.XDG_DATA_DIRS.list
    ['/usr/local/share', '/usr/share', ...]  # strings

    >>> env.SSH_AUTH_SOCK.path
    Path('/run/user/1000/keyring/ssh')

    >>> env.XDG_DATA_DIRS.path_list
    [Path('/usr/local/share'), Path('/usr/share'), ...]

To split on a different character,
simply do the split/partition on the string manually.

.. ~ (There is a ._pathsep variable that can be set on each entry,
.. ~ but not particularly more convenient.)


Examples
---------------

There are generally three cases for environment variables:

**Variable exists, has value:**

.. code:: python

    >>> env.USER                            # exists, repr
    Entry('USER', 'fred')

    >>> env.USER + '_suffix'                # str ops
    'fred_suffix'

    >>> env.USER.title()                    # str ops II
    'Fred'

    >>> print(f'term: {env.TERM}')          # via interpolation
    term: xterm-256color

    >>> bool(env.USER)                      # check exists & not empty
    True

    >>> key_name = 'PI'
    >>> env[key_name]                       # getitem syntax
    '3.1416'

    >>> env.PI.float                        # type conversion
    3.1416

    >>> env.PORT.int or 9000                # type conv. w/ default
    5150

    >>> env.QT_ACCESSIBILITY.truthy         # 0/1/yes/no/true/false
    True

    >>> env.JSON_DATA.from_json.keys()
    ['one', 'three', 'two']

    >>> env.XDG_DATA_DIRS.list
    ['/usr/local/share', '/usr/share']


**Variable exists, but is blank:**

.. code:: python

    >>> 'EMPTY' in env                      # check existence
    True

    >>> env.EMPTY                           # exists but empty
    Entry('EMPTY', '')

    >>> bool(env.EMPTY)                     # check exists & not empty
    False

    >>> env.EMPTY or 'default'              # exists, blank w/ default
    'default'


**Variable doesn't exist:**

.. code:: python

    >>> 'NO_EXISTO' in env                  # check existence
    False

    >>> env.NO_EXISTO or 'default'          # DNE with default
    'default'

    >>> env.NO_EXISTO                       # Doesn't exist repr
    NullEntry('NO_EXISTO')

    >>> bool(env.NO_EXISTO)                 # check exists & not empty
    False

    >>> env.XDG_DATA_DIRz.list              # DNE fallback
    []

    for data_dir in env.XDG_DATA_DIR.list:
        # Don't need to worry if this exists or not,
        # if not, it will be skipped.
        pass



Compatibility
---------------

*"What's the frequency Kenneth?"*

This module attempts compatibility with KR's existing
`env <https://github.com/kennethreitz/env>`_
package by implementing its ``prefix`` and ``map`` functions:

.. code:: python

    >>> env.prefix('XDG_')  # from_prefix preferred
    {'config_dirs': '/etc/xdg/xdg-mate:/etc/xdg', ...}

    >>> env.map(username='USER')
    {'username': 'fred'}

The lowercase transform can be disabled by passing another false-like value
as the second argument to ``prefix().``

While the package above has the coveted ``env`` namespace on PyPI,
ezenv uses the same simple module name and provides an implementation of the
interface.


Tests
---------------

Can be run here:

.. code:: shell

    ⏵ python3 -m env -v

Though this module works under Python2,
several of the tests *don't*,
because Py2 does Unicode differently or
doesn't have the facilities available to handle them by default
(pathlib/f-string).
Haven't had the urge to work around that due to declining interest.

FYI, a reference to the original module object is kept at ``env._module``
just in case it is needed for some reason.


Testing *with* ezenv
~~~~~~~~~~~~~~~~~~~~~

When you've used ``ezenv`` in your project,
it is easy to create a custom environment to operate under:

.. code:: python

    from env import Environment

    def test_foo():
        import mymodule

        mymodule.env = Environment(environ=dict(NO_COLOR='1'))
        assert mymodule.color_is_disabled() == True


Pricing
---------------

*"I'd buy THAT for a dollar!" :-D*

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mixmastamyk/env",
    "name": "ezenv",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Mike Miller",
    "author_email": "mixmastamyk@bitbucket.org",
    "download_url": "https://files.pythonhosted.org/packages/82/2f/781f71802c462cdab8fcb4c826d18a2e4a410ab302d164a39b5e977dda10/ezenv-0.92.tar.gz",
    "platform": "",
    "description": "\nEZ-Environment\n================\n\n*\"For easy access, baby!\u00a0 \u2026That's right.'\"\u2014Eazy-E*\n\nHave you ever thought handling environment variables in Python should be easier?\nIt is now.\n\n\nTL;DR:\n\n.. code:: python\n\n    >>> import env\n\n    >>> env.SERVER_PORT.int\n    8080\n\n*\"BAM!\" \u2014Emeril Lagasse*\n\nThe E.Z.E.nvironment module also has its own\n`theme song <https://youtu.be/Igxl7YtS1vQ?t=1m08s>`_:\n\n    *\"We want Eazy!\"*\n\n    | *EAZY!*\n    | *Everybody come on!*\n    | *EAZY!*\n    | *Who yall came to see?*\n    | *EAZY!*\n    | *A little louder come on!*\n    | *EAZY!*\n    | *Get those hands in the air!*\n    | *EAZY!*\n    | *Come on, come on say it!*\n    | *EAZY!*\n    | *A little louder come on!*\n    | *EAZY!*\n    | *Come on make some noise!*\n    |\n    | *A miracle of modern creation\u2026*\n    | *EZ E's on the set, hyped up with the bass*\n    | *And a little bit of what ya love*\n    | *From a brother who's smooth like a criminal*\n    | *I mean subliminal\u2026*\n\n\nBackground\n---------------\n\nIt's always been a tad clumsy to access environment variables and combine them\nwith other strings in Python\u2014\\\ncompared to shell languages at least.\nFor example, look how easy it is in (ba)sh:\n\n.. code:: shell\n\n    \u23f5 echo \"Libraries: $PWD/lib\"\n    Libraries: /usr/local/lib\n\nUnfortunately over in Python-land,\nrequired, escaped quotes and brackets\nserve mostly to complicate and add to visual clutter,\nreducing speed of comprehension.\n\n.. code:: python\n\n    >>> from os import environ\n    >>> from os.path import join\n\n    >>> join(environ['PWD'], 'lib')\n    '/usr/local/lib'\n\nEven the new-fangled string interpolation doesn't help as much as might be\nexpected:\n\n.. code:: python\n\n    >>> print(f'Libraries: {environ[\"PWD\"]}/lib')\n    Libraries: /usr/local/lib\n\n\nWith that in mind, allow me to introduce the ``env`` module.\nWith it I've tried to whittle complexity down,\nprimarily through direct attribute access:\n\n.. code:: python\n\n    >>> import env\n\n    >>> print('Term:', env.TERM)\n    Term: xterm-256color\n\n    >>> print(f'Libraries: {env.PWD}/lib')\n    Libraries: /usr/local/lib\n\nBut wait, there's more!\n\n\nInstall\n---------------\n\n.. code:: shell\n\n    \u23f5 pip3 install --user ezenv  # env was taken :-/\n\n\u00a0\u261b LGPL licensed. \u261a\n\n\nEnvironment and options\n------------------------\n\nOn import the module loads the environment into its namespace,\nthereby working like a dictionary with convenient attribute access.\n\nSo, no additional mapping instance has to be created or imported,\nunless you'd like to configure the interface further.\nThe following options are available to customize:\n\n.. code:: python\n\n    >>> from env import Environment\n\n    >>> env = Environment(\n            environ=os.environ,\n            sensitive=True|False,  # case: platform default\n            writable=False,\n            pathsep=os.pathsep,\n        )\n\nParam: environ\n~~~~~~~~~~~~~~\n\nA mapping of your own choosing may optionally be passed in as the first argument,\nfor testing and/or other purposes.\nI've recently learned that\n`os.environb <https://docs.python.org/3/library/os.html#os.environb>`_\n(bytes interface) is a thing that could be passed,\nfor example.\n\n\n.. ~ Noneify\n.. ~ ~~~~~~~~~~~~\n\n.. ~ Enabled by default,\n.. ~ this one signals non-existent variables by returning None.\n.. ~ It allows one to easily test for a variable and not have to worry about\n.. ~ catching exceptions.\n.. ~ If the variable is not set,\n.. ~ None will be returned instead:\n\n.. ~ .. code:: python\n\n    .. ~ >>> if env.COLORTERM:   # is not None or ''\n            .. ~ pass\n\n\n.. ~ **Default Values**\n\n.. ~ The one drawback to returning ``None`` is that there is no ``.get()`` method\n.. ~ to return a default when the variable isn't found.\n.. ~ That's easily rectified like so:\n\n.. ~ .. code:: python\n\n    .. ~ >>> env.FOO or 'bar'\n    .. ~ 'bar'\n\n\n.. ~ Blankify\n.. ~ ~~~~~~~~~~~~\n\n.. ~ Off by default,\n.. ~ this option mimics the behavior of most command-line shells.\n.. ~ Namely if the variable isn't found,\n.. ~ it doesn't complain and returns an empty string instead.\n.. ~ This can make some cases simpler,\n.. ~ as fewer checks for errors are needed when checking contents::\n\n    .. ~ if env.LANG.endswith('UTF-8'):\n        .. ~ pass\n\n.. ~ instead of the Noneify version::\n\n    .. ~ if env.LANG and env.LANG.endswith('UTF-8'):\n        .. ~ pass\n\n.. ~ However,\n.. ~ it may be a bug-magnet in the case the variable is misspelled,\n.. ~ It is here if you need it for compatibility.\n.. ~ Blankify takes precedence over Noneify if enabled.\n\n\nParam: writable\n~~~~~~~~~~~~~~~\n\nBy default the Environment object/module does not allow modification since\nwriting is rarely needed.\nThis default helps to remind us of that fact,\nthough the object can be easily be changed to writable if need be by enabling\nthis option.\n\nParam: sensitivity \ud83d\ude22\n~~~~~~~~~~~~~~~~~~~~~~\n\nVariables are case-sensitive by default on Unix,\n*insensitive* under Windows.\n\nWhile case sensitivity can be disabled to use variable names in mixed or\nlower-case,\nbe aware that variables and dictionary methods are in the same namespace,\nwhich could potentially be problematic if they are not divided by case.\nFor this reason, using variable names such as \"keys\" and \"items\"\nare not a good idea while in insensitive mode.\n*shrug*\n\nWorkaround: use \"get item\" / dictionary-style syntax if needed:\n\n.. code:: python\n\n    env['keys']  # :-/\n\n.. ~ varname = 'COLORTERM'\n.. ~ env[varname]\n\n\nEntry Objects\n----------------\n\nWhile using ``env`` at the interactive prompt,\nyou may be surprised that a variable value is not a simple string but rather\nan extended string-like object called an \"Entry.\"\nThis is most evident at the prompt since it prints a \"representation\"\nform by default:\n\n.. code:: python\n\n    >>> env.PWD                         # a.k.a. repr()\n    Entry('PWD', '/usr/local')\n\nThe reason behind this custom object is so that the variables can offer\nadditional functionality,\nsuch as parsing or conversion of the value to another type,\nwhile not crashing on a non-existent attribute access.\n\nNo matter however,\nas we've seen in the previous sections,\njust about any operation renders the string value as normal.\nAttributes ``.name`` and ``.value`` are also available for belt &\nsuspenders types:\n\n.. code:: python\n\n    >>> print(env.PWD)\n    /usr/local\n\n    >>> env.PWD.name, env.PWD.value, str(env.PWD)\n    ('PWD', '/tmp', '/tmp')\n\nRemember the ``env`` object/module is also a standard dictionary,\nwhile entry values are also strings,\nso full Python functionality is available:\n\n.. code:: python\n\n    >>> for key, value in env.items():  # it's a dict*\n            print(key, value)\n\n    # USER\u00a0fred\u2026\n\n    >>> env.USER.title()                # it's a str*\n    'Fred'\n\n    >>> env.TERM.partition('-')         # tip: a safer split\n    ('xterm', '-', '256color')\n\n*\u00a0 Sung to the tune, *\"It's a Sin,\"* by the Pet Shop Boys.\n\n\nConversions & Parsing\n-----------------------\n\nAnother handy feature of Entry objects is convenient type conversion and\nparsing of values from strings.\nAdditional properties for this functionality are available.\nFor example:\n\n.. code:: python\n\n    >>> env.PI.float\n    3.1416\n\n    >>> env.STATUS.int\n    5150\n\n    >>> env.DATA.from_json\n    {'one': 1, 'two': 2, 'three': 3}\n\n\nTruthy Values\n~~~~~~~~~~~~~~~~~~~~\n\nVariable entries may contain boolean-*like* string values,\nsuch as ``0, 1, yes, no, true, false``, etc.\nTo interpret them in a case-insensitive manner use the ``.truthy`` property:\n\n.. code:: python\n\n    >>> env.QT_ACCESSIBILITY\n    Entry('QT_ACCESSIBILITY', '1')\n\n    >>> env.QT_ACCESSIBILITY.truthy\n    True\n\n    >>> env = Environment(writable=True)\n    >>> env.QT_ACCESSIBILITY = '0'          #\u00a0set to '0'\n\n    >>> env.QT_ACCESSIBILITY.truthy\n    False\n\n\nStandard Boolean Tests\n++++++++++++++++++++++++\n\nAs always, standard tests or ``bool()`` on the entry can be done to check a\nstring.\nRemember, such a test checks merely if the string is empty or not,\nand would also return ``True`` on ``'0'`` or ``'false'``.\n\n\nPaths\n~~~~~~~~\n\nEnvironment vars often contain a list of filesystem paths.\nTo split such path strings on ``os.pathsep``\\\n`\ud83d\udd17 <https://docs.python.org/3/library/os.html#os.pathsep>`_,\nwith optional conversion to ``pathlib.Path``\\\n`\ud83d\udd17\u00b2 <https://docs.python.org/3/library/pathlib.html>`_\nobjects,\nuse one or more of the following:\n\n.. code:: python\n\n    >>> env.XDG_DATA_DIRS.list\n    ['/usr/local/share', '/usr/share', ...]  #\u00a0strings\n\n    >>> env.SSH_AUTH_SOCK.path\n    Path('/run/user/1000/keyring/ssh')\n\n    >>> env.XDG_DATA_DIRS.path_list\n    [Path('/usr/local/share'), Path('/usr/share'), ...]\n\nTo split on a different character,\nsimply do the split/partition on the string manually.\n\n.. ~ (There is a ._pathsep variable that can be set on each entry,\n.. ~ but not particularly more convenient.)\n\n\nExamples\n---------------\n\nThere are generally three cases for environment variables:\n\n**Variable exists, has value:**\n\n.. code:: python\n\n    >>> env.USER                            # exists, repr\n    Entry('USER', 'fred')\n\n    >>> env.USER + '_suffix'                # str ops\n    'fred_suffix'\n\n    >>> env.USER.title()                    # str ops II\n    'Fred'\n\n    >>> print(f'term: {env.TERM}')          # via interpolation\n    term: xterm-256color\n\n    >>> bool(env.USER)                      # check exists & not empty\n    True\n\n    >>> key_name = 'PI'\n    >>> env[key_name]                       # getitem syntax\n    '3.1416'\n\n    >>> env.PI.float                        # type conversion\n    3.1416\n\n    >>> env.PORT.int or 9000                #\u00a0type conv. w/ default\n    5150\n\n    >>> env.QT_ACCESSIBILITY.truthy         # 0/1/yes/no/true/false\n    True\n\n    >>> env.JSON_DATA.from_json.keys()\n    ['one', 'three', 'two']\n\n    >>> env.XDG_DATA_DIRS.list\n    ['/usr/local/share', '/usr/share']\n\n\n**Variable exists, but is blank:**\n\n.. code:: python\n\n    >>> 'EMPTY' in env                      # check existence\n    True\n\n    >>> env.EMPTY                           #\u00a0exists but empty\n    Entry('EMPTY', '')\n\n    >>> bool(env.EMPTY)                     # check exists & not empty\n    False\n\n    >>> env.EMPTY or 'default'              #\u00a0exists, blank\u00a0w/ default\n    'default'\n\n\n**Variable doesn't exist:**\n\n.. code:: python\n\n    >>> 'NO_EXISTO' in env                  # check existence\n    False\n\n    >>> env.NO_EXISTO or 'default'          #\u00a0DNE\u00a0with default\n    'default'\n\n    >>> env.NO_EXISTO                       #\u00a0Doesn't exist repr\n    NullEntry('NO_EXISTO')\n\n    >>> bool(env.NO_EXISTO)                 # check exists & not empty\n    False\n\n    >>> env.XDG_DATA_DIRz.list              # DNE fallback\n    []\n\n    for data_dir in env.XDG_DATA_DIR.list:\n        # Don't need to worry if this exists or not,\n        # if not, it will be skipped.\n        pass\n\n\n\nCompatibility\n---------------\n\n*\"What's the frequency Kenneth?\"*\n\nThis module attempts compatibility with KR's existing\n`env <https://github.com/kennethreitz/env>`_\npackage by implementing its ``prefix`` and ``map`` functions:\n\n.. code:: python\n\n    >>> env.prefix('XDG_')  #\u00a0from_prefix preferred\n    {'config_dirs': '/etc/xdg/xdg-mate:/etc/xdg', ...}\n\n    >>> env.map(username='USER')\n    {'username': 'fred'}\n\nThe lowercase transform can be disabled by passing another false-like value\nas the second argument to ``prefix().``\n\nWhile the package above has the coveted ``env`` namespace on PyPI,\nezenv uses the same simple module name and provides an implementation of the\ninterface.\n\n\nTests\n---------------\n\nCan be run here:\n\n.. code:: shell\n\n    \u23f5 python3 -m env -v\n\nThough this module works under Python2,\nseveral of the tests *don't*,\nbecause Py2 does Unicode differently or\ndoesn't have the facilities available to handle them by default\n(pathlib/f-string).\nHaven't had the urge to work around that due to declining interest.\n\nFYI, a reference to the original module object is kept at ``env._module``\njust in case it is needed for some reason.\n\n\nTesting *with* ezenv\n~~~~~~~~~~~~~~~~~~~~~\n\nWhen you've used ``ezenv`` in your project,\nit is easy to create a custom environment to operate under:\n\n.. code:: python\n\n    from env import Environment\n\n    def test_foo():\n        import mymodule\n\n        mymodule.env = Environment(environ=dict(NO_COLOR='1'))\n        assert mymodule.color_is_disabled() == True\n\n\nPricing\n---------------\n\n*\"I'd buy THAT for a dollar!\" :-D*\n",
    "bugtrack_url": null,
    "license": "LGPL",
    "summary": "A more convenient interface to environment variables.",
    "version": "0.92",
    "project_urls": {
        "Homepage": "https://github.com/mixmastamyk/env"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bc6e253ac7fee0cfd7db2ea5a51577dabaaeefcf3a71b9a8ac2fe060c84e5f84",
                "md5": "dcf9c644fc55bfc2ac0acf47c4b82066",
                "sha256": "fe4b20071c7497071d33530040f52f12a00dc938e5b5f7d5c4b7f922196c4ac6"
            },
            "downloads": -1,
            "filename": "ezenv-0.92-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dcf9c644fc55bfc2ac0acf47c4b82066",
            "packagetype": "bdist_wheel",
            "python_version": "3.8",
            "requires_python": null,
            "size": 10921,
            "upload_time": "2021-01-04T05:40:00",
            "upload_time_iso_8601": "2021-01-04T05:40:00.345022Z",
            "url": "https://files.pythonhosted.org/packages/bc/6e/253ac7fee0cfd7db2ea5a51577dabaaeefcf3a71b9a8ac2fe060c84e5f84/ezenv-0.92-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "822f781f71802c462cdab8fcb4c826d18a2e4a410ab302d164a39b5e977dda10",
                "md5": "e039f42963728e565cdc844491ea7447",
                "sha256": "a5a5d001a2352517b5992322c1795890dd3c9cf0ac6ad7912b0768fe84f33173"
            },
            "downloads": -1,
            "filename": "ezenv-0.92.tar.gz",
            "has_sig": false,
            "md5_digest": "e039f42963728e565cdc844491ea7447",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14154,
            "upload_time": "2021-01-04T05:39:58",
            "upload_time_iso_8601": "2021-01-04T05:39:58.311416Z",
            "url": "https://files.pythonhosted.org/packages/82/2f/781f71802c462cdab8fcb4c826d18a2e4a410ab302d164a39b5e977dda10/ezenv-0.92.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-01-04 05:39:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mixmastamyk",
    "github_project": "env",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ezenv"
}
        
Elapsed time: 0.07406s