Skip to content

PageMeta

PageMeta is a higher-level head composer that combines SEO tags, canonical URL handling, optional PWA tags, and optional favicon links in one call.

It is designed for teams that want a single, predictable entry point for page head metadata without repeating multiple helpers.


Quick Start

from faststrap import PageMeta

PageMeta(
    title="Faststrap Docs",
    description="Build modern UI in Python",
    canonical="https://faststrap.dev/docs",
    image="https://faststrap.dev/og/docs.png",
)

Visual Examples & Use Cases

1. Basic SEO Page

PageMeta(
    title="Home",
    description="Welcome to my app",
)

Renders:

<title>Home - Welcome to my app</title>
<meta name="description" content="Welcome to my app">

2. Full PageMeta with PWA

PageMeta(
    title="My App",
    description="Installable FastHTML app",
    include_pwa=True,
    pwa_name="My App",
    pwa_short_name="MyApp",
    pwa_theme_color="#0d6efd",
)

3. With Favicon

PageMeta(
    title="Dashboard",
    favicon_url="/assets/favicon.png",
)

Practical Functionality

1. Route-Level Usage

@app.get("/")
def home():
    return (
        PageMeta(title="Home", description="Welcome"),
        Container(H1("Home")),
    )

2. SEO vs PageMeta Decision Guide

Scenario Recommended
Simple content page SEO(...)
Marketing/app shell with PWA PageMeta(...)
Large codebase with many routes PageMeta(...) for consistency

3. With Structured Data

@app.get("/product")
def product():
    return (
        PageMeta(
            title="Product",
            description="Buy our product",
            image="https://example.com/og.png",
        ),
        StructuredData.Product(
            name="Product",
            description="Buy our product",
            brand="Brand",
        ),
        Container(H1("Product")),
    )

Parameter Reference

Parameter Type Default Description
title str None Page title.
description str None Meta description.
keywords str \| None None Meta keywords.
image str \| None None Open Graph image URL.
url str \| None None Canonical URL.
canonical str \| None None Canonical URL (alias for url).
robots str \| None None Robots meta content.
twitter_site str \| None None Twitter site handle.
twitter_creator str \| None None Twitter creator handle.
locale str \| None None Locale for Open Graph.
include_pwa bool False Include PWA meta tags.
pwa_name str \| None None PWA application name.
pwa_short_name str \| None None PWA short name.
pwa_theme_color str \| None None PWA theme color.
pwa_background_color str \| None None PWA background color.
favicon_url str \| None None Custom favicon URL.
extra_meta dict \| None None Additional meta tags.
**kwargs Any {} Additional attributes.

API Reference

faststrap.seo.page_meta.PageMeta(title=None, description=None, keywords=None, image=None, url=None, canonical=None, type='website', robots='index, follow', twitter_site=None, twitter_creator=None, locale=None, include_pwa=False, pwa_name=None, pwa_short_name=None, pwa_theme_color='#ffffff', pwa_background_color='#ffffff', favicon_url=None, extra_meta=None)

Compose page metadata with deduplication guarantees.

Source code in src/faststrap/seo/page_meta.py
def PageMeta(
    title: str | None = None,
    description: str | None = None,
    keywords: list[str] | None = None,
    image: str | None = None,
    url: str | None = None,
    canonical: str | None = None,
    type: Literal["website", "article", "product"] = "website",
    robots: str = "index, follow",
    twitter_site: str | None = None,
    twitter_creator: str | None = None,
    locale: str | None = None,
    include_pwa: bool = False,
    pwa_name: str | None = None,
    pwa_short_name: str | None = None,
    pwa_theme_color: str = "#ffffff",
    pwa_background_color: str = "#ffffff",
    favicon_url: str | None = None,
    extra_meta: dict[str, Any] | None = None,
) -> tuple[Any, ...]:
    """Compose page metadata with deduplication guarantees."""
    elements: list[Any] = []

    if title is not None:
        elements.append(Title(title))
    elements.extend(
        SEO(
            title=title,
            description=description,
            keywords=keywords,
            image=image,
            url=url,
            canonical=canonical,
            og_type=type,
            robots=robots,
            twitter_site=twitter_site,
            twitter_creator=twitter_creator,
            locale=locale,
        )
    )

    if include_pwa:
        elements.extend(
            PwaMeta(
                name=pwa_name or title or "Faststrap App",
                short_name=pwa_short_name or pwa_name or "Faststrap",
                description=description,
                theme_color=pwa_theme_color,
                background_color=pwa_background_color,
            )
        )

    if favicon_url:
        elements.extend(create_favicon_links(favicon_url))

    if extra_meta:
        for key, value in extra_meta.items():
            if value is None:
                continue
            attr = key.replace("_", "-")
            elements.append(Meta(name=attr, content=str(value)))

    canonical_url = canonical or url
    if canonical_url:
        elements.append(Link(rel="canonical", href=canonical_url))

    return _dedupe(elements)