# Hypermedia
hypermedia is a pure python library for working with html. hypermedias killer feature is that it is html code is composable through `slot` concept. Because of that, it works great with HTMX partials and full page reloads.
Hypermedia is made to work with FastAPI and HTMX. but can be used by any web server.
Here are some basics:
All html tags can be imported directly like:
```python
from hypermedia import Html, Body, Div, A
```
Tags are nested by adding children in the constructor:
```python
from hypermedia import Html, Body, Div
Html(Body(Div(), Div()))
```
Add text to your tag:
```python
from hypermedia import Html, Body, Div
Html(text="Hello world!")
```
use `.dump()` to dump your code to html.
```python
from hypermedia import Html, Body, Div
Html(text="Hello world!").dump()
# outputs
# '<html>hello world</html>'
```
## Composability with slots
```python
from hypermedia import Html, Body, Div, Menu, Header, Div, Ul, Li
base = Html(
Body(
Menu(slot="menu"),
Header(slot="header", text="my header"),
Div(slot="content"),
),
)
menu = Ul(Li(text="main"))
content = Div(text="Some content")
base.extend("menu", menu)
base.extend("content", content)
base.dump()
# outputs
# '<html><body><menu><ul><li>main</li></ul></menu><header>my header</header><div><div>Some content</div></div></body></html>'
```
# With FastAPI:
coming
## Using dependency injection.
Raw data
{
"_id": null,
"home_page": "https://github.com/thomasborgen/hypermedia",
"name": "hypermedia",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "HTML, HTMX, Extendable, Partial HTML, HTML Templating, FastAPI",
"author": "Thomas Borgen",
"author_email": "thomasborgen91@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/78/a1/01937541866996c289403d0f2a8c9c66c21a97ea5ad9cb850ed5eacbe11e/hypermedia-2.0.1.tar.gz",
"platform": null,
"description": "# Hypermedia\n\nhypermedia is a pure python library for working with html. hypermedias killer feature is that it is html code is composable through `slot` concept. Because of that, it works great with HTMX partials and full page reloads.\n\nHypermedia is made to work with FastAPI and HTMX. but can be used by any web server.\n\n\nHere are some basics:\n\nAll html tags can be imported directly like:\n\n```python\nfrom hypermedia import Html, Body, Div, A\n```\n\nTags are nested by adding children in the constructor:\n\n```python\nfrom hypermedia import Html, Body, Div\n\nHtml(Body(Div(), Div()))\n```\n\nAdd text to your tag:\n\n```python\nfrom hypermedia import Html, Body, Div\n\nHtml(text=\"Hello world!\")\n```\n\nuse `.dump()` to dump your code to html.\n\n\n```python\nfrom hypermedia import Html, Body, Div\n\nHtml(text=\"Hello world!\").dump()\n\n# outputs\n# '<html>hello world</html>'\n```\n\n## Composability with slots\n\n```python\nfrom hypermedia import Html, Body, Div, Menu, Header, Div, Ul, Li\n\nbase = Html(\n Body(\n Menu(slot=\"menu\"),\n Header(slot=\"header\", text=\"my header\"),\n Div(slot=\"content\"),\n ),\n)\n\nmenu = Ul(Li(text=\"main\"))\ncontent = Div(text=\"Some content\")\n\nbase.extend(\"menu\", menu)\nbase.extend(\"content\", content)\n\nbase.dump()\n\n# outputs\n# '<html><body><menu><ul><li>main</li></ul></menu><header>my header</header><div><div>Some content</div></div></body></html>'\n```\n\n\n# With FastAPI:\n\ncoming\n\n\n## Using dependency injection.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "An opinionated way to work with html in pure python with htmx support.",
"version": "2.0.1",
"project_urls": {
"Homepage": "https://github.com/thomasborgen/hypermedia",
"Repository": "https://github.com/thomasborgen/hypermedia"
},
"split_keywords": [
"html",
" htmx",
" extendable",
" partial html",
" html templating",
" fastapi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d81a8aa662ab6bf4ea49af88d5cb8f5a2786cd586464e87bdb2c94da738c952b",
"md5": "2c60d5bdd828683d81c54449a4bcd8dc",
"sha256": "22cdebc2a1ea99c8603af3896249e667bcbfefc6f7559d5aadd7fa3e4be353ba"
},
"downloads": -1,
"filename": "hypermedia-2.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2c60d5bdd828683d81c54449a4bcd8dc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 13746,
"upload_time": "2024-04-26T17:51:26",
"upload_time_iso_8601": "2024-04-26T17:51:26.579298Z",
"url": "https://files.pythonhosted.org/packages/d8/1a/8aa662ab6bf4ea49af88d5cb8f5a2786cd586464e87bdb2c94da738c952b/hypermedia-2.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "78a101937541866996c289403d0f2a8c9c66c21a97ea5ad9cb850ed5eacbe11e",
"md5": "c828424b24782fad00d9102e7da9ca6b",
"sha256": "70aab935d3afd9603677ef5e1e64c0268bc0e95c010e2a2b76361b3ee90cbd46"
},
"downloads": -1,
"filename": "hypermedia-2.0.1.tar.gz",
"has_sig": false,
"md5_digest": "c828424b24782fad00d9102e7da9ca6b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 11575,
"upload_time": "2024-04-26T17:51:27",
"upload_time_iso_8601": "2024-04-26T17:51:27.705265Z",
"url": "https://files.pythonhosted.org/packages/78/a1/01937541866996c289403d0f2a8c9c66c21a97ea5ad9cb850ed5eacbe11e/hypermedia-2.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-26 17:51:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "thomasborgen",
"github_project": "hypermedia",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "hypermedia"
}