--- id: htpy version: "26.5.1" license: MIT license_treatment: permissive maintenance: active --- # htpy — htpy - HTML in Python License: permissive · Maintenance: active · Downloads: 207.0K/mo ## What it is and what it does htpy is a Python library for generating HTML without templates. Instead of writing HTML strings or using a template language, you define HTML elements and structure using Python syntax—nesting child elements with brackets, passing attributes as function arguments, and composing components as regular Python functions or variables. It relies on markupsafe for safe HTML escaping and typing_extensions for type hints. The library is designed to work with any Python web framework (Django, Flask, etc.) and supports async rendering for ASGI frameworks. Because HTML is just Python code, you can use static type checking with mypy or pyright, debug with standard Python debuggers, and leverage Python's full feature set—functions, classes, comprehensions, conditionals—to organize and reuse components. It was created to avoid the friction of template languages while maintaining the familiarity of Python development. Use it for: - Build server-rendered HTML components for htmx-driven interfaces without switching to a template language. - Generate complex, nested HTML structures in Flask or Django views using Python functions and comprehensions. - Type-check your HTML generation code with mypy or pyright to catch structural errors early. - Render HTML asynchronously in FastAPI or Starlette applications with full async/await support. - Create reusable HTML components as Python functions or classes that compose like regular code. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. htpy lets you write HTML directly in Python using bracket syntax and Python expressions, generating valid HTML without a template language. Yes. htpy is actively maintained, has low install friction, carries no known vulnerabilities, and uses a permissive MIT license. It is well-suited if you prefer writing HTML in Python over templates and want static typing and debugging support. Not necessary if you are already satisfied with your templating approach or need Python versions below 3.10. ## Install pip install htpy uv add htpy poetry add htpy ## Installing htpy Before you install: Low friction: pure Python wheel with only two lightweight runtime dependencies (markupsafe, typing_extensions). Active maintenance with recent release 84 days ago and 477 repository stars. License in practice: MIT license permits unrestricted use, modification, and distribution in both open and closed projects with minimal restrictions. Quickstart: pip install htpy from htpy import html, head, body, title, h1, ul, li result = html[ head[title["Example"]], body[h1["Hello"], ul[(li[item] for item in ["one", "two"])]] ] Requires Python 3.10 or later. Verify before relying: - Whether the package's async support integrates seamlessly with specific ASGI frameworks beyond Starlette and FastAPI. - Performance characteristics when rendering large or deeply nested HTML structures. - Compatibility with type checkers other than mypy and pyright. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 207.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags HTML generation in Python, write HTML with Python code, template-free HTML builder, Python HTML DSL, server-side HTML rendering, htmx-friendly HTML generation, async HTML rendering, html-generation, type-safe, async-ready [View on SkillFed](https://skillfed.io/packages/htpy) · [View on PyPI](https://pypi.org/project/htpy/)