
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Adds s-expression HTML tags to FastAPI views. Inspired by FastHTML's use of fastcore's FT components.
Adds s-expression HTML tags to FastAPI views. Inspired by FastHTML's use of fastcore's FT components.
uv:
uv add fastapi-tags
pip:
pip install fastapi-tags
uv pip install fastapi-tags
from fastapi import FastAPI
import fastapi_tags as tg
app = FastAPI()
@app.get("/", response_class=tg.TagResponse)
async def index():
return tg.Html(tg.H1("Hello, world!", style="color: blue;"))
If you want to do snippets, just skip the tg.Html
tag:
@app.get("/time", response_class=tg.TagResponse)
async def time():
return tg.P("Time to do code!")
If you want to detect HTMX use dependency injection:
from fastapi import Depends
@app.get("/hello", response_class=tg.TagResponse)
def test_endpoint(is_htmx: bool = Depends(tg.is_htmx_request)):
if is_htmx:
return tg.H1("Hello, hx-request! Here's a partial of the page.")
else:
return tg.Html(tg.H1("Hello normal request, Here's the full page!"))
There are several ways to create custom Tags
class AwesomeP(tg.P) -> tg.Tag:
def render(self) -> str:
return f"<p{self.attrs}>AWESOME {self.children}!</p>"
AwesomeP('library')
<p>AWESOME library!</p>
def PicoCard(header: str, body: str, footer: str) -> tg.Tag:
return tg.Article(
tg.Header(header),
body,
tg.Footer(footer)
)
@app.get("/card", response_class=tg.TagResponse)
async def card():
return PicoCard(
'FastAPI Tags',
'Adds s-expression HTML tags (Tags) to FastAPI views.',
'by various contributors'
)
<article>
<header>FastAPI Tags</header>
Adds s-expression HTML tags (Tags) to FastAPI views.
<footer>by various contributors</footer>
</article>
For cases where you need to render raw HTML:
from fastapi_tags import RawHTML
# Render raw HTML content
raw_content = RawHTML('<strong>Bold text</strong> and <em>italic</em>')
# Note: RawHTML only accepts a single string argument
# For multiple elements, combine them first:
html_string = '<p>First</p><p>Second</p>'
raw = RawHTML(html_string)
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.