Skip to main content

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(
        head(
          title('Chapter 1: Greeting')),
        body(
          h1('Chapter 1: Greeting'),
          p('Hello, world!')))

from xml.etree import ElementTree as et
et.dump(doc)

Results in this: (added some whitespace for formatting)

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

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: http://stackoverflow.com/questions/2447353/getattr-on-a-module

Metadata

Release files for magictree 1.0.0

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

Source distribution (sdist)

Source distribution for magictree 1.0.0
File Size Uploaded Provenance Actions
magictree-1.0.0.zip 3.8 kB Without provenance Details for magictree-1.0.0.zip

Built distribution (wheel)

Table of built distributions (wheels) for magictree 1.0.0
File Interpreter ABI Platform Actions
magictree-1.0.0.win32.exe Details for magictree-1.0.0.win32.exe

Total release size: 69.0 kB

Release files / magictree-1.0.0.zip

Download URL magictree-1.0.0.zip
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4b1c5817378347f0b94b78ac138e6ae86342895f9f45e69afe9cd1b13f2877d6
BLAKE2b-256 checksum
How to use checksums
10cfb3d48d02d7e673fb4ff28ca4c96743ac710dc70180943995b5d3420efbc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / magictree-1.0.0.win32.exe

Download URL magictree-1.0.0.win32.exe
Size 65.2 kB
Tags Source
SHA-256 checksum
How to use checksums
16a57095f24c846aa2a30cb1bf64aa93224e4b9438079a218e6c663f03bf555d
BLAKE2b-256 checksum
How to use checksums
a2ba3580c3dccff3323b2db4a9dfc67da810c9fd5273ef2a3902827b7ffc19df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for magictree 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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