{ "info": { "author": "Carl Meyer", "author_email": "carl@oddbird.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5" ], "description": "====\nfern\n====\n\nYou want to be all `12factor`_ and read your config from the environ.\n\nYou also deploy your project in a variety of environments (dev, staging,\nprod...) and you want to be able to build in sane defaults for some of those\nenvironments (dev especially) so you don't have to carry around huge\nboilerplate ``.env`` files that aren't in version control. But you don't want\nto risk those built-in dev defaults silently getting used in production.\n\nFern's got your back.\n\nIn the simplest case, a ``fern.Env`` instance lets you call it to read strings\nfrom the environ::\n\n >>> env = fern.Env()\n >>> env('FOO')\n 'bar'\n\nIf we tried that and the ``FOO`` env var were not set, we'd get a\n``ValueError`` instead. Maybe that's OK, if this is a critical config value\nthat should always be set explicitly in the environ. If it's less critical, we\ncan set a default::\n\n >>> env = fern.Env()\n >>> env('DOES_NOT_EXIST', default='hey')\n 'hey'\n\nWe can also give a list of names of env vars, and fern will check each one and\ngive us the first value that's set::\n\n >>> env = fern.Env()\n >>> env(['DOES_NOT_EXIST', 'DOES_EXIST'])\n 'value_of_DOES_EXIST'\n\nAll environment values are strings. What if we want to parse this string into a\nmore structured data type? We can pass any unary coercion function to be\napplied to the value; e.g. the ``int`` type itself works as a unary coercion\nfunction: passed one string, it'll return that string parsed as an integer::\n\n >>> env = fern.Env()\n >>> env('SOME_INT', coerce=int)\n 6\n\nYou can write any function you like that takes in a string and returns\nwhatever, and pass it to ``coerce``. For instance,\n``fern.parse_dj_database_url`` will parse a database URL like\n``'postgres://localhost/dname'`` and return a Django-style database connection\ninfo dictionary.\n\nThe ``Env`` class has a few convenience methods for certain common values of\n``coerce``::\n\n >>> env = fern.Env()\n >>> env.integer('SOME_INT')\n 6\n >>> env.boolean('SOME_BOOL')\n True\n >>> env.comma_list('SOME_LIST')\n ['a', 'b', 'c']\n\nThe ``integer`` method just sets ``int`` as the coercion function.\n\nThe ``boolean`` method sets ``fern.parse_boolean`` as the coercion function; it\nconsiders the empty string, ``'0'``, ``'no'``, ``'f'``, ``'n'`` and ``'false'``\nto be ``False``; anything else is ``True``.\n\nThe ``comma_list`` method sets ``fern.parse_comma_list`` as the coercion\nfunction; it splits the env value on commas and returns the resulting values as\na list.\n\nNow let's make things a bit more complex. Let's say we want two deployment\nmodes, ``dev`` and ``prod``, and we've got a config value ``SECRET_KEY``. In\ndev mode, we want this value to default to ``\"dev secret\"`` (but still be\noverridable via the ``SECRET_KEY`` env var). In prod mode, we want to error out\nif the ``SECRET_KEY`` env var is not set explicitly; no hardcoded default could\nbe safe for production use. We can achieve that like this::\n\n >>> env = fern.Env('MODE', valid_modes=['dev', 'prod'])\n >>> env('SECRET_KEY', mode_defaults={'dev': \"dev secret\"})\n\nLet's unpack that a bit.\n\nIn the first line, we tell Fern that our valid modes are ``dev`` or ``prod``,\nand that an env var named ``MODE`` will tell us which mode we are in. (The\ndefault mode is the first one listed, so if ``MODE`` is not set we'll be in\n``dev`` mode. If ``MODE`` is set to something not listed in ``valid_modes``,\nwe'll get a ``ValueError``).\n\nIn the second line, we supply a dictionary for the ``mode_defaults``\nargument. The keys in this dictionary are mode names, and the values are\ndefaults to use for that mode. In this case, we supply a default only for\n``dev`` mode; in ``prod`` mode if the ``SECRET_KEY`` env var is not set, you'll\nget a ``ValueError``. So for our prod deployments, all we have to make sure to\ndo is set ``MODE=prod``, and that ensures the server won't start unless we also\nsupply the rest of the required config. In dev mode, we don't need any env vars\nat all.\n\n.. _12factor: https://12factor.net/\n\n\nCHANGES\n=======\n\n0.2 (2017.01.08)\n----------------\n\n* Fix ``mode_defaults`` with convenience coercion methods.\n\n\n0.1 (2017.01.07)\n----------------\n\n* Initial version.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/carljm/fern/", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "fern", "package_url": "https://pypi.org/project/fern/", "platform": "", "project_url": "https://pypi.org/project/fern/", "project_urls": { "Homepage": "https://github.com/carljm/fern/" }, "release_url": "https://pypi.org/project/fern/0.2/", "requires_dist": null, "requires_python": "", "summary": "Read config from the environment.", "version": "0.2" }, "last_serial": 2561114, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "391cbdd62c0ffb82a0abb3d9808bda2f", "sha256": "0347379782252126a69c7695bf46af4307ff8eb8a876289e08f39d7e56e50974" }, "downloads": -1, "filename": "fern-0.1.tar.gz", "has_sig": true, "md5_digest": "391cbdd62c0ffb82a0abb3d9808bda2f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5734, "upload_time": "2017-01-08T06:33:51", "url": "https://files.pythonhosted.org/packages/e6/58/89843705fe872d10dbc2980fd28246272b0a09fa8dbeec67b7fc76b26af7/fern-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "8f8dd5161b97ddabce9b7a85736cdd0a", "sha256": "77fd12acfc51e00eb85ad4dad185e6ebd44ed8873974fb2a4238524edf02c9ed" }, "downloads": -1, "filename": "fern-0.2.tar.gz", "has_sig": true, "md5_digest": "8f8dd5161b97ddabce9b7a85736cdd0a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5778, "upload_time": "2017-01-08T21:19:32", "url": "https://files.pythonhosted.org/packages/51/46/11d9dbf6a9b9de8ff1d8820ac02c75b2da8c85ff277b093943523f3bc30d/fern-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8f8dd5161b97ddabce9b7a85736cdd0a", "sha256": "77fd12acfc51e00eb85ad4dad185e6ebd44ed8873974fb2a4238524edf02c9ed" }, "downloads": -1, "filename": "fern-0.2.tar.gz", "has_sig": true, "md5_digest": "8f8dd5161b97ddabce9b7a85736cdd0a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5778, "upload_time": "2017-01-08T21:19:32", "url": "https://files.pythonhosted.org/packages/51/46/11d9dbf6a9b9de8ff1d8820ac02c75b2da8c85ff277b093943523f3bc30d/fern-0.2.tar.gz" } ] }