Skip to main content

piccup

PyPI PyPI - Python Version

[EXPERIMENTAL]

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

Installation

pip install piccup

Usage

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

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

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': 'http://example.com'}, 
            'Click Me'])
'<a href="http://example.com">Click Me</a>'

Nested HTML nodes are passed to contents.

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

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': 'http://example.com/{}'.format(e)}, e]]
             for e in ['item1', 'item2', 'item3']]])
'<ul><li class="link-item"><a href="http://example.com/item1">item1</a></li><li class="link-item"><a href="http://example.com/item2">item2</a></li><li class="link-item"><a href="http://example.com/item3">item3</a></li></ul>'

Metadata

Release files for piccup 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for piccup 0.1.1
File Size Uploaded
piccup-0.1.1.tar.gz 2.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for piccup 0.1.1
File Interpreter ABI Platform
piccup-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 5.6 kB

Release files / piccup-0.1.1.tar.gz

Download URL piccup-0.1.1.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a0f194a73de8edc0aba235891bde726c954886f8439a6c33f1969ceac3c01e88
BLAKE2b-256 checksum
How to use checksums
890e065b96c3c2dfda5d804be23d122cffc36884e947c7324880f10f1e215c5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

Release files / piccup-0.1.1-py3-none-any.whl

Download URL piccup-0.1.1-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64ab6126ac8e16a504b7f20d5f728ef8b253484109ac069570c8cdafe92a698e
BLAKE2b-256 checksum
How to use checksums
38c22a41b64a47920aa3e228063eb4f69c6922724237696c98a7a4777d560264
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page