> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.emtelligent.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.emtelligent.com/_mcp/server.

# db.schemas.schema

Module defining base functions and classes for implementing a schema

## Module Contents

### Classes

| Name                                                         | Description                                                                                                                           |
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| [`SchemaManifest`](#emtelliprodbschemasschemaschemamanifest) | Representation of a database schema, containing the SQLAlchemy metadata object, and the module implementing it.                       |
| [`SaveDocument`](#emtelliprodbschemasschemasavedocument)     | This stores references to the input document and annotated document pair that should be passed to the `save()` method in each schema. |
| [`SaveOptions`](#emtelliprodbschemasschemasaveoptions)       | Base class for the save options for each save function.                                                                               |

### Functions

| Name                                                                     | Description                                                                   |
| ------------------------------------------------------------------------ | ----------------------------------------------------------------------------- |
| [`save_options_replace`](#emtelliprodbschemasschemasave_options_replace) | Replace the attributes of `options` with matching values from `replacements`. |

### Data

`SaveOptionsType`

### API

#### `emtellipro.db.schemas.schema.SchemaManifest`

```python
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

```python
__init__(*, name, models, migrations=None, save, save_options=None)
```

##### `SchemaManifest.name`

```python
name: str
```

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

##### `SchemaManifest.models`

```python
models: typing.Any
```

The module containing the SQLAlchemy ORM models.

##### `SchemaManifest.migrations`

```python
migrations: typing.Any | None
```

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

**Value**: `None`

##### `SchemaManifest.save`

```python
save: typing.Callable
```

Callable that takes in the documents to store.

##### `SchemaManifest.save_options`

```python
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__`

```python
__post_init__()
```

##### `SchemaManifest.metadata`

```python
property metadata
```

The base SQLAlchemy metadata

##### `SchemaManifest.alembic_config`

```python
property alembic_config: alembic.config.Config
```

Path to alembic config file.

**Return type:** `Config`

##### `SchemaManifest.tables`

```python
property tables
```

The list of tables in the SQLAlchemy metadata object.

#### `emtellipro.db.schemas.schema.SaveDocument`

```python
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

```python
__init__(annotated, input=None)
```

##### `SaveDocument.annotated`

```python
annotated: emtellipro.data.AnnotatedDocument
```

**Type:** [`AnnotatedDocument`](/nlp/python/reference/data#emtelliprodataannotateddocument)

The annotated document to save.

##### `SaveDocument.input`

```python
input: emtellipro.data.InputDocument | None
```

**Type:** [`InputDocument`](/nlp/python/reference/data#emtelliprodatainputdocument) | 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`

```python
property text
```

#### `emtellipro.db.schemas.schema.SaveOptions`

```python
class emtellipro.db.schemas.schema.SaveOptions
```

**Bases:** object

Base class for the save options for each save function.

#### `emtellipro.db.schemas.schema.SaveOptionsType`

```python
emtellipro.db.schemas.schema.SaveOptionsType
```

**Value**: `TypeVar(...)`

#### `emtellipro.db.schemas.schema.save_options_replace`

```python
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`](/nlp/python/reference/db-schemas-schema#emtelliprodbschemasschemasaveoptionstype)