Skip to main content

iris_persistence

Python models, object persistence, queries, and managed schema for InterSystems IRIS. Python owns declared class members; the IRIS compiler owns generated storage and runtime methods.

1. Define a model and configure the runtime

from iris_persistence import Field, Index, Model


class Person(Model, persistent=True):
    Name: str = Field(required=True, max_length=120)
    Age: int | None = None

    class Meta:
        classname = "App.Person"
        mode = "managed"
        indexes = [Index("NameIdx", properties="Name")]

Embedded Python discovers IRIS automatically. Native Python supplies its connection through the same normalized runtime boundary:

from iris_persistence import RuntimeConfig, configure_runtime

configure_runtime(RuntimeConfig(native_connection=connection))

Application and domain code uses the same model API in both environments. It does not inspect the selected backend or wrapper state.

2. Manage schema

Preview and apply the Python-owned schema through the model:

diff = Person.diff_schema()
Person.sync_schema()

# Equivalent preview form
assert Person.sync_schema(dry_run=True) == Person.diff_schema()

managed adds, updates, and removes Python-owned properties, indexes, and parameters without deleting the class. IRIS generates and evolves Storage Default when compiling the class. observe never changes IRIS and is intended for existing or scaffolded classes.

For creation-time physical locations, managed models can declare StorageTuning:

from iris_persistence import StorageTuning


class Meta:
    mode = "managed"
    storage_tuning = StorageTuning(
        data_location="^App.PersonD",
        id_location="^App.PersonD",
        index_location="^App.PersonI",
    )

Existing populated storage is never relocated by ordinary schema synchronization. A conflicting location raises StorageMigrationRequired before mutation.

3. Persist and query objects

person = Person(Name="Ada", Age=36)
person.save()

loaded = Person.get(person.pk)
loaded.Name = "Ada Lovelace"
loaded.save()

matches = Person.where(Name="Ada Lovelace").order_by("Name").all()
deleted = loaded.delete()

save() calls IRIS %Save(), get() opens by ID, query methods use the compiled SQL projection, and delete() removes the persistent object. CRUD does not rewrite schema unless Meta.auto_sync=True was explicitly selected.

IRIS handles can be converted explicitly with Model.to_iris() and Model.from_iris(). The old root materialize() and from_iris() wrappers are deprecated and will be removed in 0.4.0.

4. Optional operational tooling

The package includes operational capabilities, but they are intentionally imported from explicit secondary namespaces rather than the core package root.

Reviewed migrations

from iris_persistence.migrations import apply_plan, create_plan, verify_plan

plan = create_plan([Person], target_revision="001-person")
for operation in plan.operations:
    print(operation.safety, operation.op_type, operation.path)

result = apply_plan(plan)
assert verify_plan(plan).converged

apply_plan() is explicit authorization to apply a reviewed plan and writes a backup before mutation. Blocked physical-storage changes remain rejected. The iris-persistence migration CLI continues to expose the same commands.

Reverse scaffolding

from iris_persistence.scaffold import scaffold_from_iris

scaffold_from_iris("App.*", "./generated")

Generated models observe IRIS by default. Storage extraction is an expert option and emits explicit imports from iris_persistence.advanced_storage.

Expert storage operations

Complete custom storage definitions, optimizer statistics, inspection, and relocation helpers are expert APIs:

from iris_persistence.advanced_storage import (
    StorageProperty,
    inspect_existing_storage,
    tune_existing_storage_statistics,
)

These APIs operate on writable dictionary definitions and enforce storage safety rules. Physical relocation requires a maintenance/copy/validation/cutover workflow; it is not an in-place tuning operation. See advanced schema mapping and the runnable storage statistics and relocation examples.

Compatibility and architecture

The 0.3.0 compatibility window supports old root imports for migrations and scaffolding with a DeprecationWarning. Canonical module imports are unchanged. The aliases are removed in 0.4.0.

Development

.venv/bin/ruff check .
.venv/bin/mypy iris_persistence
.venv/bin/pytest -m "not integration"
.venv/bin/pytest -m integration

Generated model execution is a private optimization guarded by a reproducible Embedded and Native benchmark. See the benchmark gate.

Metadata

Release files for iris-persistence 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iris-persistence 0.3.0
File Size Uploaded
iris_persistence-0.3.0.tar.gz 3.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for iris-persistence 0.3.0
File Interpreter ABI Platform
iris_persistence-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 3.2 MB

Release files / iris_persistence-0.3.0.tar.gz

Download URL iris_persistence-0.3.0.tar.gz
Size 3.1 MB
Tags Source
SHA-256 checksum
How to use checksums
da95a9a27d75753a1b5684210bf091dc1a898e4492dbe9efd36881f380c9d488
BLAKE2b-256 checksum
How to use checksums
bf83acb0bd03e653bce72ea0cea4edc4c86656b2f5fd388b7c8b6f67e71e0f20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release files / iris_persistence-0.3.0-py3-none-any.whl

Download URL iris_persistence-0.3.0-py3-none-any.whl
Size 76.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42647871403ff2f6f66004324a45d40fac913cdec8de0cf2dad4f6d058640a86
BLAKE2b-256 checksum
How to use checksums
9284f9fcadcc999d20cce2b5ae1194c6013b2708df1666e1efa048df85ebfafc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page