# pyghtml
Python-Generatable HTML
> ⚠️ **In per-issue development**
> 🦐 Any help or critique is encouraged.
## Idea
This library was born when I needed to convert English lesson plans from JSON to a static website. I didn't want to learn how to set up a server just to compile some pages. And I don't know PHP. So this library consists of HTML tags as Python classes, with attributes as class properties.
> 💅 It's pie-tea-em-el, actually.
## Features
### Attribute types and defaults
Boolean Python values behave according to the logic of boolean HTML attributes. `autofocus` is turned off by default, so `autofocus=False` doesn't lead to redundancies. The same goes for `autocorrect="on"`, which is the default value.
```python
b = pyghtml.Button(title="Home", disabled=True, autofocus=False, autocorrect="on")
print(b)
```
produces:
```html
<button title="Home" disabled></button>
```
### Simple container logic
All container tags support list operations that are applied on the `inner_html` property. You can return specific children, reverse their order, etc. You can use `+` or `+=` to put something inside a "tag" (`+` returns a new instance). And if you put a list of elements or strings inside a tag, it is automatically unpacked.
```python
list1 = pyghtml.Ul() + pyghtml.Li(inner_html="I'm Sawcon")
list2 = pyghtml.Ul() + (list1[0] + ", too!")
list1 += pyghtml.Li() + ["Sawcon", " ", "Deeznuts"]
print(list1)
print(list2)
```
produces:
```html
<ul>
<li>I'm Sawcon</li>
<li>Sawcon Deeznuts</li>
</ul>
<ul>
<li>I'm Sawcon, too!</li>
</ul>
```
## Installation
Run:
```bash
pip install pyghtml
```
Import:
```python
import pyghtml as html
```
## Additional notes
- Self-closing tags are self-closing (`<br />`).
- `<!DOCTYPE html>` is `Doctype()` and `<!-- -->` is `CommentHtml()`.
- HTML attributes that match Python reserved words are suffixed with `_` (`class` is `class_`).
- If the attribute's default value is `None`, that usually means there is no clear default value for it in the HTML spec (like the values controlled by the client-side agents when omitted). Attributes like `alt` default to `None` because an omitted `alt` is not the same as `alt=""` from the accessibility standpoint.
- `data-*`, `aria-*`, event (`onclick`, etc), and custom/missing attributes should be given as dictionaries through `data_attrs`, `aria_attrs`, `event_attrs`, `custom_attrs`. For example: `data_attrs = {"data-custom-name": "custom value"}`.
- Abbreviations are broken: `Html()`, `Wbr()`. This may be debatable, but I thought that classes like `HttpEquiv()` and `AriaAttrs()` reflect `http-equiv` and `aria-*` much more clearly than `HTTPEquiv()` and `ARIAAttrs()` would do. Also, it's hard to keep in mind whether `bdi`, `bdo`, `src`, `ul`, `li`, `dt`, `dfn` count as abbreviations.
- There are class names like `I()` for `<i></i>`, so please use a font that differentiates between `Il1`. JetBrains Mono, for instance.
## Future improvements
- [x] Add attribute docstrings
- [x] Add tag docstrings
- [ ] Add attribute validation
- [ ] Add tag validation
- [ ] Add recipes (`LinkStylesheet` with pre-set `rel`, etc)
- [x] Package for pip
## Sources
- [HTML Spec](https://developer.mozilla.org/en-US/docs/Web/HTML)
- [MDN Web Docs](https://html.spec.whatwg.org/)
- [W3Schools](https://www.w3schools.com/tags/default.asp)
Raw data
{
"_id": null,
"home_page": null,
"name": "pyghtml",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.13",
"maintainer_email": null,
"keywords": "OOP, generator, html, python, static pages",
"author": null,
"author_email": "Artem Shush <shushtain@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/5d/e8/efd9e7785371eba30948b7213aa77aef73375c86a410029cd7ab2598239f/pyghtml-1.2.0.tar.gz",
"platform": null,
"description": "# pyghtml\n\nPython-Generatable HTML\n\n> \u26a0\ufe0f **In per-issue development** \n> \ud83e\udd90 Any help or critique is encouraged.\n\n## Idea\n\nThis library was born when I needed to convert English lesson plans from JSON to a static website. I didn't want to learn how to set up a server just to compile some pages. And I don't know PHP. So this library consists of HTML tags as Python classes, with attributes as class properties.\n\n> \ud83d\udc85 It's pie-tea-em-el, actually.\n\n## Features\n\n### Attribute types and defaults\n\nBoolean Python values behave according to the logic of boolean HTML attributes. `autofocus` is turned off by default, so `autofocus=False` doesn't lead to redundancies. The same goes for `autocorrect=\"on\"`, which is the default value.\n\n```python\nb = pyghtml.Button(title=\"Home\", disabled=True, autofocus=False, autocorrect=\"on\")\nprint(b)\n```\n\nproduces:\n\n```html\n<button title=\"Home\" disabled></button>\n```\n\n### Simple container logic\n\nAll container tags support list operations that are applied on the `inner_html` property. You can return specific children, reverse their order, etc. You can use `+` or `+=` to put something inside a \"tag\" (`+` returns a new instance). And if you put a list of elements or strings inside a tag, it is automatically unpacked.\n\n```python\nlist1 = pyghtml.Ul() + pyghtml.Li(inner_html=\"I'm Sawcon\")\nlist2 = pyghtml.Ul() + (list1[0] + \", too!\")\nlist1 += pyghtml.Li() + [\"Sawcon\", \" \", \"Deeznuts\"]\nprint(list1)\nprint(list2)\n```\n\nproduces:\n\n```html\n<ul>\n <li>I'm Sawcon</li>\n <li>Sawcon Deeznuts</li>\n</ul>\n<ul>\n <li>I'm Sawcon, too!</li>\n</ul>\n```\n\n## Installation\n\nRun:\n\n```bash\npip install pyghtml\n```\n\nImport:\n\n```python\nimport pyghtml as html\n```\n\n## Additional notes\n\n- Self-closing tags are self-closing (`<br />`).\n- `<!DOCTYPE html>` is `Doctype()` and `<!-- -->` is `CommentHtml()`.\n- HTML attributes that match Python reserved words are suffixed with `_` (`class` is `class_`).\n- If the attribute's default value is `None`, that usually means there is no clear default value for it in the HTML spec (like the values controlled by the client-side agents when omitted). Attributes like `alt` default to `None` because an omitted `alt` is not the same as `alt=\"\"` from the accessibility standpoint.\n- `data-*`, `aria-*`, event (`onclick`, etc), and custom/missing attributes should be given as dictionaries through `data_attrs`, `aria_attrs`, `event_attrs`, `custom_attrs`. For example: `data_attrs = {\"data-custom-name\": \"custom value\"}`.\n- Abbreviations are broken: `Html()`, `Wbr()`. This may be debatable, but I thought that classes like `HttpEquiv()` and `AriaAttrs()` reflect `http-equiv` and `aria-*` much more clearly than `HTTPEquiv()` and `ARIAAttrs()` would do. Also, it's hard to keep in mind whether `bdi`, `bdo`, `src`, `ul`, `li`, `dt`, `dfn` count as abbreviations.\n- There are class names like `I()` for `<i></i>`, so please use a font that differentiates between `Il1`. JetBrains Mono, for instance.\n\n## Future improvements\n\n- [x] Add attribute docstrings\n- [x] Add tag docstrings\n- [ ] Add attribute validation\n- [ ] Add tag validation\n- [ ] Add recipes (`LinkStylesheet` with pre-set `rel`, etc)\n- [x] Package for pip\n\n## Sources\n\n- [HTML Spec](https://developer.mozilla.org/en-US/docs/Web/HTML)\n- [MDN Web Docs](https://html.spec.whatwg.org/)\n- [W3Schools](https://www.w3schools.com/tags/default.asp)\n",
"bugtrack_url": null,
"license": null,
"summary": "Python-Generatable HTML.",
"version": "1.2.0",
"project_urls": {
"Homepage": "https://github.com/shushtain/pyghtml",
"Issues": "https://github.com/shushtain/pyghtml/issues"
},
"split_keywords": [
"oop",
" generator",
" html",
" python",
" static pages"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "33117f359de05e0358ce93ce474346f0dd87aa1df8ed25d79445b9aff65491b1",
"md5": "6df9d39aa1ff4bca4bf9a56ed3fa428b",
"sha256": "012b48e17f4d5f999c9c534b0df46f3727100e31e67c60f47235c6692d603105"
},
"downloads": -1,
"filename": "pyghtml-1.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6df9d39aa1ff4bca4bf9a56ed3fa428b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.13",
"size": 15249,
"upload_time": "2025-03-20T14:18:20",
"upload_time_iso_8601": "2025-03-20T14:18:20.270326Z",
"url": "https://files.pythonhosted.org/packages/33/11/7f359de05e0358ce93ce474346f0dd87aa1df8ed25d79445b9aff65491b1/pyghtml-1.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "5de8efd9e7785371eba30948b7213aa77aef73375c86a410029cd7ab2598239f",
"md5": "816c61c8982c0c5dd845775941be34c3",
"sha256": "dd5f06e6a106941256c7518881c9b3c38937d55558dc707915da1822aa736250"
},
"downloads": -1,
"filename": "pyghtml-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "816c61c8982c0c5dd845775941be34c3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.13",
"size": 15487,
"upload_time": "2025-03-20T14:18:22",
"upload_time_iso_8601": "2025-03-20T14:18:22.395105Z",
"url": "https://files.pythonhosted.org/packages/5d/e8/efd9e7785371eba30948b7213aa77aef73375c86a410029cd7ab2598239f/pyghtml-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-03-20 14:18:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "shushtain",
"github_project": "pyghtml",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyghtml"
}