Skip to main content

Control the web with Python

Project description

Hyperscript Markup Language Python Extension

An extension to the Python language with an f-string-like template syntax for writing HTMl inspired by pyxl:

# coding=html

def html(tag, props, children):
    return (tag, props, children)

size = "30px"
text = "Hello!"

model = html"""
<div height={size} width={size} >
    <p>{text}</p>
</div>
"""

HTML Template Usage

Every file that uses the HTML template syntax must:

  1. Have an html encoding indicator as its first or second line.
  2. Define a callable html(tag, props, children) in the module.

So your files should all start a bit like this:

# coding=html
def html(tag, props, children): ...

If you haven't permanently installed the language extension you'll need to import modules with HTML Template Syntax, you'll need to make sure idom has been imported at your application's entry point to register the language extension before importing your module:

import htm_pyx
import my_project

Where my_project.py would have the following contents:

# coding=html

def html(tag, props, children):
    ...

cool_stuff = html"<div>...</div>"

HTML Template Syntax Installation

If you want to more permanently install the language extension you can run the console command:

htm-pyx register

Which can be undone (if desired) later:

htm-pyx deregister

This is optional, because you can always import htm_pyx at the root of your application to enable the extension. After this initial import all the follow with coding=html will be appropriately transpiled.

Additional Support For HTML Template Syntax

You won't be able to use the HTML template syntax directly in Python's default REPL, but it will work out of the box with:

  1. Jupyter
  2. IPython

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

htm_pyx-0.1.0.dev0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file htm_pyx-0.1.0.dev0-py3-none-any.whl.

File metadata

  • Download URL: htm_pyx-0.1.0.dev0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.9

File hashes

Hashes for htm_pyx-0.1.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 d662634aa1729da74093067369d905b9bde7bf1b881f6ecd92ceb1f7a315a978
MD5 f57acfd0f58bdf4c34ac537d72daa7e3
BLAKE2b-256 23e3949d0d4ddee4ead94857e365a93e63be4673895706383bfed0991775e9a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page