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} >

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 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.

Built Distribution

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

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page