Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Library for representing HTML in Python

Project Description

pyhiccup 0.1

Python version of clojure hiccup Original concept by James Reeves

Pyhiccup is a library for representing HTML in Python. It uses list or tuple to represent elements, and dict to represent an element’s attributes. Supported Python versions are:

  • 2.6
  • 2.7
  • 3.3
  • 3.4


pip install pyhiccup


Here is a basic example of pyhiccup syntax.

>>> from pyhiccup.core import html
>>> data = [
>>>    ['div',
>>>     {'class': 'a-class', 'data-y': '23'},
>>>     ['span', 'my-text',
>>>      ['ul', [['li', x] for x in ['café', 'milk', 'sugar']]]]]
>>> ]
>>> html(data)
u'<!DOCTYPE html><html lang="en" xml:lang="en" dir="rtl"><div data-y="23" class="a-class"><span>my-text<ul><li>café<li>milk<li>sugar</ul></span></div></html>'

The html function supports different default type html5, html4, xhtml-strict, xhtml-transitional

>>> from pyhiccup.core import html
>>> data = []
>>> html(data, etype='xhtml-strict')
>>> u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ""><html lang="en" xml:lang="en" dir="rtl" xmlns=""/>'

You can pass arbitrary keyword arguments to the html they will be transformed into html tag attributes

>>> from pyhiccup.core import html
>>> data = []
>>> html(data, etype='xhtml-strict', an-attr='foo')
u'... <html an-attr="foo" lang="en" xml:lang="en" dir="rtl" xmlns=""/>'

Pyhiccup also provides a function to represent XML. Arbitrary keyword arguments are also supported.

>>> from pyhiccup.core import xml
>>> data = ['form-desc',
>>>         ['field', {'name': 'a_name'}],
>>>         ['field', {'name': 'a_other_name'}]]
>>> conv = xml(data, 'foo-ns', bar='an_attr')
u'<?xml version="1.0" encoding="UTF-8"?><foo-ns bar="an_attr"><form-desc><field name="a_name"/><field name="a_other_name"/></form-desc></foo-ns>'

Some time you want to be able to create XML/HTML chunk out of a namespace. The core.convert is made for this.

>>> from pyhiccup.core import convert
>>> from pyhiccup.element import link_to
>>> convert(link_to('', 'pyhiccup'))
u'<a href="">pyhiccup</a>'

Helpers are available on the elements namespace. The will help you to add hyperlink, images etc.

>>> from pyhiccup.element import link_to
>>> link_to(u'', u'pyhiccup' )
[u'a', {u'href': u''}, u'pyhiccup']
Release History

Release History

This version
History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pyhiccup-0.1.tar.gz (20.4 kB) Copy SHA256 Checksum SHA256 Source Nov 2, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting