{ "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'))\nHello 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())\nNow you can write HTML in Python!
\n