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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file choubun-1.3.1.tar.gz.

File metadata

  • Download URL: choubun-1.3.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Linux/5.4.109+

File hashes

Hashes for choubun-1.3.1.tar.gz
Algorithm Hash digest
SHA256 99aa89ea64dbb8d2794b8971a762769c8b29e129522d3c945e010396c447726d
MD5 8d38579fae4dc6ab409277edfabda2b2
BLAKE2b-256 bd7a87ee25aab1fceecb314c3c1cb06e34c72b7c01847630c9c7a87cac2b19e3

See more details on using hashes here.

File details

Details for the file choubun-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: choubun-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Linux/5.4.109+

File hashes

Hashes for choubun-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64da53e09e2b7137c41399250b83faf14f71578898e6da7446653bf8831f4832
MD5 70f8e036e226ecbdf2c36211aafe7b25
BLAKE2b-256 f4a6a74149878d89dd0dbcaa29bae18f77256f528d85a1efc2f91d34d30db602

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page