Skip to main content

A basic internal XML-generating DSL in Python 3.

Project description

PyMarkup

Build Status Documentation Status

An internal DSL for generating XML-like markup in Python 3.7

Installation

Installation is as simple as pip install pymarkup. To develop, download the source, and run pip install -e .[dev]

Usage

A basic example:

from pymarkup import MarkupBuilder

t = MarkupBuilder()

with t:  # <html> tag
    with t.h1(id='HelloWorld'):  # Attribute access creates new element, and call adds attributes to tag
        t + 'Hello World!'  # Add child text to tag

    with t.a(href="github.com"):
        t + t.img(src="i_am_an_image.png")  # Self-closing tags are added with +
    with t.ul:
        for x in range(2):
            with t.li:
                t + x

repr(t) gives:

<html>
<h1 id="HelloWorld">
Hello World!
</h1>
<a href="github.com"><img src="i_am_an_image.png"/>
</a>
<ul>
<li>
0
</li>
<li>
1
</li>
</html>

For more information, see the docs

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

pymarkup-0.0.1.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

pymarkup-0.0.1-py3-none-any.whl (4.1 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