Skip to main content

Render HTML from Python using plain data structures, inspired by Clojure's Hiccup

Project description


PyPI PyPI - Python Version


Render HTML from Python using plain data structures, inspired by Clojure's Hiccup.


pip install piccup


piccup allows you to write HTML using plain Python data structures.

>>> p.html(['p', 'hello'])

Each HTML node is defined using [element, attributes, contents] triple. element string is required, attributes dict and contents object are optional.

>>> p.html(['a',
            {'href': ''}, 
            'Click Me'])
'<a href="">Click Me</a>'

Nested HTML nodes are passed to contents.

>>> p.html(['ul', 
            [['li', 'first'], 
             ['li', 'second'], 
             ['li', 'third']]])

piccup uses simple data structures, so you can write normal Python code instead of a foreign templating language.

>>> p.html(['ul',
            [['li', {'class': 'link-item'},
              ['a', {'href': '{}'.format(e)}, e]]
             for e in ['item1', 'item2', 'item3']]])
'<ul><li class="link-item"><a href="">item1</a></li><li class="link-item"><a href="">item2</a></li><li class="link-item"><a href="">item3</a></li></ul>'

Project details

Download files

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

Files for piccup, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size piccup-0.1.1-py3-none-any.whl (3.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size piccup-0.1.1.tar.gz (2.2 kB) File type Source Python version None Upload date Hashes View

Supported by

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