Skip to content

caxton.api

The extended generative API. caxton re-exports most of it; import caxton.api directly for the backend-specific escape hatches.

Factories and operations

Identical to the caxton facade — caxton.api is where they are defined.

from caxton.api import (
    Column,
    ColumnSchema,
    SemanticType,
    Text,
    compose,
    literal,
    render,
    sheet,
    spreadsheet,
    table,
    text,
    validate,
    write,
)

Column(...) is the normalized generic constructor. ColumnSchema provides named reusable column tuples, and literal() creates a constant Python row expression. Built-in semantic types and SemanticType are exported here and from the short caxton facade.

ColumnSchema

Named, inheritable organization for immutable column values.

Use compose({"Section": document, ...}) to combine independently built spreadsheet documents into one section-qualified workbook. See Documents.

Formatting and format helpers

from caxton.api import (
    AutoWidth,
    Style,
    StyleSheet,
    custom_format,
    date_format,
    decimal_format,
    money_format,
    percentage_format,
    time_format,
)

See caxton.core.formatting for the full documentation.

XLSX escape hatches

Backend-specific, namespaced, and never part of the core model.

Classes:

Functions:

  • openpyxl_hook –

    Create an XLSX-namespaced post-render OpenPyXL hook.

  • pivot –

    Bind an existing XLSX pivot to generated data.

OpenpyxlHookContext dataclass

OpenpyxlHookContext(native_workbook: Any, native_sheet: Any)

Narrow XLSX-scoped access to native OpenPyXL objects.

OpenpyxlHookExtension dataclass

OpenpyxlHookExtension(function: OpenpyxlHook, sheet: str | None = None)

Run one explicit hook after semantic content is rendered.

PivotBinding dataclass

PivotBinding(target: str, source: TemplateRef | TableReference, refresh_on_open: bool = True)

XLSX-only intent to rebind an existing pivot cache source.

openpyxl_hook

openpyxl_hook(function: OpenpyxlHook, *, sheet: str | None = None) -> OpenpyxlHookExtension

Create an XLSX-namespaced post-render OpenPyXL hook.

Returns:

pivot

pivot(target: str, *, source: TemplateRef | TableReference, refresh_on_open: bool = True) -> PivotBinding

Bind an existing XLSX pivot to generated data.

Returns: