{ "info": { "author": "Netlandish Inc.", "author_email": "hello@netlandish.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Intended Audience :: Developers", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": ".. |nlshield| image:: https://img.shields.io/badge/100%25-Netlandish-blue.svg?style=square-flat\n :target: https://www.netlandish.com\n\n================================\ndjango-json-settings2 |nlshield|\n================================\n:Info: Simple application to store Django settings in a json file.\n:Version: 0.1.0\n:Author: Team Netlandish (https://www.netlandish.com)\n\nPython / Django Support\n=======================\n\n* Python 3.6+ for Django versions 1.11+\n\nTruthfully, this app is so simple it will probably work with previous \nversion of Python and Django but we can't promise that.\n\nWhy?\n====\n\nI know, right? Who needs another way to store settings outside of the \nstandard Django ``settings.py`` setup.\n\nNone of the existing ways actually fit our typical Django deployment \nsetup in a way that was satisfactory. This method allows us to store \nsettings externally and in a way that fits our needs. Maybe it'll \nfit yours too.\n\nAlso, there is already a ``django-json-settings`` app and while that app \nvery well may be perfect for your project, it isn't a good fit for ours.\n\nWe created this app years ago and simply tuned it slowly as needed. It's \nvery simple yet flexible enough to work within virtually any workflow.\n\nThis app is really nothing more than helper functins wrapped on top \nof standard ``json`` module ops.\n\nOthers\n======\n\nThere are several other options to store settings outside of the typical\nDjango ``settings.py`` file. Here are a few:\n\n* https://github.com/isotoma/django-json-settings\n* https://github.com/theskumar/python-dotenv\n\nThere's dozens of others. Pick the one that best suits your needs.\n\nUsage\n=====\n\nSaving Settings\n---------------\n\nYou're going to need to save your desired settings to a json file \nfirst. There's a simple helper function, and management command, \nincluded to help.\n\nFor instance, say you want to create a simple setting for your ``SECRET_KEY`` \nvariable::\n\n $ python\n >>> settings_to_save = ['SECRET_KEY']\n >>> from json_settings2 import write_settings_from_django\n >>> write_settings_from_django(*settings_to_save)\n >>> exit()\n $ cat .settings.json\n {\n \"SECRET_KEY\": \"SUPER SECRET KEY IS HERE! COOOOOOOLLLLL!\"\n }\n $\n\nThe ``write_settings_from_django`` function takes a few optional variables:\n\n* settings_vars = Positional args giving every Django setting to save\n* filename = Filename of the json settings file. Defaults to ``.settings.json``\n* directory = Directory in which to save ``filename``. Defaults to ``.``.\n* indent = Indentation level for the json output. Set to ``None`` for the most \n compact file. Defaults to ``4``.\n* force = If ``directory``/``filename`` exists, overwrite it. \n Defaults to ``False``\n\nYou can also just use the management command. This requires that you place\n``json_settings2`` in your ``INSTALLED_APPS`` setting::\n\n $ python manage.py write_json_settings SECRET_KEY\n\nYou can add as many settings as you'd like too::\n\n $ python manage.py write_json_settings SECRET_KEY DATABASES STATIC_URL\n\nTo see the options, simply::\n\n $ python manage.py help write_json_settings\n\nLoading Settings\n----------------\n\nThe easiest way is to store all your default and local settings in \n``settings.py`` and load the json settings at the end. It's pretty \nstraight forward. Let's see an example::\n\n $ cat settings.py\n import os\n from json_settings2 import load_settings\n\n DEBUG = True\n STATIC_URL = '/static/'\n ... LOTS OF OTHERS SETTINGS HERE ...\n\n SETTINGS_DIR = os.path.dirname(os.path.abspath(__file__))\n load_settings(globals(), directory=SETTINGS_DIR, depth=3)\n\nEssentially this will tell the function to look for the settings file \nstarting in the same directory as ``settings.py`` and if not found, \nlook up to 3 levels higher in the directory tree. So let's say the \npath if your ``settings.py`` file is ``/home/user/app/current/code/settings.py``\n\nThe ``load_settings`` function will search the following paths for \n``.settings.json``:\n\n* ``/home/user/app/current/code/``\n* ``/home/user/app/current/``\n* ``/home/user/app/``\n* ``/home/user/``\n\nUseful if you want to store your settings outside of the code deployment \ndirectories, which is often the case.\n\nThe ``load_settings`` function takes the following variables:\n\n* current_settings - Dictionary that will be updated with found settings. \n Generally you'd pass in ``globals()``.\n* filename - Name of json file with settings. Defaults to ``.settings.json``\n* directory - Path of the directory where ``filename`` lives. Defaults to ``.``.\n* depth - Number of parent directories to scan for ``filename``. Defaults to ``0``.\n* store = Store settings into the ``current_settings`` dict. Defaults to ``True``.\n\nIf ``store`` is set to ``False`` then the ``current_settings`` dict will not \nbe altered.\n\nThe function will always return the pythonic representation of what was found \nin the json settings file.\n\n**Note on directory** - By default, the ``directory`` variable above is \nset to ``.`` - meaning current directory. This usually means the directory\nwhere you started the Python interpreter or are running ``manage.py`` from.\nThis is usually NOT what you want. It's best practice to always set the \nexpected directory to avoid troubleshooting headaches.\n\nWhat Is Used As a Setting?\n--------------------------\n\nWhen calling ``load_settings`` you can include extra data in your json \nsettings file that is useful for other puposes in your code but is not \nsomething you want cluttering your ``django.conf.settings`` object.\n\nOnly keys that are stored in all capital letters will be stored\nto the ``current_settings`` dict. So if your json settings has options \nthat are not all caps, they will only be returned as part of the loaded \njson data.\n\nIn other words, say you ``load_settings`` on the following data::\n\n {\n \"SeCreT_Key\": \"This will not be saved in Django settings.\",\n \"SECRET_KEY\": \"This WILL be saved in Django settings.\",\n \"secret_key\": :This will not be saved in Django settings.\"\n }\n\nYour ``SECRET_KEY`` setting will be set to ``This WILL be saved in Django settings.``\n\nWhere To Load Settings?\n-----------------------\n\nNormally you can place it at the bottom of the ``settings.py`` file. \nHowever, there are often times that you need those settings to guide \nthe values of other settings.\n\nThere is nothing stopping you from loading your json settings from \nanywhere in the process. It's up to you. Just remember that if you \nload your settings and then set a duplicate variable AFTER loading \nthe json settings, the duplicate variable will have the final say.\n\nFor example::\n\n $ cat .setting.json\n {\n \"STATIC_URL\": \"/my/cool/static/url/\"\n }\n $ cat settings.py\n import os\n from json_settings2 import load_settings\n\n SETTINGS_DIR = os.path.dirname(os.path.abspath(__file__))\n load_settings(globals(), directory=SETTINGS_DIR, depth=3)\n\n DEBUG = True\n STATIC_URL = '/static/'\n ... LOTS OF OTHERS SETTINGS HERE ...\n\nThe value of your ``STATIC_URL`` setting will be set to ``/static/`` when \nyou might be expecting it to be ``/my/cool/static/url/``. Just a heads up.\n\nCopyright & Warranty\n====================\nAll documentation, libraries, and sample code are\nCopyright 2019 Netlandish Inc. . The library and\nsample code are made available to you under the terms of the BSD license\nwhich is contained in the included file, BSD-LICENSE.\n\n\n==================\nCommercial Support\n==================\n\nThis software, and lots of other software like it, has been built in support of many of\nNetlandish's own projects, and the projects of our clients. We would love to help you\non your next project so get in touch by dropping us a note at hello@netlandish.com.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/netlandish/django-json-settings2/", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "django-json-settings2", "package_url": "https://pypi.org/project/django-json-settings2/", "platform": "any", "project_url": "https://pypi.org/project/django-json-settings2/", "project_urls": { "Homepage": "https://bitbucket.org/netlandish/django-json-settings2/" }, "release_url": "https://pypi.org/project/django-json-settings2/0.1/", "requires_dist": null, "requires_python": "", "summary": "Set, and save, Django settings to json formatted files.", "version": "0.1" }, "last_serial": 5299551, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "4235370622c584c704ac22254f480fc6", "sha256": "249c47774c515977d65730a926c8ac35f79930f6a8e9ded56501e048088bb770" }, "downloads": -1, "filename": "django-json-settings2-0.1.tar.gz", "has_sig": false, "md5_digest": "4235370622c584c704ac22254f480fc6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7450, "upload_time": "2019-05-21T20:02:47", "url": "https://files.pythonhosted.org/packages/5f/fc/d62554ce5538d8ee78b6c4c32a8732ba2bc6693294242951daa43329166e/django-json-settings2-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4235370622c584c704ac22254f480fc6", "sha256": "249c47774c515977d65730a926c8ac35f79930f6a8e9ded56501e048088bb770" }, "downloads": -1, "filename": "django-json-settings2-0.1.tar.gz", "has_sig": false, "md5_digest": "4235370622c584c704ac22254f480fc6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7450, "upload_time": "2019-05-21T20:02:47", "url": "https://files.pythonhosted.org/packages/5f/fc/d62554ce5538d8ee78b6c4c32a8732ba2bc6693294242951daa43329166e/django-json-settings2-0.1.tar.gz" } ] }