Skip to content

pyaccesskit.schema.columns

pyaccesskit.schema.columns

Column (field) specifications and the :class:Column factory.

Each Access data type has its own immutable spec class (TextColumn, NumberColumn...) so that only options meaningful for that type are accepted. The classes form a discriminated union on type (:data:ColumnSpec), which is also how columns appear in JSON/YAML::

{"type": "text", "name": "Email", "length": 255}

Most code uses the :class:Column factory, which mirrors the Access table designer::

Column.autonumber("CustomerID", primary_key=True)
Column.text("CustomerName", length=200, required=True)
Column.number("Quantity", size=NumberSize.INTEGER)
Column.currency("UnitPrice", default=0)

ColumnSpec module-attribute

ColumnSpec = Annotated[
    TextColumn
    | LongTextColumn
    | NumberColumn
    | DecimalColumn
    | CurrencyColumn
    | AutoNumberColumn
    | DateTimeColumn
    | YesNoColumn
    | HyperlinkColumn
    | OleObjectColumn
    | UnsupportedColumn,
    Field(discriminator="type"),
]

Any column spec (a Pydantic discriminated union on type).

ColumnBase

Bases: SpecModel

Options shared by every column type.

Attributes:

Name Type Description
name str

Field name (≤64 characters; see Access naming rules).

required bool

Disallow Null values (Required property).

default DefaultValue | None

Default value: a Python literal (rendered as an Access literal) or an Expr.

validation_rule str | None

Validation Rule expression, e.g. ">0".

validation_text str | None

Message shown when the validation rule fails.

description str | None

Description shown in the table designer.

caption str | None

Caption used as the default label text on forms and datasheet headers.

format str | None

Format property, e.g. "Short Date" or "Currency".

primary_key bool

Shorthand: include this column in the table's primary key.

unique bool

Shorthand: create a unique single-column index named after the column.

indexed bool

Shorthand: create a non-unique single-column index named after the column.

properties dict[str, PropertyValue]

Other Access/DAO field properties to set verbatim (escape hatch).

normalized

normalized() -> Self

Canonical form: the index shorthands are cleared (they live in TableSpec.indexes).

TextColumn

Bases: ColumnBase

Short Text: up to 255 characters.

LongTextColumn

Bases: ColumnBase

Long Text (Memo): up to ~1 GB; optionally rich text and append-only.

HyperlinkColumn

Bases: ColumnBase

Hyperlink: a Long Text field flagged as a hyperlink.

NumberColumn

Bases: ColumnBase

Number with a Field Size of Byte, Integer (16-bit), Long Integer, Single, Double or Replication ID.

decimal_places class-attribute instance-attribute

decimal_places: int | None = Field(
    default=None, ge=0, le=15
)

None means Auto.

DecimalColumn

Bases: ColumnBase

Number with Field Size = Decimal (exact, with precision and scale).

CurrencyColumn

Bases: ColumnBase

Currency: fixed-point, 4 decimal places, no rounding surprises.

AutoNumberColumn

Bases: ColumnBase

AutoNumber: an incrementing Long Integer, or a Replication ID (GUID).

Random AutoNumbers are not offered: DAO silently ignores the setting, so PyAccessKit cannot create them reliably (see ADR 0002).

DateTimeColumn

Bases: ColumnBase

Date/Time.

YesNoColumn

Bases: ColumnBase

Yes/No (Boolean). Shown as a check box in datasheets and bound forms.

OleObjectColumn

Bases: ColumnBase

OLE Object (long binary data).

UnsupportedColumn

Bases: ColumnBase

A column PyAccessKit can read but not create yet (Attachment, Calculated, Large Number...).

It appears when introspecting existing databases so that to_spec() never fails; creating a table with one raises :class:~pyaccesskit.errors.SpecError.

ColumnOptions

Bases: TypedDict

Keyword options accepted by every :class:Column constructor (see :class:ColumnBase).

AutoNumberOptions

Bases: TypedDict

Keyword options accepted by :meth:Column.autonumber (no default/required).

OleObjectOptions

Bases: AutoNumberOptions

Keyword options accepted by :meth:Column.ole_object (no default value).

Column

Column()

Factory for column specs, mirroring the data types of the Access table designer.

Every constructor raises :class:~pyaccesskit.errors.SpecError for invalid options.

text staticmethod

text(
    name: str,
    *,
    length: int = 255,
    allow_zero_length: bool = False,
    unicode_compression: bool = True,
    input_mask: str | None = None,
    **options: Unpack[ColumnOptions],
) -> TextColumn

Short Text (length 1-255, default 255).

long_text staticmethod

long_text(
    name: str,
    *,
    rich_text: bool = False,
    append_only: bool = False,
    allow_zero_length: bool = False,
    unicode_compression: bool = True,
    **options: Unpack[ColumnOptions],
) -> LongTextColumn

Long Text (Memo).

number staticmethod

number(
    name: str,
    *,
    size: NumberSize | str = NumberSize.LONG_INTEGER,
    decimal_places: int | None = None,
    input_mask: str | None = None,
    **options: Unpack[ColumnOptions],
) -> NumberColumn

Number. size defaults to Long Integer (32-bit), exactly like Access.

decimal staticmethod

decimal(
    name: str,
    *,
    precision: int = 18,
    scale: int = 0,
    decimal_places: int | None = None,
    input_mask: str | None = None,
    **options: Unpack[ColumnOptions],
) -> DecimalColumn

Number with Field Size = Decimal(precision, scale).

currency staticmethod

currency(
    name: str,
    *,
    decimal_places: int | None = None,
    input_mask: str | None = None,
    **options: Unpack[ColumnOptions],
) -> CurrencyColumn

Currency.

autonumber staticmethod

autonumber(
    name: str,
    *,
    replication_id: bool = False,
    **options: Unpack[AutoNumberOptions],
) -> AutoNumberColumn

AutoNumber (Long Integer by default; replication_id=True for a GUID).

date_time staticmethod

date_time(
    name: str,
    *,
    input_mask: str | None = None,
    **options: Unpack[ColumnOptions],
) -> DateTimeColumn

Date/Time.

yes_no staticmethod

yes_no(
    name: str, **options: Unpack[ColumnOptions]
) -> YesNoColumn

Yes/No (Boolean).

hyperlink(
    name: str,
    *,
    allow_zero_length: bool = False,
    unicode_compression: bool = True,
    **options: Unpack[ColumnOptions],
) -> HyperlinkColumn

Hyperlink.

ole_object staticmethod

ole_object(
    name: str, **options: Unpack[OleObjectOptions]
) -> OleObjectColumn

OLE Object (long binary).