Skip to content

pyaccesskit.tables

pyaccesskit.tables

Tables, fields and indexes: the db.tables collection and its handles.

Field

Field(session: Session, table: Table, name: str)

A column of a table (a live, name-based handle).

name property

name: str

The field name.

spec property

spec: ColumnBase

The current definition of the field.

data_type property

data_type: DataType

The Access data type.

size property

size: int | None

Text length for Short Text fields, else None.

required property

required: bool

Whether Null is disallowed.

properties property

properties: PropertyBag

The field's DAO properties.

rename

rename(new_name: str) -> None

Rename the field.

drop

drop() -> None

Delete the field.

FieldCollection

FieldCollection(session: Session, table: Table)

The fields of a table, in order.

names

names() -> list[str]

Field names in order.

Table

Table(session: Session, name: str)

A table (a live, name-based handle). to_spec() returns an immutable snapshot.

name property

name: str

The table name.

fields property

fields: FieldCollection

The table's fields.

indexes property

indexes: tuple[IndexSpec, ...]

The table's indexes (excluding the hidden ones owned by relationships).

primary_key property

primary_key: IndexSpec | None

The primary-key index, if any.

description property writable

description: str | None

The table Description.

is_linked property

is_linked: bool

Whether this is a linked table.

connect property

connect: str | None

A linked table's connection string (None for local tables). It may contain credentials.

source_table property

source_table: str | None

A linked table's name in its source database (None for local tables).

is_system property

is_system: bool

Whether this is a system table (MSys*).

properties property

properties: PropertyBag

The table's DAO properties.

to_spec

to_spec() -> TableSpec

The table's current definition as a normalized :class:TableSpec.

record_count

record_count() -> int

Number of rows (runs SELECT COUNT(*)).

add_column

add_column(column: ColumnSpec) -> Field

Append a column (unique=/indexed=/primary_key= also create the index).

drop_column

drop_column(name: str) -> None

Delete a column (drop its indexes and relationships first).

rename_column

rename_column(old: str, new: str) -> None

Rename a column.

create_index

create_index(index: IndexSpec) -> None

Create an index.

drop_index

drop_index(name: str) -> None

Delete an index.

rename

rename(new_name: str) -> None

Rename the table.

drop

drop(*, drop_relationships: bool = False) -> None

Delete the table (with drop_relationships=True, its relationships first).

TableCollection

TableCollection(session: Session)

db.tables: every local and linked table (system tables are hidden unless asked for).

names

names(*, include_system: bool = False) -> list[str]

Table names.

get

get(name: str) -> Table | None

The table called name (case-insensitive), or None.

create

create(spec: TableSpec) -> Table
create(
    name: str,
    /,
    *,
    columns: Sequence[ColumnSpec],
    indexes: Sequence[IndexSpec] = (),
    primary_key: Sequence[str] | str | None = None,
    description: str | None = None,
    validation_rule: str | None = None,
    validation_text: str | None = None,
    properties: Mapping[str, PropertyValue] | None = None,
) -> Table
create(
    spec_or_name: TableSpec | str,
    /,
    *,
    columns: Sequence[ColumnSpec] | None = None,
    indexes: Sequence[IndexSpec] = (),
    primary_key: Sequence[str] | str | None = None,
    description: str | None = None,
    validation_rule: str | None = None,
    validation_text: str | None = None,
    properties: Mapping[str, PropertyValue] | None = None,
) -> Table

Create a table from a :class:TableSpec or from keyword arguments.

Creation is atomic: if any step fails, the partially created table is removed.

drop

drop(
    name: str, *, drop_relationships: bool = False
) -> None

Delete a table.

specs

specs() -> list[TableSpec]

Specs of every (non-system, non-linked) table.