{ "info": { "author": "Jouni K. Sepp\u00e4nen", "author_email": "jks@iki.fi", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Text Processing :: Markup :: HTML" ], "description": "htexpr\n======\n\nhtexpr compiles an html-like syntax into Python expressions. It is\ninspired by [JSX]() and intended to complement the excellent [dash]()\npackage, which allows you to write single-page React apps in\nPython. Here is an example, a simple ASCII table:\n\n```python\napp.layout = htexpr.compile(\"\"\"\n
\n \n \n\t[\n\t (\n\t \n\t \n\t \n\t )\n\t for line, char in enumerate(chr(i) for i in range(32, 128))\n\t]\n
charnamecategory
{ char }{ unicodedata.name(char, '???') }{ unicodedata.category(char) }
\n
\n\"\"\").run()\n```\n\nCompare this to a similar implementation using function calls:\n\n```python\napp.layout = html.Div([\n html.Table(style={\"margin\": \"0 auto\"}, children=[\n html.Tr(html.Th(\"char\"), html.Th(\"name\"), html.Th(\"category\"))\n ] + [\n html.Tr(\n [html.Td(char),\n html.Td(unicodedata.name(char, '???')),\n html.Td(unicodedata.category(char))],\n style={'background-color': '#eee' if line % 2 else '#ccc'}\n )\n for line, char in enumerate(chr(i) for i in range(32, 128))\n ])\n])\n```\n\nThe latter has a small mistake that is in my opinion easy to make by\naccident, but is completely avoided in the htexpr syntax.\n\nA somewhat more complicated [Unicode table]() example\ndemonstrates the syntax further.\n\n[JSX]: https://reactjs.org/docs/introducing-jsx.html\n[dash]: https://dash.plot.ly\n[Unicode table]: https://github.com/jkseppan/htexpr/blob/master/examples/unicode_table.py\n\n\nAPI\n---\n\nUse the following imports:\n\n```python\nimport dash_core_components as dcc\nimport dash_html_components as html\nimport dash_table\n```\n\nThen call `htexpr.compile` with an expression, and elements such as\n\n
\n\nwill be transformed into Python function calls:\n\n html.Div(className=\"c\", children=[\n\t dcc.Input(id=\"i\", type=\"number\", children=[])\n\t])\n\n`html` tags can be written in any case, `dcc` tags must be in the\nexact same case as the function name. The `class` attribute becomes\n`className` and some other lower-case attributes such as `rowspan` are\ntransformed into camel-case (`rowSpan`). The `map_tag` and\n`map_attribute` keyword arguments override these defaults.\n\nThe expression must be evaluated with its `eval` method to be\neffective, with suitable bindings for all variables referenced\n(including imports of `dash_html_components as html`, etc.) A\nconvenience method that captures the globals and locals in the calling\nenvironment is `run`.\n\n\nSyntax\n------\n\nAll tags must be closed: `
...
` or `
`. Literal\nattribute values must appear in quotes and Python values in brackets\n`[]` or braces `{}`. Text inside elements can also include Python\nexpressions in brackets or braces.\n\nBraces may contain any Python expression, but the braces are not\nincluded in the expression; however, if there is a colon at the top\nlevel of an expression appearing as an attribute value, the braces are\nincluded. This allows specifying dictionary-valued attributes with a\nsingle level of braces at the cost of misparsing type annotations.\nBrackets are included in the expression, so they always specify a list\nvalue. A bracketed expression is spliced into the list of children of\nthe parent element, so\n\n \n\nresults in a single flat list of eleven elements as the children of\nthe `ul` element. This splicing is triggered solely by the bracket\nsyntax, so a list-valued expression inside braces does not get the\nsplicing treatment.\n\nThe htexpr syntax can appear nested inside Python expressions, but the\nsubexpression must be surrounded in parentheses: `(
  • ...
  • )`.\n\n\nDevelopment status\n------------------\n\nI wrote this to help me with a particular project where I kept making\nthe kind of bracketing mistakes exhibited above. The code works for\nthat purpose, but there are likely to be corner cases I haven't\nconsidered.\n\nThe Python grammar used here is quite simplistic: it recognizes\nstrings and variously parenthesized expressions. By understanding more\nPython it would probably be possible to disambiguate between\ncomparison operators and tags, and thus drop the requirement to\nenclose nested expressions in parentheses.\n\nThe error messages are not always helpful, and in particular the code\nobjects don't yet have reliable line-number data.\n\nSince the library creates code objects using the `ast` module, it is\nlikely quite dependent on the CPython implementation. I haven't looked\nhow much work it would be to work with the other Python\nimplementations.\n\n\n\n", "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/jkseppan/htexpr", "keywords": "", "license": "MIT license", "maintainer": "", "maintainer_email": "", "name": "htexpr", "package_url": "https://pypi.org/project/htexpr/", "platform": "", "project_url": "https://pypi.org/project/htexpr/", "project_urls": { "Homepage": "https://github.com/jkseppan/htexpr" }, "release_url": "https://pypi.org/project/htexpr/0.0.3/", "requires_dist": [ "parsimonious (~=0.8.1)", "toolz (~=0.9.0)", "pytest ; extra == 'dev'", "pytest-cov ; extra == 'dev'", "dash (<1.1,>=0.39) ; extra == 'examples'", "dash-core-components (<1.1,>=0.44) ; extra == 'examples'", "dash-html-components (<1.1,>=0.14) ; extra == 'examples'", "dash-renderer (<1.1,>=0.20) ; extra == 'examples'", "dash-table (<4.1,>=3.6) ; extra == 'examples'" ], "requires_python": ">=3.6", "summary": "htexpr compiles an html string into a Python expression", "version": "0.0.3" }, "last_serial": 5429319, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "eaf817195f2089f9e66e42eca7730847", "sha256": "e88346c51a4fd854f58c153d0562d2e5cb499a1cf55c099be9ac0699bafc4eba" }, "downloads": -1, "filename": "htexpr-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "eaf817195f2089f9e66e42eca7730847", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6", "size": 9104, "upload_time": "2019-03-31T15:55:33", "url": "https://files.pythonhosted.org/packages/dc/ad/85389ef76b2ef6a884f2c16dded0c9874bba33f65aad773b0c412da14da9/htexpr-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "90243fd385713cecc6d2dd218e5661a9", "sha256": "124aec6cc5c61250e20281e82e1a43d067a91c6dcbec771211335e61b0961c6f" }, "downloads": -1, "filename": "htexpr-0.0.1.tar.gz", "has_sig": false, "md5_digest": "90243fd385713cecc6d2dd218e5661a9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 8355, "upload_time": "2019-03-31T15:55:35", "url": "https://files.pythonhosted.org/packages/c7/35/f0fd082de740b084bc305f42b7fc3b1c84c853ced222f40013be4e328526/htexpr-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "82f718ade52e60d0388239396ae4bf26", "sha256": "b3da2e2c3bc5aaf3ac9d4c3a9b2a4dccb40b03bb989fbfa23e6cd80d4e0fc65e" }, "downloads": -1, "filename": "htexpr-0.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "82f718ade52e60d0388239396ae4bf26", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6", "size": 9715, "upload_time": "2019-04-14T16:06:31", "url": "https://files.pythonhosted.org/packages/6a/6b/be0be4e3cf2827c801d6cf28131b2df19f330b776e8fd1e080c50dc4ce48/htexpr-0.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b83f48ee9d4c5965f4a45e0806457967", "sha256": "3ecba00c4561de6d17e5bd1e07872848749fe3b0e54d1ef83e421916cc42ff63" }, "downloads": -1, "filename": "htexpr-0.0.2.tar.gz", "has_sig": false, "md5_digest": "b83f48ee9d4c5965f4a45e0806457967", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 9658, "upload_time": "2019-04-14T16:06:33", "url": "https://files.pythonhosted.org/packages/11/aa/b6239df0ce684ca0d948d5015f91fb2b8470377585c19818ce1666421695/htexpr-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "bc49d85be7ad6ccd7fb609dc8d743400", "sha256": "dc9fee4a69397d531cc45fff139193e8ee011ca16d4e87934ee9021ad1c7df5c" }, "downloads": -1, "filename": "htexpr-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "bc49d85be7ad6ccd7fb609dc8d743400", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6", "size": 9735, "upload_time": "2019-06-21T06:40:14", "url": "https://files.pythonhosted.org/packages/20/70/cb94c65d73871868b8d5fe36c54951de0be56d0e8b70842a0c918765911d/htexpr-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ef48ea76a3692f8d837d13179d520440", "sha256": "f296987ff104054839910d77d5f37a16d23552ece7dcbd85d4cb9cdb8d73af5e" }, "downloads": -1, "filename": "htexpr-0.0.3.tar.gz", "has_sig": false, "md5_digest": "ef48ea76a3692f8d837d13179d520440", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 9700, "upload_time": "2019-06-21T06:40:16", "url": "https://files.pythonhosted.org/packages/e0/c8/8ae79210c41eaff180d019ab4c87395c4bc18f13ac6d954d21239fe28b6c/htexpr-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bc49d85be7ad6ccd7fb609dc8d743400", "sha256": "dc9fee4a69397d531cc45fff139193e8ee011ca16d4e87934ee9021ad1c7df5c" }, "downloads": -1, "filename": "htexpr-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "bc49d85be7ad6ccd7fb609dc8d743400", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6", "size": 9735, "upload_time": "2019-06-21T06:40:14", "url": "https://files.pythonhosted.org/packages/20/70/cb94c65d73871868b8d5fe36c54951de0be56d0e8b70842a0c918765911d/htexpr-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ef48ea76a3692f8d837d13179d520440", "sha256": "f296987ff104054839910d77d5f37a16d23552ece7dcbd85d4cb9cdb8d73af5e" }, "downloads": -1, "filename": "htexpr-0.0.3.tar.gz", "has_sig": false, "md5_digest": "ef48ea76a3692f8d837d13179d520440", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 9700, "upload_time": "2019-06-21T06:40:16", "url": "https://files.pythonhosted.org/packages/e0/c8/8ae79210c41eaff180d019ab4c87395c4bc18f13ac6d954d21239fe28b6c/htexpr-0.0.3.tar.gz" } ] }