{"id":5309,"library":"markuppy","title":"MarkupPy: An HTML/XML Generator","description":"MarkupPy is a Python module designed to simplify the generation of HTML/XML from Python code in an intuitive, lightweight, and Pythonic manner. It supports both Python 2 and 3 environments, offering a straightforward approach to creating markup. The library maintains an active status with intermittent releases, with version 1.18 being published in March 2025.","status":"active","version":"1.18","language":"en","source_language":"en","source_url":"https://github.com/tylerbakke/MarkupPy","tags":["html","xml","generator","markup","html-generator","xml-generator"],"install":[{"cmd":"pip install MarkupPy","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The primary class to interact with is 'markup.page()', which resides within the 'MarkupPy' package, not a direct 'markuppy' module.","wrong":"import markuppy.markup","symbol":"markup","correct":"from MarkupPy import markup"}],"quickstart":{"code":"from MarkupPy import markup\n\n# Create an HTML page\npage = markup.page()\npage.init(title=\"My Title\", lang=\"en\")\npage.h1(\"Welcome!\")\npage.p(\"Hello, World!\")\npage.p.close()\npage.a(\"Visit GitHub\", href=\"https://github.com/tylerbakke/MarkupPy\")\nprint(page)","lang":"python","description":"This example demonstrates how to initialize an HTML page, add a title, paragraphs, and a link. Elements are added as method calls on the page object. Closing tags are explicitly called for block elements like 'p'."},"warnings":[{"fix":"Align usage with the library's intended lightweight purpose; consider other tools for complex production scenarios.","message":"MarkupPy is a lightweight generator and not intended as a full-blown web framework, templating engine, or XML parser. For robust production environments or complex needs, alternatives like ElementTree are suggested.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to MarkupPy 1.17+ and use `page.add_raw('your raw content\\n')` for pre-formatted text.","message":"When adding content to `<pre>` tags, versions prior to 1.17 might insert extra newlines between additions. Use the `add_raw()` method (available from v1.17+) to preserve exact formatting without unwanted newlines.","severity":"gotcha","affected_versions":"< 1.17"},{"fix":"For older versions, manual methods (e.g., adding `<style>` or `<script>` tags directly with `page.add()` or similar) would be required, or upgrade to 1.16+.","message":"Direct embedding of inline CSS and JavaScript content via the `init()` method's `style_content` and `script_content` arguments is only supported in version 1.16 and newer.","severity":"gotcha","affected_versions":"< 1.16"},{"fix":"Avoid using 'add' as a custom element name; choose a different, non-conflicting name.","message":"Due to the existence of the `page.add()` method for inserting raw text, 'add' cannot be used as an HTML/XML element name (e.g., `page.add(...)` for creating an `<add>` tag) as it would clash with the method.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Migrate your project to Python 3. MarkupPy's functionality is fully supported in Python 3.","message":"While MarkupPy states compatibility with Python 2 and 3, Python 2 has reached End-of-Life. It is strongly recommended to use MarkupPy with Python 3 for modern development and security.","severity":"gotcha","affected_versions":"All versions (in context of Python 2 usage)"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}