Skip to content

schema_access

Typed accessors over the LiteRT flatbuffer object API.

The generated *T classes in schema_py_generated initialise every vector and table field to None and only fill it in when the flatbuffer carries that field, so a type checker sees op.inputs as list | None and flags every iteration, index and attribute access. Read those fields through the helpers here instead: each one rejects None with a clear error naming the missing field, and restates the element type the generated code only records in # type: comments.

Functions

present

present(value: _T | None, what: str) -> _T

Return value, rejecting the None the object API uses for absent fields.

Parameters:

  • value

    (_T | None) –

    The field value read from a generated *T object.

  • what

    (str) –

    Human-readable name of the field, used in the error message.

Returns:

  • _T

    value unchanged.

Raises:

subgraphs_of

subgraphs_of(model: ModelT) -> list[litert.SubGraphT]

The model's subgraphs.

subgraph_at

subgraph_at(model: ModelT, index: int) -> litert.SubGraphT

The subgraph at index.

buffers_of

buffers_of(model: ModelT) -> list[litert.BufferT]

The model's buffer table.

operator_codes_of

operator_codes_of(model: ModelT) -> list[litert.OperatorCodeT]

The model's operator-code table.

operators_of

operators_of(subgraph: SubGraphT) -> list[litert.OperatorT]

The subgraph's operators.

operator_at

operator_at(subgraph: SubGraphT, index: int) -> litert.OperatorT

The operator at index within subgraph.

tensors_of

tensors_of(subgraph: SubGraphT) -> list[litert.TensorT]

The subgraph's tensors.

tensor_at

tensor_at(subgraph: SubGraphT, index: int) -> litert.TensorT

The tensor at index within subgraph.

inputs_of

inputs_of(node: OperatorT | SubGraphT) -> Sequence[int]

Input tensor indices of an operator or subgraph.

outputs_of

outputs_of(node: OperatorT | SubGraphT) -> Sequence[int]

Output tensor indices of an operator or subgraph.

builtin_options

builtin_options(op: OperatorT) -> Any

The operator's builtin options table.

The concrete *OptionsT class depends on the operator, so the result is deliberately untyped; callers read the fields they know exist.

shape_of

shape_of(tensor: TensorT) -> Sequence[int]

The tensor's static shape.