Structured data

Document.structured_data() pulls every machine-readable metadata format a page embeds in one walk, with the per-format helpers Document.json_ld(), Document.opengraph(), Document.microdata(), Document.rdfa(), and Document.dublin_core() beside it. The walk runs in the C core; the typed, read-only result records below are handed back from it.

class turbohtml.StructuredData(json_ld, microdata, opengraph, microformats, rdfa, dublin_core)

Every machine-readable metadata format a document embeds, the combined result of one walk.

Parameters:
json_ld: list[bool | int | float | str | list[bool | int | float | str | list[JSONValue] | dict[str, JSONValue] | None] | dict[str, bool | int | float | str | list[JSONValue] | dict[str, JSONValue] | None] | None]

each <script type="application/ld+json"> block decoded with json.

microdata: list[MicrodataItem]

every top-level MicrodataItem.

opengraph: dict[str, str]

each og:/twitter: <meta> key mapped to its content.

microformats: list[bool | int | float | str | list[bool | int | float | str | list[JSONValue] | dict[str, JSONValue] | None] | dict[str, bool | int | float | str | list[JSONValue] | dict[str, JSONValue] | None] | None]

reserved for a later phase, an empty list for now.

rdfa: list[RdfaItem]

every top-level RdfaItem.

dublin_core: dict[str, str]

each dc.*/dcterms.* <meta> name (lower-cased) mapped to its content.

class turbohtml.MicrodataItem(type, id, properties)

One HTML Microdata item: an element carrying itemscope and the properties beneath it.

Parameters:
  • type (str | None) – the itemtype attribute verbatim, or None when the element has none.

  • id (str | None) – the itemid attribute verbatim, or None when the element has none.

  • properties (dict[str, list[str | MicrodataItem]]) – each itemprop name mapped to its values in document order, a value being the property’s text/URL as a str or a nested MicrodataItem for a property that is itself an itemscope.

type: str | None

the itemtype attribute verbatim, or None when the element has none.

id: str | None

the itemid attribute verbatim, or None when the element has none.

properties: dict[str, list[str | MicrodataItem]]

each itemprop name mapped to its values in document order.

get(name)

Return the property’s first value, or None when the item lacks it (microdata.Item.get).

Parameters:

name (str)

Return type:

str | MicrodataItem | None

get_all(name)

Return the property’s values in document order, an empty list when absent (microdata.Item.get_all).

Parameters:

name (str)

Return type:

list[str | MicrodataItem]

json()

Serialize as microdata.Item.json does: a two-space-indented JSON object of the tree below the item.

Return type:

str

class turbohtml.RdfaItem(vocab, type, resource, properties)

One RDFa resource: an element carrying typeof and the property values beneath it.

Mirrors MicrodataItem with the RDFa vocabulary context added. property keys and the type IRIs are expanded against the in-scope @vocab and @prefix mappings (the RDFa 1.1 initial context seeds the common prefixes, so schema:, dc:, foaf: resolve without a page-level declaration); a token whose prefix is undeclared, or a bare term with no @vocab in scope, is kept verbatim.

Parameters:
  • vocab (str | None) – the in-scope @vocab IRI, or None when no vocabulary is set.

  • type (list[str]) – the expanded @typeof IRIs in document order, an empty list for a valueless typeof.

  • resource (str | None) – the resource subject (@about/@resource/@href/@src), or None for a blank node.

  • properties (dict[str, list[str | RdfaItem]]) – each expanded property IRI mapped to its values in document order, a value being a literal or IRI str or a nested RdfaItem for a property that is itself a typeof.

vocab: str | None

the in-scope @vocab IRI, or None when no vocabulary is set.

type: list[str]

the expanded @typeof IRIs in document order, an empty list for a valueless typeof.

resource: str | None

the resource subject (@about/@resource/@href/@src), or None for a blank node.

properties: dict[str, list[str | RdfaItem]]

each expanded property IRI mapped to its values in document order.

get(name)

Return the property’s first value, or None when the item lacks it.

Parameters:

name (str)

Return type:

str | RdfaItem | None

get_all(name)

Return the property’s values in document order, an empty list when absent.

Parameters:

name (str)

Return type:

list[str | RdfaItem]