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!

Easily create ElementTree with automatic Element factories

Project Description

Creating tree structures like those used for HTML and XML should be dead easy. The xml.etree.ElementTree library goes quite far in creating a simple to use library for creating and modifying such structures. I’d like to go a step further, building on top of ElementTree:

from magictree import html, head, title, body, h1, p
doc = html(
          title('Chapter 1: Greeting')),
          h1('Chapter 1: Greeting'),
          p('Hello, world!')))

from xml.etree import ElementTree as et

Results in this: (added some whitespace for formatting)

    <title>Chapter 1: Greeting</title>
    <h1>Chapter 1: Greeting</h1>
    <p>Hello, world!</p>

This works by replacing this module with a wrapper object in sys.modules that creates factory functions for elements based on their name.

I used this page as a basis for the hack:

Release History

This version
History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(65.2 kB) Copy SHA256 Hash SHA256
Windows Installer any Jul 6, 2011
(3.8 kB) Copy SHA256 Hash SHA256
Source None Jul 6, 2011

Supported By

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 Google Google Cloud Servers