{ "info": { "author": "Ilya Kogan", "author_email": "kogan@ohio.edu", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development" ], "description": "# Jinja 2 Command Line Template Renderer\n\n[![Build Status](https://travis-ci.org/ikogan/j2tmpl.svg?branch=master)](https://travis-ci.org/ikogan/j2tmpl)\n\nJinja2 command line renderer that converts environment variables\ninto objects on the context. For example:\n\n```\nDATABASE_MAIN_URI=mysql:3306\nDATABASE_MAIN_USERNAME=app\nDATABASE_CACHE_URI=redis:6379\nDATABASE_CACHE_USERNAME=app\n```\n\nBecomes:\n\n```json\n{\n \"database\": {\n \"main\": {\n \"uri\": \"mysql:3306\",\n \"username\": \"app\"\n },\n \"cache\": {\n \"uri\": \"redis:6379\",\n \"username\": \"app\"\n }\n }\n}\n```\n\nThis allows using things like iterations and others for more\ndynamic templates.\n\nWhile [there](https://sudo.isl.co/shinto-cli/)\n[are](https://github.com/kolypto/j2cli)\n[several](https://github.com/mattrobenolt/jinja2-cli) command line\nJinja2 template renderers, they all share a single property that this\nattempts to solve.\n\nOf those that support environment variables (for Docker, typically),\nthose environment variables are presented to the template verbatum.\nThat is, given this environment:\n\n```\nDATABASE_MAIN_URI=mysql:3306\nDATABASE_MAIN_USERNAME=app\nDATABASE_CACHE_URI=redis:6379\nDATABASE_CACHE_USERNAME=app\n```\n\nA template would have to use them in the following way:\n\n```jinja\ndatabases: {\n main: {\n uri: {{ DATABASE_MAIN_URI }}\n username: {{ DATABASE_MAIN_USERNAME }}\n cache: {\n uri: {{ DATABASE_CACHE_URI }}\n username {{ DATABASE_CACHE_USERNAME }}\n```\n\nSuppose, though, that you don't necessarily know how many databases\nyour container will have? This construct makes it diffcult in those\ninstances where you have to define *N* things differently depending\non a container deployment, or for base images.\n\n```jinja\ndatabases: {\n {% for name,definition in databases.items() %}\n {{ name }}: {\n uri: {{ definition.uri }},\n username: {{ definition.username }}\n },\n {% endfor %}\n```\n\n### Handling Collisions\n\nEnvironment variables can sometimes cause interesting\nproblems when building a tree structure. A `ValueError` will\nbe thrown if a variable is defined twice. Howver, the following\nis a valid set of environment variables:\n\n```\nAUTH_LDAP=true\nAUTH_LDAP_USERNAME=app\n```\n\nIn the template context, `{{ auth.ldap }}` has to be an object as\n`username` is a key inside of it. In this case, the value of\n`AUTH_LDAP` will be moved down into a special `_` key. The two\nvariables would then be:\n\n```jinja\n{{ auth.ldap._ }}=true\n{{ auth.ldap.username }}=app\n```\n\nFor this to work, almost all `_` in environment keys are removed.\nSo, `AUTH__LDAP_` is still translated to `{{ auth.ldap }}`. The only\nexception is a variable with *just* underscores. In this case, a '_'\nis added to the root of the context with that value. Note that all\nof the following would create this single underscore value:\n\n- `_`\n- `___`\n- `____________________`\n\nIf multiple solely-underscore environment variables exist, a `ValueError`\nis thrown.\n\n## Installation\n\nThis can be installed in two ways:\n\n1. `pip3 install j2tmpl`\n2. Download the prebuilt binaries.\n\nNote that the prebuilt binaries include the entire Python interpreter\nso they can be used just as easily as\n[confd](https://github.com/kelseyhightower/confd).\n\n## Usage\n\nThis can be used in two ways: processing a single file, or an entire directory.\n\nWhen a directory path is passed as the template file,\n`j2tmpl` will scan the directory for any files with\nan extension matching `template-extensions`, an argument that\ndefaults to `tmpl,jinja,jinja2,j2,jnj`.\n\n> Note that it will _still_ output to stdout unless `-o` is used.\n> If it is, then make sure it's a directory as well. If the\n> target directory doesn't exist, it will be created.\n\nIn addition to files matching that pattern, any _directory_\nthat matches that pattern and also ends with `.d` will be\nscanned for template fragments. Template files as well\nas files in `.d` directories that end in those extensions will\nall be concatenated together and rendered into one output file\nthat matches the name of the directory without the template\nextension and without `.d`.\n\nFor example, given the following directory structure:\n\n```\nfoo.conf.jinja.d/\n foo-1.jinja\n foo-2.jinja\nbar.conf.jinja.d/\n bar-1.jinja\n bar-2.jinja\nfoo.conf.jinja\nbaz.conf.jinja\n```\n\nThe output directory will contain the following:\n\n```\nbar.conf\nbaz.conf\nfoo.conf\n```\n\n## Built-In Filters and extensions\n\nJinja's [do](http://jinja.pocoo.org/docs/2.10/extensions/#expression-statement)\nand [loopcontrols](http://jinja.pocoo.org/docs/2.10/extensions/#loop-controls)\nextensions are enabled by default as are\nthe [trim_blocks](http://jinja.pocoo.org/docs/2.10/api/#jinja2.Environment)\nand [lstrip_blocks](http://jinja.pocoo.org/docs/2.10/api/#jinja2.Environment)\n\nFinally, the following additionals filters are avilable:\n\n**readfile(str)**:\n Read in the contents of the file represented by `str`. This is particularly\n useful for container secrets.\n\n**boolean(str)**:\n Convert the argument into a boolean. A case insensitive comparison to\n \"true\", \"yes\", and \"1\" will return `True`. Everything else is false.\n\n**b64encode(str)**:\n Base 64 encode the value.\n\n**b64decode(str)**:\n Base 64 decode the value.\n\n## Why not confd?\n\nSpeaking of confd, why not just use it? While confd is great, it can\nbe a bit too verbose. Having to define a series of config files with\nall keys enurmated for every single key can be daunting. For certain\nprojects, it probably makes sense, but I would often like to just\nbarf some environment variables into a configuration file with only\na tiny amount complexity.\n\nconfd is a 5.5mb or so binary and this is still less than 15mb. There are likely\nways to make this smaller that I would love to explore.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ikogan/j2tmpl", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "j2tmpl", "package_url": "https://pypi.org/project/j2tmpl/", "platform": "", "project_url": "https://pypi.org/project/j2tmpl/", "project_urls": { "Homepage": "https://github.com/ikogan/j2tmpl" }, "release_url": "https://pypi.org/project/j2tmpl/0.0.11/", "requires_dist": null, "requires_python": "", "summary": "Jinja2 templating based on environment variables.", "version": "0.0.11" }, "last_serial": 5892667, "releases": { "0.0.10": [ { "comment_text": "", "digests": { "md5": "a67d145a12aa3bf4dc9c7daa17135005", "sha256": "fcf2fe825336584f01ff769b33ac734900c00f09e84c2e9b9bd322c622993dab" }, "downloads": -1, "filename": "j2tmpl-0.0.10.tar.gz", "has_sig": false, "md5_digest": "a67d145a12aa3bf4dc9c7daa17135005", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7774, "upload_time": "2019-08-29T14:39:03", "url": "https://files.pythonhosted.org/packages/70/59/9da42d9339abff98730c6b6f628f7a5412b5e473d0c89ae75aa8ff89a6de/j2tmpl-0.0.10.tar.gz" } ], "0.0.11": [ { "comment_text": "", "digests": { "md5": "913167b2f115d4320053c63ba67aaf06", "sha256": "5590e51c9247e02b5b0dde0830af70915b20334d96282694f1c442a516d74433" }, "downloads": -1, "filename": "j2tmpl-0.0.11.tar.gz", "has_sig": false, "md5_digest": "913167b2f115d4320053c63ba67aaf06", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7782, "upload_time": "2019-09-26T20:47:43", "url": "https://files.pythonhosted.org/packages/9f/81/76f55d0d15e2e46ed3a9ccc6c9efa772b46af77038741296219ef87976f1/j2tmpl-0.0.11.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "329501a375c3aad91aafa62d818c7ee3", "sha256": "84f047b251a907e9818d94d142aceb0143880d39e6d1bc4a88944cddd25eff9b" }, "downloads": -1, "filename": "j2tmpl-0.0.2.tar.gz", "has_sig": false, "md5_digest": "329501a375c3aad91aafa62d818c7ee3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4479, "upload_time": "2019-05-17T23:09:50", "url": "https://files.pythonhosted.org/packages/57/3d/51c1b3d346cca8b2e0376fe409c52a196eb25227c01dc09ae39c236c2853/j2tmpl-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "cbdbf38f95447a519610354e3bf44910", "sha256": "3631d0ed29d942b6e3f20272bc9bd7cc879e9645ab8337a93643d4b036bf13c3" }, "downloads": -1, "filename": "j2tmpl-0.0.3.tar.gz", "has_sig": false, "md5_digest": "cbdbf38f95447a519610354e3bf44910", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6467, "upload_time": "2019-05-24T21:27:25", "url": "https://files.pythonhosted.org/packages/44/11/2840e446fc32a91a0c8e6977b4be17efd840cdb9ce8fc56eb36728b095ee/j2tmpl-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "c48d7d553469b228dac6f82582e8ad01", "sha256": "30690080d9e169ea145f0c7e7ee1da37d5f430f6e14ca347acaf53434d0d6f2a" }, "downloads": -1, "filename": "j2tmpl-0.0.4.tar.gz", "has_sig": false, "md5_digest": "c48d7d553469b228dac6f82582e8ad01", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6480, "upload_time": "2019-05-29T21:29:58", "url": "https://files.pythonhosted.org/packages/82/88/642d6025623966f0a0e1cbb3b415e9696788185ae52edcfecf6a04fa3dbe/j2tmpl-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "127d5005ba9263443b8a3af1f758adda", "sha256": "33723d085ad6444c7553f888095d29bf0b4d1498fb56f90a6ed0a793a38bc6bf" }, "downloads": -1, "filename": "j2tmpl-0.0.5.tar.gz", "has_sig": false, "md5_digest": "127d5005ba9263443b8a3af1f758adda", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6754, "upload_time": "2019-05-30T19:17:11", "url": "https://files.pythonhosted.org/packages/69/da/51cd499223aba953588c5e30a9776ef7d7ed4b8c8b2f6338767ec05a44e2/j2tmpl-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "273747ba211436580f82b53ccb8cd466", "sha256": "1d7a6d8834c8372c21c3554fdbcaa19d10cb2769dd1ea32f67738f95f134f7be" }, "downloads": -1, "filename": "j2tmpl-0.0.6.tar.gz", "has_sig": false, "md5_digest": "273747ba211436580f82b53ccb8cd466", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6857, "upload_time": "2019-06-11T17:22:23", "url": "https://files.pythonhosted.org/packages/c8/91/13e1d157eacd38a5286fd2ad5c16a9b85a72fa88d512201d56af58846b76/j2tmpl-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "33b389dab2be90f4614a9f34366f115f", "sha256": "9c73a4e4dd403dc8b23871f85c446436ae78f813d69fed3f8d513358f3a31f7f" }, "downloads": -1, "filename": "j2tmpl-0.0.7.tar.gz", "has_sig": false, "md5_digest": "33b389dab2be90f4614a9f34366f115f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7053, "upload_time": "2019-06-13T18:10:23", "url": "https://files.pythonhosted.org/packages/44/4b/6c6ef218a4728d5b65885d23dcead92f7c8c68f5b8bef14b7ef4e389decf/j2tmpl-0.0.7.tar.gz" } ], "0.0.8": [ { "comment_text": "", "digests": { "md5": "0595bf5b1fc57c9e1a2134b3becd1a32", "sha256": "e57f7993babd342d321368303d3d70fa7d97301a4fc1681b359b13d4ff32b9f9" }, "downloads": -1, "filename": "j2tmpl-0.0.8.tar.gz", "has_sig": false, "md5_digest": "0595bf5b1fc57c9e1a2134b3becd1a32", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7048, "upload_time": "2019-06-13T20:40:26", "url": "https://files.pythonhosted.org/packages/22/67/9a46003150c7b8aed6600a3a7d603bb8bd073a90d2b6ff3af5eeabdb57be/j2tmpl-0.0.8.tar.gz" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "4653aa12076ba8b06e4d582fcd563281", "sha256": "2f242d0095ba83ea8bd2f1e4a5d89c938b79c52a83b053f14a925e3127036755" }, "downloads": -1, "filename": "j2tmpl-0.0.9.tar.gz", "has_sig": false, "md5_digest": "4653aa12076ba8b06e4d582fcd563281", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7906, "upload_time": "2019-08-08T17:47:59", "url": "https://files.pythonhosted.org/packages/df/b1/23f00bfbfcd805c3c5ca7390ecef06e4d11fbcc7bd89d47185fdf5b05156/j2tmpl-0.0.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "913167b2f115d4320053c63ba67aaf06", "sha256": "5590e51c9247e02b5b0dde0830af70915b20334d96282694f1c442a516d74433" }, "downloads": -1, "filename": "j2tmpl-0.0.11.tar.gz", "has_sig": false, "md5_digest": "913167b2f115d4320053c63ba67aaf06", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7782, "upload_time": "2019-09-26T20:47:43", "url": "https://files.pythonhosted.org/packages/9f/81/76f55d0d15e2e46ed3a9ccc6c9efa772b46af77038741296219ef87976f1/j2tmpl-0.0.11.tar.gz" } ] }