Skip to main content

A library for generating HTML and XML from Python using context managers

Project description

Choubun 超文

(this is not recommended as a real way of generating HTML!)

@contextlib.contextmanager

Choubun is an alternative approach to templating engines. Where a traditional template system has you writing your templates as separate files, Choubun allows you to mix Python control flow and HTML markup, all within Python's syntax.

To prevent injection vulnerabilities, Choubun uses MarkupSafe to escape unsafe text. markupsafe.Markup is also reexported as Markup and M.

How do I install it?

Choubun is available on PyPI. Use poetry add choubun or your favorite dependency wrangler to start using Choubun in your project.

What does code using Choubun look like?

from choubun import Node
doc = Node()
doc.raw('<!DOCTYPE html>')
with doc.node('html', lang='en'):
	with doc.node('head'):
		doc.leaf('meta', charset='utf-8')
		for k, v in dict(
			viewport="width=device-width, initial-scale=1",
			referrer='no-referrer',
		).items():
			doc.leaf('meta', name=k, content=v)
	with doc.node('body'):
		doc.text("Page body")

Project details


Download files

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

Source Distribution

choubun-1.3.1.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

choubun-1.3.1-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

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