{ "info": { "author": "Jiangge Zhang", "author_email": "tonyseek@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries" ], "description": "python-envcfg\n=============\n\nAccessing environment variables with a magic module.\n\n::\n\n >>> import os\n >>> from envcfg.raw.python import CONFIGURE_OPTS\n >>>\n >>> CONFIGURE_OPTS\n '--enable-shared --enable-universalsdk=/ --with-universal-archs=intel'\n >>> CONFIGURE_OPTS == os.environ['PYTHON_CONFIGURE_OPTS']\n True\n\nIt works with many frameworks such as Django and Flask. Then you can store your\nconfig in the environment variables instead of framework-specific config files.\nIt is recommended by 12-Factor_.\n\n\nInstallation\n------------\n\n::\n\n $ pip install python-envcfg\n\n\nSupported Formats\n-----------------\n\n- ``import envcfg.raw.foo as config``:\n Import each ``FOO_*`` environment variable as string.\n- ``import envcfg.json.foo as config``:\n Import each ``FOO_*`` environment variable as JSON body.\n- ``import envcfg.smart.foo as config``:\n Try to import each ``FOO_*`` environment variable as JSON body, if fail then import it as string.\n\nThere is an example table:\n\n+----------------------+---------------------------+-----------------------+\n| Environment Variable | Python Import Statement | Python Variable Value |\n+======================+===========================+=======================+\n| ``FOO_NAME=foo`` | ``envcfg.raw.foo.NAME`` | ``'foo'`` |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NAME=\"foo\"`` | ``envcfg.raw.foo.NAME`` | ``'\"foo\"'`` |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NUM1=42`` | ``envcfg.raw.foo.NUM1`` | ``'42'`` |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NUM1=\"42\"`` | ``envcfg.raw.foo.NUM1`` | ``'\"42\"'`` |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NAME=foo`` | ``envcfg.json.foo.NAME`` | *ImportError* |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NAME=\"foo\"`` | ``envcfg.json.foo.NAME`` | ``'foo'`` |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NUM1=42`` | ``envcfg.json.foo.NUM1`` | ``42`` |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NUM1=\"42\"`` | ``envcfg.json.foo.NUM1`` | ``'42'`` |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NAME=foo`` | ``envcfg.smart.foo.NAME`` | ``'foo'`` |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NAME=\"foo\"`` | ``envcfg.smart.foo.NAME`` | ``'foo'`` |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NUM1=42`` | ``envcfg.smart.foo.NUM1`` | ``42`` |\n+----------------------+---------------------------+-----------------------+\n| ``FOO_NUM1=\"42\"`` | ``envcfg.smart.foo.NUM1`` | ``'42'`` |\n+----------------------+---------------------------+-----------------------+\n\nExamples\n--------\n\nUses with Flask\n~~~~~~~~~~~~~~~\n\n1. Defines environment variables with a prefix::\n\n $ cat .env # should not checked into VCS\n # values are valid JSON expressions\n MYAPP_DEBUG=true\n MYAPP_SECRET_KEY='\"7950ad141c7e4b3990631fcdf9a1d909\"'\n MYAPP_SQLALCHEMY_DATABASE_URI='\"sqlite:///tmp/myapp.sqlite3\"'\n\n2. Creates Flask app and loads config from python-envcfg::\n\n $ cat myapp.py\n ...\n app = Flask(__name__)\n app.config.from_object('envcfg.json.myapp') # MYAPP_ -> .myapp\n ...\n\n3. Enters your app with those environment variables::\n\n $ env $(cat .env | xargs) python myapp.py\n\n\nUses with Django\n~~~~~~~~~~~~~~~~\n\n1. Creates a django project and moves all sensitive config items into the\n environment variables::\n\n $ cat djapp/settings.py # codebase-scope config\n ...\n INSTALLED_APPS = (\n 'django.contrib.admin',\n )\n ...\n\n $ cat .env # environment-scope config, should not checked into VCS\n # values are valid JSON expressions\n DJAPP_SECRET_KEY='\"wo9g2o#jws=u\"'\n DJAPP_DEBUG=true\n DJAPP_TEMPLATE_DEBUG=true\n\n2. Adds importing statements in the end of ``settings.py`` module::\n\n $ tail -n 2 djapp/settings.py\n # importing all config items stored in the environment variables \n from envcfg.json.djapp import * # noqa\n\n3. Runs your Django app with environment variables::\n\n $ env $(cat .env | xargs) python manage.py runserver\n\n\nUses with Tornado\n~~~~~~~~~~~~~~~~~\n\n1. Defines environment variables with a prefix::\n\n $ cat .env\n export TORAPP_PORT='8888'\n export TORAPP_MYSQL_HOST='\"127.0.0.1\"'\n export TORAPP_MYSQL_DATABASE='\"database\"'\n\n\n2. Creates a Tornado project and loads config::\n\n $ cat torapp/server.py\n\n from tornado.web import Application, RequestHandler\n from tornado.ioloop import IOLoop\n from tornado.options import define, options\n from tordb import Connection\n\n\n def options_from_object(*args, **kwargs):\n module = __import__(*args, **kwargs)\n for name, value in vars(module).items():\n name = name.lower()\n if name in options._options:\n options._options[name].set(value)\n\n\n class IndexHandler(RequestHandler):\n def initialize(self):\n self.db = Connection(options.mysql_host, options.mysql_database)\n\n def get(self):\n pass # some database operations with ``self.db``\n\n\n application = Application([\n (r'/', IndexHandler),\n ])\n\n define('port', type=int)\n define('mysql_host', type=unicode)\n define('mysql_database', type=unicode)\n options_from_object('envcfg.json.torapp', fromlist=['torapp'])\n\n\n if __name__ == '__main__':\n application.listen(options.port)\n IOLoop.instance().start()\n\n\n3. Runs your Tornado app::\n\n $ env $(cat .env | xargs) python server.py\n\n\nWorks on Projects\n-----------------\n\nIn development, we can work with per-project environments but no more typing\n``source foo/bar``.\n\nI recommend to put your project-specified environment variables in\n``{PROJECT_ROOT}/.env`` and mark the ``.env`` as ignored in your VCS. For\nexample, you can write ``/.env`` in ``.gitignore`` if you are using Git, and\nput a ``.env.example`` as a copying template for new-cloned projects.\n\nAnd then, you can use some utility such as `honcho`_ or `autoenv`_ to apply\nthe ``.env`` automatically.\n\nFor honcho::\n\n $ echo 'MYPROJECT_DEBUG=true' >> .env\n $ echo 'web: python manage.py runserver' >> Procfile\n $ honcho run python manage.py check-debug\n True\n $ honcho start web\n Starting development server at http://127.0.0.1:5000/\n ...\n\nFor autoenv::\n\n $ echo 'MYPROJECT_DEBUG=true' >> myproject/.env\n $ cd myproject\n $ python manage.py check-debug\n True\n $ python manage.py runserver\n Starting development server at http://127.0.0.1:5000/\n ...\n\n\nIssues\n------\n\nIf you want to report bugs or request features, please create issues on\n`GitHub Issues `_.\n\n\n.. _12-Factor: http://12factor.net\n.. _honcho: https://github.com/nickstenning/honcho\n.. _autoenv: https://github.com/kennethreitz/autoenv\n\n.. |Build Status| image:: https://travis-ci.org/tonyseek/python-envcfg.svg?branch=master,develop\n :target: https://travis-ci.org/tonyseek/python-envcfg\n :alt: Build Status\n.. |Coverage Status| image:: https://img.shields.io/coveralls/tonyseek/python-envcfg/develop.svg\n :target: https://coveralls.io/r/tonyseek/python-envcfg\n :alt: Coverage Status\n.. |Wheel Status| image:: https://img.shields.io/pypi/wheel/python-envcfg.svg\n :target: https://warehouse.python.org/project/python-envcfg\n :alt: Wheel Status\n.. |PyPI Version| image:: https://img.shields.io/pypi/v/python-envcfg.svg\n :target: https://pypi.python.org/pypi/python-envcfg\n :alt: PyPI Version\n.. |PyPI Downloads| image:: https://img.shields.io/pypi/dm/python-envcfg.svg\n :target: https://pypi.python.org/pypi/python-envcfg\n :alt: Downloads\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/tonyseek/python-envcfg", "keywords": "env,config,12-factor", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "python-envcfg", "package_url": "https://pypi.org/project/python-envcfg/", "platform": "Any", "project_url": "https://pypi.org/project/python-envcfg/", "project_urls": { "Homepage": "https://github.com/tonyseek/python-envcfg" }, "release_url": "https://pypi.org/project/python-envcfg/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "Accessing environment variables with a magic module.", "version": "0.2.0" }, "last_serial": 2207559, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "5096f87fe1b28ff9f70475fdae224ecd", "sha256": "cba57590f68c921b96a07fced6ed02029961b012b72ce40e0482937f7a2a97f7" }, "downloads": -1, "filename": "python_envcfg-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5096f87fe1b28ff9f70475fdae224ecd", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5141, "upload_time": "2014-09-07T16:16:19", "url": "https://files.pythonhosted.org/packages/74/b3/d0ace3ba25ee35dc8d973176a33ab011499f84b1b381c335c8f1dc264bd8/python_envcfg-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4533f1bfd8c9b906d3875f7886b3d979", "sha256": "94983ea10439c0236913dbecee3047ce794582639d0841841be8b3aa1de7ed63" }, "downloads": -1, "filename": "python-envcfg-0.1.0.tar.gz", "has_sig": false, "md5_digest": "4533f1bfd8c9b906d3875f7886b3d979", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3544, "upload_time": "2014-09-07T16:16:15", "url": "https://files.pythonhosted.org/packages/06/06/f71b22478744f914dd76558989b0d1664ba6b12012ff5d10b590f003b00f/python-envcfg-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "3c87d10fda922cddca2828edb2e761ed", "sha256": "427e02e795536eb9564bd94e4ae79e0e6b9d425c3cd19832a1470d57b922d58e" }, "downloads": -1, "filename": "python_envcfg-0.2.0-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "3c87d10fda922cddca2828edb2e761ed", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9008, "upload_time": "2016-07-07T09:14:44", "url": "https://files.pythonhosted.org/packages/8c/45/3aa2ef6954e6f6d135ca468ee6d2ce57f97a322b315f33d96b6fa0b345a3/python_envcfg-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5006237e58bdd6297f38d59dc3a5b1cb", "sha256": "7b5d8617ec39d62306af073ea1f2dfe7be5c60e6aa9d725899d15d023a0946ff" }, "downloads": -1, "filename": "python-envcfg-0.2.0.tar.gz", "has_sig": true, "md5_digest": "5006237e58bdd6297f38d59dc3a5b1cb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5360, "upload_time": "2016-07-07T09:15:07", "url": "https://files.pythonhosted.org/packages/fc/7d/892061b11030a210d3341354d67143417dcac6757d711583e9c463787e05/python-envcfg-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3c87d10fda922cddca2828edb2e761ed", "sha256": "427e02e795536eb9564bd94e4ae79e0e6b9d425c3cd19832a1470d57b922d58e" }, "downloads": -1, "filename": "python_envcfg-0.2.0-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "3c87d10fda922cddca2828edb2e761ed", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9008, "upload_time": "2016-07-07T09:14:44", "url": "https://files.pythonhosted.org/packages/8c/45/3aa2ef6954e6f6d135ca468ee6d2ce57f97a322b315f33d96b6fa0b345a3/python_envcfg-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5006237e58bdd6297f38d59dc3a5b1cb", "sha256": "7b5d8617ec39d62306af073ea1f2dfe7be5c60e6aa9d725899d15d023a0946ff" }, "downloads": -1, "filename": "python-envcfg-0.2.0.tar.gz", "has_sig": true, "md5_digest": "5006237e58bdd6297f38d59dc3a5b1cb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5360, "upload_time": "2016-07-07T09:15:07", "url": "https://files.pythonhosted.org/packages/fc/7d/892061b11030a210d3341354d67143417dcac6757d711583e9c463787e05/python-envcfg-0.2.0.tar.gz" } ] }