{ "info": { "author": "Satoru SATOH", "author_email": "satoru.satoh@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Text Processing :: Markup", "Topic :: Utilities" ], "description": "=============\nanytemplate\n=============\n\nAbout\n======\n\n.. image:: https://img.shields.io/pypi/v/anytemplate.svg\n :target: https://pypi.python.org/pypi/anytemplate/\n :alt: [Latest Version]\n\n.. image:: https://img.shields.io/pypi/pyversions/anytemplate.svg\n :target: https://pypi.python.org/pypi/anytemplate/\n :alt: [Python versions]\n\n.. .. image:: https://img.shields.io/pypi/l/anytemplate.svg\n :target: https://pypi.python.org/pypi/anytemplate/\n :alt: [MIT License]\n\n.. image:: https://api.travis-ci.org/ssato/python-anytemplate.png?branch=master\n :target: https://travis-ci.org/ssato/python-anytemplate\n :alt: [Test status]\n\n.. image:: https://coveralls.io/repos/ssato/python-anytemplate/badge.png\n :target: https://coveralls.io/r/ssato/python-anytemplate\n :alt: [Coverage Status]\n\n.. image:: https://landscape.io/github/ssato/python-anytemplate/master/landscape.png\n :target: https://landscape.io/github/ssato/python-anytemplate/master\n :alt: [Code Health]\n\nThis is a python library works as an abstraction layer for various python\ntemplate engines and rendering libraries, and provide a few very simple and\neasily understandable APIs to render templates.\n\nAlso a CLI tool called anytemplate_cli is provided to render templates written\nin these template languages.\n\n- Author: Satoru SATOH \n- License: MIT\n\nThe following template engines are supported currently:\n\n.. csv-table::\n :header: \"Name\", \"Notes\"\n :widths: 15, 65\n\n `string.Template `_ , Always available as it's included in python standard lib.\n `jinja2 `_ , Highest priory will be given and becomes default if found\n `mako `_ ,\n `tenjin `_ , renders() API is not supported\n `Cheetah `_ , `Cheetah3 `_ is needed to use with python 3.x\n `pystache `_ ,\n\n.. .. [#] https://pypi.python.org/pypi/Cheetah3/ , which is not yet available in stable Fedora release according to https://apps.fedoraproject.org/packages/python-cheetah.\n\nFeatures\n==========\n\n- Provides very simple and unified APIs for various template engines:\n\n - anytemplate.renders() to render given template string\n - anytemplate.render() to render given template file\n\n- Can process template engine specific options:\n\n - anytemplate.render{s,} allow passing option parameters specific to each template rendering functions behind this library\n - anytemplate.find_engine() returns an 'engine' object to allow some more fine tunes of template engine specific customization by passing option parameters to them\n\n- Provide a CLI tool called anytemplate_cli to process templates in command line\n\nAPI Usage\n============\n\nAPI Examples\n--------------\n\nCall 'anytemplate.renders' to render given template strings like this:\n\n.. code-block:: python\n\n result = anytemplate.renders(\"{{ x|default('aaa') }}\", {'x': 'bbb'},\n at_engine=\"jinja2\")\n\nThe first parameter is a template string itself. And the second one is a dict\nor dict-like object which is generally called as 'context' object to\ninstantiate templates. The third one, keyword parameter 'at_engine' is needed\nto find the appropriate template engine to render given template string. This\nkeyword parameter is necessary because it's very difficult and should be almost\nimpossible for any template languages to detect correct template engine only by\ngiven template string itself.\n\nIf 'at_engine' is omitted, a template engine of highest priority is choosen.\nOnly available template engines and libraries are enabled automatically in\nanytemplate, so that that engine will be vary in accordance with your\nenvironment. For example, 'jinja2' is the engine of highest priority in my\ndevelopment envrionment with all supported template engines and libraries\ninstalled:\n\n.. code-block:: python\n\n In [6]: import anytemplate\n\n In [7]: anytemplate.find_engine() # It will return the highest priority one.\n Out[7]: anytemplate.engines.jinja2.Engine\n\n In [8]: anytemplate.find_engine().name()\n Out[8]: 'jinja2'\n\nIt's also possible to some option parameters specific to the template engine\nchoosen with keyword parameters like this:\n\n.. code-block:: python\n\n # 'strict_undefined' is a parameter for mako.template.Template.__init__().\n result = anytemplate.renders(\"${x}\", {'x': 'bbb'},\n at_engine=\"mako\",\n strict_undefined=False)\n\nFor details such as generic option parameters list of 'anytemplate.renders',\nsee its help:\n\n.. code-block:: python\n\n In [20]: help(anytemplate.renders)\n Help on function renders in module anytemplate.api:\n\n renders(template_content, context=None, at_paths=None, at_encoding='UTF-8', at_engine=None, at_ask_missing=False, at_cls_args=None, **kwargs)\n Compile and render given template content and return the result string.\n\n :param template_content: Template content\n :param context: A dict or dict-like object to instantiate given\n template file\n :param at_paths: Template search paths\n :param at_encoding: Template encoding\n :param at_engine: Specify the name of template engine to use explicitly or\n None to find it automatically anyhow.\n :param at_cls_args: Arguments passed to instantiate template engine class\n :param kwargs: Keyword arguments passed to the template engine to\n render templates with specific features enabled.\n\n :return: Rendered string\n\n In [21]:\n\nCall 'anytemplate.render' to render given template file like this:\n\n.. code-block:: python\n\n result1 = anytemplate.render(\"/path/to/a_template.tmpl\", {'x': 'bbb'},\n at_engine=\"mako\")\n\n result2 = anytemplate.render(\"another_template.t\", {'y': 'ccc'},\n at_engine=\"tenjin\",\n at_paths=['/path/to/templates/', '.'])\n\nThe parameters are similar to the previous example except for the first one.\n\nThe first parameter is not a template string but a path of template file, may\nbe relative or absolute path, or basename with template search paths\n(at_paths=[PATH_0, PATH_1, ...]) given.\n\nSome module wraps actual template engines in anytemplate supports automatic\ndetection of the engine by file extensions of template files. For example,\nJinja2 template files of which expected file extensions are '.j2' or '.jinja2'\ntypically. So I made that such files are automatically detected as jinja2\ntemplate file and you don't need to specify the engine by 'at_engine' parameter\nlike this:\n\n.. code-block:: python\n\n # 'jinaj2' template engine is automatically choosen because the extension\n # of template file is '.j2'.\n result = anytemplate.render(\"/path/to/a_template.j2\", {'x': 'bbb'})\n\nFor details such as option parameters list of 'anytemplate.render',\nsee its help:\n\n.. code-block:: python\n\n In [21]: help(anytemplate.render)\n Help on function render in module anytemplate.api:\n\n render(filepath, context=None, at_paths=None, at_encoding='UTF-8', at_engine=None, at_ask_missing=False, at_cls_args=None, **kwargs)\n Compile and render given template file and return the result string.\n\n :param template: Template file path\n :param context: A dict or dict-like object to instantiate given\n template file\n :param at_paths: Template search paths\n :param at_encoding: Template encoding\n :param at_engine: Specify the name of template engine to use explicitly or\n None to find it automatically anyhow.\n :param at_cls_args: Arguments passed to instantiate template engine class\n :param kwargs: Keyword arguments passed to the template engine to\n render templates with specific features enabled.\n\n :return: Rendered string\n\n In [22]:\n\nCLI Usage\n============\n\nCLI help\n-----------\n\n.. code-block:: console\n\n ssato@localhost% PYTHONPATH=. python anytemplate/cli.py -h\n Usage: anytemplate/cli.py [OPTION ...] TEMPLATE_FILE\n\n Options:\n -h, --help show this help message and exit\n -T TEMPLATE_PATHS, --template-path=TEMPLATE_PATHS\n Template search path can be specified multiple times.\n Note: Dir in which given template exists is always\n included in the search paths (at the end of the path\n list) regardless of this option.\n -C CONTEXTS, --context=CONTEXTS\n Specify file path and optionally its filetype, to\n provides context data to instantiate templates. The\n option argument's format is\n [type:] ex. -C\n json:common.json -C ./specific.yaml -C yaml:test.dat,\n -C yaml:/etc/foo.d/*.conf\n -E ENGINE, --engine=ENGINE\n Specify template engine name such as 'jinja2'\n -L, --list-engines List supported template engines in your environment\n -o OUTPUT, --output=OUTPUT\n Output filename [stdout]\n -v, --verbose Verbose mode\n -q, --quiet Quiet mode\n ssato@localhost% cat examples/ctx.yml\n xs:\n - name: Alice\n - name: Bob\n - name: John\n\n ssato@localhost% cat examples/jinja2.j2\n {% include \"jinja2-incl.j2\" %}\n ssato@localhost% cat examples/jinja2-incl.j2\n {# jinja2 example: #}\n {% for x in xs if x.name -%}\n {{ x.name }}\n {% endfor %}\n ssato@localhost% PYTHONPATH=. python anytemplate/cli.py -E jinja2 \\\n > -C examples/ctx.yml examples/jinja2.j2\n\n Alice\n Bob\n John\n\n ssato@localhost%\n\nCLI Features\n-----------------\n\nMultiple context files support to define template parameters\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThe CLI tool (anytemplate_cli) supports to load multiple context files in YAML\nor JSON or others to give template parameters with -C|--context option.\n\nLoading and composing of context files are handled by my another python library\ncalled anyconfig (python-anyconfig) if installed and available on your system.\n\n- anyconfig on PyPI: http://pypi.python.org/pypi/anyconfig/\n- python-anyconfig on github: https://github.com/ssato/python-anyconfig\n\nIf anyconfig is not found on your system, only JSON context files are supported\nformat of context files, by help of python standard json or simplejson library.\n\nTemplate search paths\n^^^^^^^^^^^^^^^^^^^^^^^\n\nTemplate search paths are specified with -T|--template-path option of the CLI\ntool (anytemplate_cli). This is useful when using 'include' directive in\ntemplates; ex. -T .:templates/.\n\nNOTE: The default search path will be ['.',\ndir_in_which_given_template_file_is] where templatedir is the directory in\nwhich the given template file exists if -T option is not given. And even if -T\noption is used, templatedir will be appended to that search paths at the end.\n\nBuild & Install\n================\n\nIf you're Fedora or Red Hat Enterprise Linux user, you can build and install\n[s]rpm by yourself:\n\n.. code-block:: console\n\n $ python setup.py srpm && mock dist/python-anytemplate-.src.rpm\n\nor:\n\n.. code-block:: console\n\n $ python setup.py rpm\n\nor you can install pre-built RPMs from one of my copr repos, https://copr.fedorainfracloud.org/coprs/ssato/python-anyconfig/\n\n.. code-block:: console\n\n # Fedora\n $ sudo dnf copr enable ssato/python-anyconfig\n $ sudo dnf install -y python-anytemplate # or python3-anytemplate (python3 version)\n\n.. code-block:: console\n\n # RHEL, CentOS\n $ (cd /etc/yum.repos.d; sudo curl -O https://copr.fedorainfracloud.org/coprs/ssato/python-anyconfig/repo/epel-7/ssato-python-anyconfig-epel-7.repo)\n $ sudo dnf install -y python-anytemplate # or python3-anytemplate (python3 version)\n\nOtherwise, try usual ways to build and/or install python modules such like 'pip\ninstall git+https://github.com/ssato/python-anytemplate' and 'python setup.py\nbdist', etc.\n\nHacking\n===========\n\nHow to test\n-------------\n\nTry to run '[WITH_COVERAGE=1] ./pkg/runtest.sh [path_to_python_code]'.\n\nTODO & Issues\n===============\n\n- Add descriptions (doctext) of template engine and library specific options: WIP\n- Add descriptions (doctext) how anytemplate wraps each template engine and library: WIP\n- Complete unit tests:\n\n - Add test cases of each template engine specific options: WIP\n\n- Stablize public and private (internal) APIs:\n\n - Private APIs still needs a lot of work especially. It's very vague how it should be as each template engine have its own concept and design and I'm not sure how to abstract them yet.\n - I don't think public APIs have large issues but these be affected by changes of private APIs more or less; I'm thinking to deprecate the keyword parameter 'at_cls_args' for example.\n\nMisc\n======\n\nAlternatives\n---------------\n\nThere are a few libraries works like this:\n\n- TemplateAlchemy: https://pypi.python.org/pypi/TemplateAlchemy/\n- collective.templateengines: https://pypi.python.org/pypi/collective.templateengines\n\nThese look more feature-rich and comprehensive, but I prefer a lot more\nlightweight and thin wrapper library along with CLI tool (template renderer) so\nthat I made anytemplate.\n\nAnd:\n\n- python-jinja2-cli: https://github.com/ssato/python-jinja2-cli\n\nAnytemplate is a successor of python-jinja2-cli.\n\n.. vim:sw=2:ts=2:et:\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ssato/python-anytemplate", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "anytemplate", "package_url": "https://pypi.org/project/anytemplate/", "platform": "", "project_url": "https://pypi.org/project/anytemplate/", "project_urls": { "Homepage": "https://github.com/ssato/python-anytemplate" }, "release_url": "https://pypi.org/project/anytemplate/0.1.5/", "requires_dist": null, "requires_python": "", "summary": "A module to abstract template engines and provide common APIs", "version": "0.1.5" }, "last_serial": 4142162, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "337a0ceea95c92f658d613cbb06f952a", "sha256": "524078dd39262ea5ef6137e39c2dac492a962cc6619dc97bf56a1c52e86153da" }, "downloads": -1, "filename": "anytemplate-0.0.1.tar.gz", "has_sig": false, "md5_digest": "337a0ceea95c92f658d613cbb06f952a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29185, "upload_time": "2015-05-10T04:47:22", "url": "https://files.pythonhosted.org/packages/5c/8e/da390d90f7d50d568399859868b1ceaf99dcbe87d64e9a42bc26a4746893/anytemplate-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "633da1ba19358e58626e34ab11091fd8", "sha256": "885ebab5e0e70db11fbd9ca7fc9156f874518a69abc39681b8c71790fe3c2148" }, "downloads": -1, "filename": "anytemplate-0.0.2.tar.gz", "has_sig": false, "md5_digest": "633da1ba19358e58626e34ab11091fd8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29260, "upload_time": "2015-05-10T06:15:26", "url": "https://files.pythonhosted.org/packages/71/9d/2a84de3dca25f6599668827ca45267dbba6cff88553436c221ec3e025dda/anytemplate-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "378192b75537673de12ac27639c6fd25", "sha256": "7be1db05d1b0c6ed89f410ac7306d13f5a59295762a16e4a32c55a71cd640b6b" }, "downloads": -1, "filename": "anytemplate-0.0.3.tar.gz", "has_sig": false, "md5_digest": "378192b75537673de12ac27639c6fd25", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31490, "upload_time": "2015-05-11T15:54:15", "url": "https://files.pythonhosted.org/packages/d0/05/fd940d791daa5e8f9381d7df4db2352a699e22c214a483a8cbf72dc1bd56/anytemplate-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "1c4e06188f6c49d7bc556a69553db657", "sha256": "1dd94d9dffd6adf7e097dcf14c9261af130e4b5505d6525ac6d74bbf8e7fd1dc" }, "downloads": -1, "filename": "anytemplate-0.0.4.tar.gz", "has_sig": false, "md5_digest": "1c4e06188f6c49d7bc556a69553db657", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32155, "upload_time": "2015-06-03T05:08:38", "url": "https://files.pythonhosted.org/packages/52/19/b550cc832eb6b4a1b66f1e6054481079b4547070bb45a01f3d6138193094/anytemplate-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "9c630afb1f1b59fd52ae04d3ff31a030", "sha256": "bc412b0921ed992edde51ac3f737683156568b67d3ecf5734f3c392ceda0ca7f" }, "downloads": -1, "filename": "anytemplate-0.0.5.tar.gz", "has_sig": false, "md5_digest": "9c630afb1f1b59fd52ae04d3ff31a030", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32680, "upload_time": "2015-06-15T17:46:44", "url": "https://files.pythonhosted.org/packages/f8/69/d29bfe0e916b8d926504fb674bd574e66e982deeacc0adeed4556685c6ec/anytemplate-0.0.5.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "4dc049174952047e9575ab7f63c6abb4", "sha256": "d457f7fa277af6d6800cfe3f14b177d976cb92a7b01bec9bae1f4614dc513c6e" }, "downloads": -1, "filename": "anytemplate-0.1.0.tar.gz", "has_sig": false, "md5_digest": "4dc049174952047e9575ab7f63c6abb4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 34111, "upload_time": "2016-11-09T13:35:52", "url": "https://files.pythonhosted.org/packages/5a/78/3d0b49995f9b7c53be69482d72590e11c58dd3e7ec892c5cb8060281a61e/anytemplate-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "e13fefb0b66c51ec54490a78f493805e", "sha256": "aeaea6b0285c9df7bc3693e221d76d33eedade36f9eb6931e355f04e3e55206d" }, "downloads": -1, "filename": "anytemplate-0.1.1.tar.gz", "has_sig": false, "md5_digest": "e13fefb0b66c51ec54490a78f493805e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31466, "upload_time": "2017-04-25T07:18:10", "url": "https://files.pythonhosted.org/packages/07/30/ea8f7fbd756067bab4f0118bf4b05d5fe4ef12c549b43555a51a79e0f054/anytemplate-0.1.1.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "36a3f3cdc0692f9fee904432e10a9689", "sha256": "94d19b73fcb05f7dec4ed788bb9bf69eff1611a0e94a44f2f638c8cdc9878b1c" }, "downloads": -1, "filename": "anytemplate-0.1.3.tar.gz", "has_sig": false, "md5_digest": "36a3f3cdc0692f9fee904432e10a9689", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32002, "upload_time": "2017-11-18T01:45:17", "url": "https://files.pythonhosted.org/packages/e7/01/c9da270632932e1d3c505c58a6ba6e840c42e8f5ab0bd8dab5f2b0c1bf0f/anytemplate-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "7f2c3d2f6de79cb1d061fdef98ab247c", "sha256": "1a5acb18b63909f0098ddd4054860c370e6a8190e11bc5def7bfe80336921d50" }, "downloads": -1, "filename": "anytemplate-0.1.4.tar.gz", "has_sig": false, "md5_digest": "7f2c3d2f6de79cb1d061fdef98ab247c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32032, "upload_time": "2018-04-30T20:10:22", "url": "https://files.pythonhosted.org/packages/07/0b/f4f11d0ed065b8cc2f4f0c4d6e717a0d7383fcc9062d9a1fe423f0c831e4/anytemplate-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "61b49d5156881a53f1a8a5d01a7a4384", "sha256": "5d18e59ac94c81ee954c470e07d3bf7a3d5d07daab205a2fdcd382ece96250d6" }, "downloads": -1, "filename": "anytemplate-0.1.5.tar.gz", "has_sig": false, "md5_digest": "61b49d5156881a53f1a8a5d01a7a4384", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30350, "upload_time": "2018-08-06T22:57:57", "url": "https://files.pythonhosted.org/packages/51/22/ab7fc9198c2942e02278a5ac4a375fb934497b5ee7866fc9cebc890e3856/anytemplate-0.1.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "61b49d5156881a53f1a8a5d01a7a4384", "sha256": "5d18e59ac94c81ee954c470e07d3bf7a3d5d07daab205a2fdcd382ece96250d6" }, "downloads": -1, "filename": "anytemplate-0.1.5.tar.gz", "has_sig": false, "md5_digest": "61b49d5156881a53f1a8a5d01a7a4384", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30350, "upload_time": "2018-08-06T22:57:57", "url": "https://files.pythonhosted.org/packages/51/22/ab7fc9198c2942e02278a5ac4a375fb934497b5ee7866fc9cebc890e3856/anytemplate-0.1.5.tar.gz" } ] }