Name | htpy JSON |
Version |
24.10.1
JSON |
| download |
home_page | None |
Summary | htpy - HTML in Python |
upload_time | 2024-10-24 10:00:05 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<p align="center">
<img src="https://htpy.dev/assets/htpy.webp" width="300">
</p>
# htpy - HTML in Python
htpy is a library that makes writing HTML in plain Python fun and efficient,
without a template language.
**Define HTML in Python:**
```python
from htpy import body, h1, head, html, li, title, ul
menu = ["egg+bacon", "bacon+spam", "eggs+spam"]
print(
html[
head[title["Today's menu"]],
body[
h1["Menu"],
ul(".menu")[(li[item] for item in menu)],
],
]
)
```
**And Get HTML:**
```html
<!DOCTYPE html>
<html>
<head>
<title>Today's menu</title>
</head>
<body>
<h1>Menu</h1>
<ul class="menu">
<li>egg+bacon</li>
<li>bacon+spam</li>
<li>eggs+spam</li>
</ul>
</body>
</html>
```
## Motivation for This Project
At [Personalkollen](https://personalkollen.se/start/), where htpy was originally
developed we often found ourselves hitting walls when using classic templates.
htpy was created to improve the productiveness and experience of generating HTML
from a Python backend.
## Key Features
- **Leverage static types:** Use [mypy](https://mypy.readthedocs.io/en/stable/) or [pyright](https://github.com/microsoft/pyright) to type check your code.
- **Great debugging:** Avoid cryptic stack traces from templates. Use your favorite Python debugger.
- **Easy to extend:** There is no special way to define template tags/filters. Just call regular functions.
- **Works with existing Python web framework:** Works great with Django, Flask or any other Python web framework!
- **Works great with htmx:** htpy makes for a great experience when writing server rendered partials/components.
- **Create reusable components:** Define components, snippets, complex layouts/pages as regular Python variables or functions.
- **Familiar concepts from React:** React helped make it popular writing HTML with a programming language. htpy uses a lot of similar constructs.
## Philosophy
htpy generates HTML elements and attributes and provide a few helpers.
htpy does not enforce any particular pattern or style to organize
your pages, components and layouts. That does not mean that htpy cannot be used
to build sophisticated web pages or applications.
Rather the opposite: you are encouraged the leverage the power of Python to
structure your project. Use modules, classes, functions, decorators, list
comprehension, generators, conditionals, static typing and any other feature of
Python to organize your components. This gives you a lot of power and makes htpy
scale from a single small Flask project to bigger applications.
[Common patterns](https://htpy.dev/common-patterns/) can give you some ideas
that you can build upon yourself.
## The Syntax
Child elements are specified using the `[]` syntax. This may look strange at
first but it has some nice benefits. This clearly separates attributes from
child elements and makes the code more readable. It is implemented using the
`__getitem__` method, just like lists or dicts.
## Installation
[htpy is available on PyPI](https://pypi.org/project/htpy/). You may install the latest version using pip:
```
pip install htpy
```
## Documentation
The full documentation is available at [htpy.dev](https://htpy.dev):
- [Usage](https://htpy.dev/usage/)
- [Common patterns](https://htpy.dev/common-patterns/)
- [Static typing](https://htpy.dev/static-typing/)
- [Usage with Django](https://htpy.dev/django/)
- [Streaming of contents](https://htpy.dev/streaming/)
- [Convert HTML to htpy code](https://htpy.dev/html2htpy/)
- [FAQ](https://htpy.dev/faq/)
- [References](https://htpy.dev/references/)
- [Changelog](https://htpy.dev/changelog/)
Raw data
{
"_id": null,
"home_page": null,
"name": "htpy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Andreas Pelme <andreas@pelme.se>",
"download_url": "https://files.pythonhosted.org/packages/14/13/489e52462d3ac4a09732052d9d23e65db835e808235d1079dcc20fd73a0b/htpy-24.10.1.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <img src=\"https://htpy.dev/assets/htpy.webp\" width=\"300\">\n</p>\n\n# htpy - HTML in Python\n\nhtpy is a library that makes writing HTML in plain Python fun and efficient,\nwithout a template language.\n\n**Define HTML in Python:**\n\n```python\nfrom htpy import body, h1, head, html, li, title, ul\n\nmenu = [\"egg+bacon\", \"bacon+spam\", \"eggs+spam\"]\n\nprint(\n html[\n head[title[\"Today's menu\"]],\n body[\n h1[\"Menu\"],\n ul(\".menu\")[(li[item] for item in menu)],\n ],\n ]\n)\n```\n\n**And Get HTML:**\n\n```html\n<!DOCTYPE html>\n<html>\n <head>\n <title>Today's menu</title>\n </head>\n <body>\n <h1>Menu</h1>\n <ul class=\"menu\">\n <li>egg+bacon</li>\n <li>bacon+spam</li>\n <li>eggs+spam</li>\n </ul>\n </body>\n</html>\n```\n\n## Motivation for This Project\n\nAt [Personalkollen](https://personalkollen.se/start/), where htpy was originally\ndeveloped we often found ourselves hitting walls when using classic templates.\nhtpy was created to improve the productiveness and experience of generating HTML\nfrom a Python backend.\n\n## Key Features\n\n- **Leverage static types:** Use [mypy](https://mypy.readthedocs.io/en/stable/) or [pyright](https://github.com/microsoft/pyright) to type check your code.\n\n- **Great debugging:** Avoid cryptic stack traces from templates. Use your favorite Python debugger.\n\n- **Easy to extend:** There is no special way to define template tags/filters. Just call regular functions.\n\n- **Works with existing Python web framework:** Works great with Django, Flask or any other Python web framework!\n\n- **Works great with htmx:** htpy makes for a great experience when writing server rendered partials/components.\n\n- **Create reusable components:** Define components, snippets, complex layouts/pages as regular Python variables or functions.\n\n- **Familiar concepts from React:** React helped make it popular writing HTML with a programming language. htpy uses a lot of similar constructs.\n\n## Philosophy\n\nhtpy generates HTML elements and attributes and provide a few helpers.\n\nhtpy does not enforce any particular pattern or style to organize\nyour pages, components and layouts. That does not mean that htpy cannot be used\nto build sophisticated web pages or applications.\n\nRather the opposite: you are encouraged the leverage the power of Python to\nstructure your project. Use modules, classes, functions, decorators, list\ncomprehension, generators, conditionals, static typing and any other feature of\nPython to organize your components. This gives you a lot of power and makes htpy\nscale from a single small Flask project to bigger applications.\n\n[Common patterns](https://htpy.dev/common-patterns/) can give you some ideas\nthat you can build upon yourself.\n\n## The Syntax\n\nChild elements are specified using the `[]` syntax. This may look strange at\nfirst but it has some nice benefits. This clearly separates attributes from\nchild elements and makes the code more readable. It is implemented using the\n`__getitem__` method, just like lists or dicts.\n\n## Installation\n\n[htpy is available on PyPI](https://pypi.org/project/htpy/). You may install the latest version using pip:\n\n```\npip install htpy\n```\n\n## Documentation\n\nThe full documentation is available at [htpy.dev](https://htpy.dev):\n\n- [Usage](https://htpy.dev/usage/)\n- [Common patterns](https://htpy.dev/common-patterns/)\n- [Static typing](https://htpy.dev/static-typing/)\n- [Usage with Django](https://htpy.dev/django/)\n- [Streaming of contents](https://htpy.dev/streaming/)\n- [Convert HTML to htpy code](https://htpy.dev/html2htpy/)\n- [FAQ](https://htpy.dev/faq/)\n- [References](https://htpy.dev/references/)\n- [Changelog](https://htpy.dev/changelog/)\n",
"bugtrack_url": null,
"license": null,
"summary": "htpy - HTML in Python",
"version": "24.10.1",
"project_urls": {
"Documentation": "https://htpy.dev",
"Homepage": "https://htpy.dev",
"Issues": "https://github.com/pelme/htpy/issues",
"Repository": "https://github.com/pelme/htpy"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "70f54f90955c35bb4b44d5d2a1293b834a272c1c81d330aad4f49739e6d9f94c",
"md5": "e66adcc81c19d97f54f7382a3de334a6",
"sha256": "c2824ab27116248dbc60dd8e4c7ca34593f323cee702e48f72b0e8b96378ddef"
},
"downloads": -1,
"filename": "htpy-24.10.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e66adcc81c19d97f54f7382a3de334a6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 12475,
"upload_time": "2024-10-24T10:00:02",
"upload_time_iso_8601": "2024-10-24T10:00:02.921234Z",
"url": "https://files.pythonhosted.org/packages/70/f5/4f90955c35bb4b44d5d2a1293b834a272c1c81d330aad4f49739e6d9f94c/htpy-24.10.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "1413489e52462d3ac4a09732052d9d23e65db835e808235d1079dcc20fd73a0b",
"md5": "dad80d60ce6b8d3805145ae83a206346",
"sha256": "e85b57d73e86b1ba7b01eb956cf8b8fa32d4cc1dcce4be7c6c17a35c66bd2d13"
},
"downloads": -1,
"filename": "htpy-24.10.1.tar.gz",
"has_sig": false,
"md5_digest": "dad80d60ce6b8d3805145ae83a206346",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 280895,
"upload_time": "2024-10-24T10:00:05",
"upload_time_iso_8601": "2024-10-24T10:00:05.081302Z",
"url": "https://files.pythonhosted.org/packages/14/13/489e52462d3ac4a09732052d9d23e65db835e808235d1079dcc20fd73a0b/htpy-24.10.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-24 10:00:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pelme",
"github_project": "htpy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "htpy"
}