{ "info": { "author": "F\u00e1bio Mac\u00eado Mendes", "author_email": "fabiomacedomendes@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Application Frameworks", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": ".. image:: https://readthedocs.org/projects/hyperpython/badge/?version=latest\n :target: http://hyperpython.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation Status\n.. image:: https://travis-ci.org/fabiommendes/hyperpython.svg?branch=master\n :target: https://travis-ci.org/fabiommendes/hyperpython\n :alt: Build status\n.. image:: https://codeclimate.com/github/fabiommendes/hyperpython/badges/gpa.svg\n :target: https://codeclimate.com/github/fabiommendes/hyperpython\n :alt: Code Climate\n.. image:: https://codecov.io/gh/fabiommendes/hyperpython/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/fabiommendes/hyperpython\n :alt: Code coverage\n\n\nHyperpython\n===========\n\nHyperpython is a Python interpretation of Hyperscript_. If you are not\nfamiliar with Hyperscript, think of it as a pure Javascript alternative to JSX.\nHyperpython allow us to generate, manipulate and query HTML documents using a\nsmall DSL embedded in Python. Just like Hyperscript, the default entry point is\nthe ``hyperpython.h`` function:\n\n>>> from hyperpython import h\n>>> elem = h('p', {'class': 'hello'}, ['Hello World!'])\n\n.. _Hyperscript: https://github.com/hyperhype/hyperscript\n\nThis can be converted to HTML by calling ``str()`` on the element:\n\n>>> print(elem)\n

Hello World!

\n\nIt accepts Hyperscript's ``h(tag, attributes, list_of_children)`` signature,\nbut we encourage to use more idiomatic Python version that uses keyword arguments to\nrepresent attributes instead of a dictionary. If the list of children contains a\nsingle element, we can also omit the brackets:\n\n>>> h('p', 'Hello World!', class_='hello') == elem\nTrue\n\nNotice in the snippet above that we had to escape the \"class\" attribute because\nit is a reserved word in Python. Hyperpython maps Python keyword arguments by replacing\nunderscores with dashes and by escaping Python reserved words such as \"class\", \"for\"\n\"from\", etc with a trailing underscore.\n\nElements can be be more conveniently created with standalone functions representing\nspecific tags:\n\n>>> print(p('Hello World!', class_='hello'))\n

Hello World!

\n\nIn Python, keyword arguments cannot appear after positional arguments. This means\nthat attributes are placed *after* the list of children, which isn't natural to\nrepresent HTML. For simple elements like the ones above, it does not hinders\nlegibility, but for larger structures it can be a real issue. Hyperpython\nprovides two alternatives. The first uses the index notation:\n\n\n>>> from hyperpython import div, p, h1\n>>> fragment = \\\n... div(class_=\"alert-box\")[\n... h1('Hello Python'),\n... p('Now you can write HTML in Python!'),\n... ]\n\nThe second alternative is to use the \"children\" pseudo-attribute. This is the\napproach taken by some Javascript libraries such as React:\n\n>>> fragment = \\\n... div(class_=\"alert-box\",\n... children = [\n... h1('Hello Python'),\n... p('Now you can write HTML in Python!'),\n... ])\n\n\nHyperpython returns a DOM-like structure which we can introspect, query and\nmodify later. The main usage, of course, is to render strings of HTML source\ncode. We expect that the main use of Hyperpython will be to complement (or even replace)\nthe templating language in a Python web application. That said, Hyperpython generates a\nvery compact HTML that is efficient to generate and transmit over the wire. To\nget a more human-friendly output (and keep your sanity while debugging), use\nthe .pretty() method:\n\n>>> print(fragment.pretty())\n
\n

Hello Python

\n

Now you can write HTML in Python!

\n
\n\n\n\nReplacing templates\n===================\n\nThe goal of ``hyperpython`` is to replace a lot of work that would be traditionally\ndone with a template engine such as Jinja2 by Python code that generates HTML\nfragments. Templating languages are obviously more expressive than pure Python for\nstring interpolation, and are a perfect match for ad hoc documents. For large systems,\nthey offer little in terms of architecture, organization and code reuse.\n\nA recent trend in Javascript is to promote direct creation of DOM or\nvirtual DOM nodes sidestepping the whole business of rendering intermediate\nHTML strings. React was probably the library that better popularized this idea. As they\nnicely put, \"Templates separate technologies, not concerns\". There is no point\non choosing a deliberately underpowered programming language that integrates\npoorly with your data sources just to output structured documents in a flat string\nrepresentation.\n\nThe same lesson can be applied to Python on the server side. With Hyperpython,\nwe can generate HTML directly in Python. Hyperpython plays nicely with\nexisting templating systems, but it makes easy to migrate parts of your rendering\nsub-system to Python.\n\nFor those afraid of putting too much logic on templates, we recognize that\nHyperpython doesn't prevent anyone from shooting themselves on the foot, but neither\ndo any minimally powerful templating engine. It always requires some discipline to\nkeep business logic separated from view logic. Our advice is to break code in\nsmall pieces and compose those pieces in simple and predictable ways.\nIncidentally, this is a good advice for any piece of code ;).\n\n\nCan it be used on Django? Flask? Etc?\n=====================================\n\nOf course! Hyperpython is completely framework agnostic. We have a few optional\nintegrations with Django, but it does not prevent Hyperpython of being used\nin other frameworks or without any framework at all. It implements the __html__\ninterface which is recognized by most templating engines in Python. That way, it\nis possible to pass Hyperpython fragments to existing templates in Django, Jinja2\nand others.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/fabiommendes/hyperpython/", "keywords": "web, html, templating", "license": "BSD License (BSD)", "maintainer": "", "maintainer_email": "", "name": "hyperpython", "package_url": "https://pypi.org/project/hyperpython/", "platform": "", "project_url": "https://pypi.org/project/hyperpython/", "project_urls": { "Homepage": "https://github.com/fabiommendes/hyperpython/" }, "release_url": "https://pypi.org/project/hyperpython/1.1.1/", "requires_dist": null, "requires_python": "", "summary": "Create HTML data structures using Python functions.", "version": "1.1.1" }, "last_serial": 5357814, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "76d38d5c4e12ae62e9c940c3ad075268", "sha256": "d72ed3b31875d491a2b5b5b78e77340b2e7661b8b69439b2d0176c10e0c1d393" }, "downloads": -1, "filename": "hyperpython-0.1.0.tar.gz", "has_sig": false, "md5_digest": "76d38d5c4e12ae62e9c940c3ad075268", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19120, "upload_time": "2018-05-28T18:06:33", "url": "https://files.pythonhosted.org/packages/59/c1/7863e18ea5680d8ea952359d08e01f05e238fd60c2b64f460d439d820ad5/hyperpython-0.1.0.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "a3f0a7161eb769616557482c6d41e883", "sha256": "796c5c1a0cb29fc7d95e6e378f89531b7232ce5271fc545b9402a47514de5360" }, "downloads": -1, "filename": "hyperpython-0.1.3.tar.gz", "has_sig": false, "md5_digest": "a3f0a7161eb769616557482c6d41e883", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19171, "upload_time": "2018-05-29T02:43:20", "url": "https://files.pythonhosted.org/packages/1b/d5/88155e7ec0bd3eba755df83cae88c1e6c418d9d39dbbec466f484999f5d0/hyperpython-0.1.3.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "9a5d7d0ef3947fcf030556560bb0a930", "sha256": "a4af743e3f187e30866c1743890979a33f471a35905405b38c91fbddf6accd07" }, "downloads": -1, "filename": "hyperpython-0.2.0.tar.gz", "has_sig": false, "md5_digest": "9a5d7d0ef3947fcf030556560bb0a930", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32880, "upload_time": "2018-08-16T13:00:44", "url": "https://files.pythonhosted.org/packages/eb/d7/4b1ac2123b709ff3033d7c901c1a1a2cc82c97076d80e721b6f9674ec5da/hyperpython-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "d73a72e2c2995e5c30128d816ae62959", "sha256": "9756f6c968ac48f08ab7014a9d68defce26524ed8e7104d0ef6e7eb4f80a54ac" }, "downloads": -1, "filename": "hyperpython-0.3.0.tar.gz", "has_sig": false, "md5_digest": "d73a72e2c2995e5c30128d816ae62959", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 35857, "upload_time": "2018-09-06T14:50:38", "url": "https://files.pythonhosted.org/packages/b2/e1/f26dc8053023bbe7b34d4c8fe04c447009743fb98504eb260f04c6c1f329/hyperpython-0.3.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "c47fc689e2dcdbd65e4075389b50b9c1", "sha256": "d7a38b8b50e82e89532a5067e0302533c6a88f9da36953074e3acc6ff7177b39" }, "downloads": -1, "filename": "hyperpython-1.0.1.tar.gz", "has_sig": false, "md5_digest": "c47fc689e2dcdbd65e4075389b50b9c1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 34332, "upload_time": "2018-09-08T22:27:52", "url": "https://files.pythonhosted.org/packages/17/33/3c0b175dafed8c8213b5ee6521dbd5f3f4f367095bc1139e7afed795bb80/hyperpython-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "9ef7c1e315d797a59d99ced236e90ea1", "sha256": "c0b0ba6853f0bb9f9dafeeb1c5611b30de26c31164afae639f11ddeaafd1b0fb" }, "downloads": -1, "filename": "hyperpython-1.0.2.tar.gz", "has_sig": false, "md5_digest": "9ef7c1e315d797a59d99ced236e90ea1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 39621, "upload_time": "2019-02-28T19:31:28", "url": "https://files.pythonhosted.org/packages/d0/c6/85fda786f92acb10f8aaeb4bfb896ba8e0e72f9acd62fe255ce9481d92c1/hyperpython-1.0.2.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "c9cee52aa65447d09c4fda7578b9451c", "sha256": "3e098dd2e14055ffc40fabeb6a20c0b8e4489570dfc7dcba4e79e50b5e678af1" }, "downloads": -1, "filename": "hyperpython-1.1.0.tar.gz", "has_sig": false, "md5_digest": "c9cee52aa65447d09c4fda7578b9451c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 38953, "upload_time": "2019-04-08T01:21:57", "url": "https://files.pythonhosted.org/packages/eb/19/8681b840c099be45779644e5329cf68f73b5570c74a154e496512df7c222/hyperpython-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "587df11f1a616172706b602756fedf13", "sha256": "5f2a3f6eed01ee1b942f41f4e111cfb8216ab6abbc52a1892dece52d7cd3a051" }, "downloads": -1, "filename": "hyperpython-1.1.1.tar.gz", "has_sig": false, "md5_digest": "587df11f1a616172706b602756fedf13", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 38963, "upload_time": "2019-06-04T14:22:53", "url": "https://files.pythonhosted.org/packages/9f/27/2187d9895776d9f8bf4b1974d2a3a1be3d7db589a7d19bf765c7bb993fe8/hyperpython-1.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "587df11f1a616172706b602756fedf13", "sha256": "5f2a3f6eed01ee1b942f41f4e111cfb8216ab6abbc52a1892dece52d7cd3a051" }, "downloads": -1, "filename": "hyperpython-1.1.1.tar.gz", "has_sig": false, "md5_digest": "587df11f1a616172706b602756fedf13", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 38963, "upload_time": "2019-06-04T14:22:53", "url": "https://files.pythonhosted.org/packages/9f/27/2187d9895776d9f8bf4b1974d2a3a1be3d7db589a7d19bf765c7bb993fe8/hyperpython-1.1.1.tar.gz" } ] }