db.schemas.schema

emtellipro.db.schemas.schema

Module defining base functions and classes for implementing a schema

Module Contents

Classes

NameDescription
SchemaManifestRepresentation of a database schema, containing the SQLAlchemy metadata object, and the module implementing it.
SaveDocumentThis stores references to the input document and annotated document pair that should be passed to the save() method in each schema.
SaveOptionsBase class for the save options for each save function.

Functions

NameDescription
save_options_replaceReplace the attributes of options with matching values from replacements.

Data

SaveOptionsType

API

emtellipro.db.schemas.schema.SchemaManifest

class emtellipro.db.schemas.schema.SchemaManifest

Bases: object

Representation of a database schema, containing the SQLAlchemy metadata object, and the module implementing it.

Authors of schemas must provide an object that is an instance of this class (or a subclass). This class itself can be instantiated, but if some of the properties need to be overridden, then a subclass will be necessary.

Initialization
__init__(*, name, models, migrations=None, save, save_options=None)
SchemaManifest.name
name: str

The name of the schema. This should match the entry-point definition.

SchemaManifest.models
models: typing.Any

The module containing the SQLAlchemy ORM models.

SchemaManifest.migrations
migrations: typing.Any | None

The migrations module. This can be None if the schema doesn’t support migrations.

Value: None

SchemaManifest.save
save: typing.Callable

Callable that takes in the documents to store.

SchemaManifest.save_options
save_options: type | None

The SaveOptions class that can be passed to the save function. If not passed explictly when instantiating SchemaManifest, it will be discovered by inspecting the type annotation for the save() function’s options parameter.

Value: None

SchemaManifest.__post_init__
__post_init__()
SchemaManifest.metadata
property metadata

The base SQLAlchemy metadata

SchemaManifest.alembic_config
property alembic_config: alembic.config.Config

Path to alembic config file.

Return type: Config

SchemaManifest.tables
property tables

The list of tables in the SQLAlchemy metadata object.

emtellipro.db.schemas.schema.SaveDocument

class emtellipro.db.schemas.schema.SaveDocument

Bases: object

This stores references to the input document and annotated document pair that should be passed to the save() method in each schema.

Initialization
__init__(annotated, input=None)
SaveDocument.annotated
annotated: emtellipro.data.AnnotatedDocument

Type: AnnotatedDocument

The annotated document to save.

SaveDocument.input
input: emtellipro.data.InputDocument | None

Type: InputDocument | None

Optional input document. Some save functions may not require this, but some do to compute things like annotation texts when emtelliPro did not return it.

Value: None

SaveDocument.text
property text

emtellipro.db.schemas.schema.SaveOptions

class emtellipro.db.schemas.schema.SaveOptions

Bases: object

Base class for the save options for each save function.

emtellipro.db.schemas.schema.SaveOptionsType

emtellipro.db.schemas.schema.SaveOptionsType

Value: TypeVar(...)

emtellipro.db.schemas.schema.save_options_replace

emtellipro.db.schemas.schema.save_options_replace(
options: emtellipro.db.schemas.schema.SaveOptionsType, **replacements
) -> emtellipro.db.schemas.schema.SaveOptionsType

Replace the attributes of options with matching values from replacements.

Parameters:

options
emtellipro.db.schemas.schema.SaveOptionsType

The SaveOptions subclass instance from some schema.

**replacements

Attributes to replace in the options instance. Only keys which match attributes of the options object will be used; any other keys will be ignored.

Returns:

A new instance of the same type as options, with changed attributes.

Return type: SaveOptionsType