Basilico
Build HTML components in Python.
Basilico lets you create HTML components using pure Python code. Generate HTML5 markup effortlessly while building reusable components that enhance your development workflow.
Key Features
- Write HTML components using familiar Python syntax
- Generate standards-compliant HTML5 output
- Create and maintain reusable components
- Keep your templates type-safe with Python's typing
- No external dependencies
Usage
pip install basilico
from basilico.attributes import Class, Href
from basilico.components import If
from basilico.elements import A, Li, Nav, Ol, Text
from basilico.node import Node
def navbar(logged_in: bool) -> Node:
return Nav(
Class("navbar"),
Ol(
navbar_item("Home", "/"),
navbar_item("Contact", "/contact"),
navbar_item("About", "/about"),
If(
logged_in is False,
navbar_item("Login", "/login"),
),
),
)
def navbar_item(name: str, path: str) -> Node:
return Li(A(Href(path), Text(name)))
We can use generators to create components inline:
from basilico.elements import Li, Text, Ul
items = ["Coffee", "Tea", "Milk"]
Ul(
*(Li(Text(i)) for i in items),
)
# <ul>
# <li>Coffee</li>
# <li>Tea</li>
# <li>Milk</li>
# </ul>
HTMX support:
from basilico import htmx as hx
from basilico.elements import Button
Button(hx.Get("/example"))
# <button hx-get="/example"></button>
Alpine JS support:
from basilico import alpine as x
from basilico.elements import Button, Div, Text
Div(
x.Data("{ open: false }"),
Button(x.On("click", "open = !open"), Text("Toggle")),
Div(x.Show("open"), Text("Hello, Basilico!")),
)
# <div x-data="{ open: false }">
# <button x-on:click="open = !open">Toggle</button>
# <div x-show="open">Hello, Basilico!</div>
# </div>
FastAPI example:
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from basilico.attributes import Class, Src
from basilico.components import HTML5, HTML5Props
from basilico.elements import H1, Div, Script, Text
from basilico.node import Node
app = FastAPI()
def page(title: str, description: str, body: Node) -> Node:
props = HTML5Props(
title=title,
description=description,
language="en",
head=[Script(Src("https://cdn.tailwindcss.com"))],
body=[body],
)
return HTML5(props)
def body() -> Node:
return Div(
Class("min-h-screen flex items-center justify-center"),
H1(
Class("text-2xl font-bold text-teal-600 text-7xl"),
Text("Hello, Basilico!"),
),
)
@app.get("/")
def home():
content = page(
title="Home",
description="This is a simple example of Basilico with FastAPI.",
body=body(),
)
return HTMLResponse(content.string())
Metadata
Release files for basilico 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| basilico-0.1.0.tar.gz | 19.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| basilico-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.3 kB
Release files / basilico-0.1.0.tar.gz
| Download URL | basilico-0.1.0.tar.gz |
|---|---|
| Size | 19.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ce411ce9339a1f7c5384ef26c8d115507acce68022e31ea63e449284a4d42102
|
|
BLAKE2b-256 checksum How to use checksums |
1c91cd243e5c94fe50a562a991067282bb6d994a4bd6758d66b8f8c1687d7804
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Release files / basilico-0.1.0-py3-none-any.whl
| Download URL | basilico-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17d7622b276718c390003a844fcfb4a646835d066cd50ed815c79f133ceca3f5
|
|
BLAKE2b-256 checksum How to use checksums |
5b3da2670319d9bee57d9c6a967d8d63dfc4cb0f87040656c19b08f8467c4c6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Security for basilico 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.