orm-loader 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. orm_loader-0.1.0/PKG-INFO +160 -0
  2. orm_loader-0.1.0/README.md +149 -0
  3. orm_loader-0.1.0/pyproject.toml +35 -0
  4. orm_loader-0.1.0/src/orm_loader/__init__.py +0 -0
  5. orm_loader-0.1.0/src/orm_loader/helpers/__init__.py +22 -0
  6. orm_loader-0.1.0/src/orm_loader/helpers/bootstrap.py +13 -0
  7. orm_loader-0.1.0/src/orm_loader/helpers/bulk.py +44 -0
  8. orm_loader-0.1.0/src/orm_loader/helpers/discovery.py +9 -0
  9. orm_loader-0.1.0/src/orm_loader/helpers/errors.py +6 -0
  10. orm_loader-0.1.0/src/orm_loader/helpers/logging.py +90 -0
  11. orm_loader-0.1.0/src/orm_loader/helpers/metadata.py +15 -0
  12. orm_loader-0.1.0/src/orm_loader/helpers/sqlite.py +32 -0
  13. orm_loader-0.1.0/src/orm_loader/py.typed +0 -0
  14. orm_loader-0.1.0/src/orm_loader/registry/__init__.py +67 -0
  15. orm_loader-0.1.0/src/orm_loader/registry/registry.py +167 -0
  16. orm_loader-0.1.0/src/orm_loader/registry/validation.py +230 -0
  17. orm_loader-0.1.0/src/orm_loader/registry/validation_presets.py +14 -0
  18. orm_loader-0.1.0/src/orm_loader/registry/validation_report.py +88 -0
  19. orm_loader-0.1.0/src/orm_loader/registry/validation_runner.py +36 -0
  20. orm_loader-0.1.0/src/orm_loader/tables/__init__.py +27 -0
  21. orm_loader-0.1.0/src/orm_loader/tables/base/__init__.py +15 -0
  22. orm_loader-0.1.0/src/orm_loader/tables/base/allocators.py +22 -0
  23. orm_loader-0.1.0/src/orm_loader/tables/base/loadable_table.py +160 -0
  24. orm_loader-0.1.0/src/orm_loader/tables/base/orm_table.py +76 -0
  25. orm_loader-0.1.0/src/orm_loader/tables/base/serialisable_table.py +48 -0
  26. orm_loader-0.1.0/src/orm_loader/tables/base/typing.py +84 -0
  27. orm_loader-0.1.0/src/orm_loader/tables/data/__init__.py +9 -0
  28. orm_loader-0.1.0/src/orm_loader/tables/data/converters.py +6 -0
  29. orm_loader-0.1.0/src/orm_loader/tables/data/data_type_management.py +147 -0
  30. orm_loader-0.1.0/src/orm_loader/tables/data/ingestion.py +184 -0
@@ -0,0 +1,160 @@
1
+ Metadata-Version: 2.3
2
+ Name: orm-loader
3
+ Version: 0.1.0
4
+ Summary: Generic base classes to handle ORM functionality for multiple downstream datamodels
5
+ Author: gkennos
6
+ Author-email: gkennos <georgina.kennedy@unsw.edu.au>
7
+ Requires-Dist: pandas>=2.3.3
8
+ Requires-Dist: sqlalchemy>=2.0.45
9
+ Requires-Python: >=3.12
10
+ Description-Content-Type: text/markdown
11
+
12
+ ## orm-loader
13
+
14
+ A lightweight, reusable foundation for building and validating SQLAlchemy-based clinical (and non-clinical) data models.
15
+
16
+ This library provides general-purpose ORM infrastructure that sits below any specific data model (OMOP, PCORnet, custom CDMs, etc.), focusing on:
17
+
18
+ * declarative base configuration
19
+ * bulk ingestion patterns
20
+ * file-based validation & loading
21
+ * table introspection
22
+ * model-agnostic validation scaffolding
23
+ * safe, database-portable operational helpers
24
+
25
+ It intentionally contains no domain logic and no assumptions about a specific schema.
26
+
27
+
28
+ ### What this library provides:
29
+
30
+ This library provides a small set of composable building blocks for defining, loading, inspecting, and validating SQLAlchemy-based data models.
31
+ All components are model-agnostic and can be selectively combined in downstream libraries.
32
+
33
+ 1. A minimal, opinionated ORM table base
34
+
35
+ ORMTableBase provides structural introspection utilities for SQLAlchemy-mapped tables, without imposing any domain semantics.
36
+
37
+ It supports:
38
+ * mapper access and inspection
39
+ * primary key discovery
40
+ * required (non-nullable) column detection
41
+ * consistent primary key handling across models
42
+ * simple ID allocation helpers for sequence-less databases
43
+
44
+ ```python
45
+ from orm_loader.tables import ORMTableBase
46
+
47
+ class MyTable(ORMTableBase, Base):
48
+ __tablename__ = "my_table"
49
+
50
+ ```
51
+ This base is intended to be inherited by all ORM tables, either directly or via higher-level mixins.
52
+
53
+ 2. CSV-based ingestion mixins
54
+
55
+ CSVLoadableTableInterface adds opt-in CSV loading support for ORM tables using pandas, with a focus on correctness and scalability.
56
+
57
+ Features include:
58
+ * chunked loading for large files
59
+ * optional per-table normalisation logic
60
+ * optional deduplication against existing database rows
61
+ * safe bulk inserts using SQLAlchemy sessions
62
+
63
+ ```python
64
+ class MyTable(CSVLoadableTableInterface, ORMTableBase, Base):
65
+ __tablename__ = "my_table"
66
+
67
+ ```
68
+
69
+ Downstream models may override:
70
+ * normalise_dataframe(...)
71
+ * dedupe_dataframe(...)
72
+ * csv_columns()
73
+ to implement table-specific ingestion policies.
74
+
75
+ 3. Structured serialisation and hashing
76
+
77
+ SerialisableTableInterface adds lightweight, explicit serialisation helpers for ORM rows.
78
+
79
+ It supports:
80
+ * conversion to dictionaries
81
+ * JSON serialisation
82
+ * stable row-level fingerprints
83
+ * iterator-style access to field/value pairs
84
+
85
+ ```python
86
+ row = session.get(MyTable, 1)
87
+ row.to_dict()
88
+ row.to_json()
89
+ row.fingerprint()
90
+ ```
91
+
92
+ This is useful for:
93
+
94
+ * debugging
95
+ * auditing
96
+ * reproducibility checks
97
+ * downstream APIs or exports
98
+
99
+
100
+ 4. Model registry and validation scaffolding
101
+
102
+ The library includes model-agnostic validation infrastructure, designed to compare ORM models against external specifications.
103
+
104
+ This includes:
105
+ * a model registry
106
+ * table and field descriptors
107
+ * validator contracts
108
+ * a validation runner
109
+ * structured validation reports
110
+ Specifications can be loaded from CSV today, with support for other formats (e.g. LinkML) planned.
111
+
112
+ ```python
113
+ registry = ModelRegistry(model_version="1.0")
114
+ registry.load_table_specs(table_csv, field_csv)
115
+ registry.register_models([MyTable])
116
+
117
+ runner = ValidationRunner(validators=always_on_validators())
118
+ report = runner.run(registry)
119
+ ```
120
+
121
+ Validation output is available as:
122
+ * human-readable text
123
+ * structured dictionaries
124
+ * JSON (for CI/CD integration)
125
+ * exit codes suitable for pipelines
126
+
127
+ 5. Database bootstrap helpers
128
+ The library provides lightweight helpers for schema creation and bootstrapping, without imposing a migration strategy.
129
+
130
+ ```python
131
+ from orm_loader.metadata import Base
132
+ from orm_loader.bootstrap import bootstrap
133
+
134
+ bootstrap(engine, create=True)
135
+ ```
136
+
137
+ 6. Safe bulk-loading utilities
138
+
139
+ A reusable context manager simplifies trusted bulk ingestion workflows:
140
+ * temporarily disables foreign key checks where supported
141
+ * suppresses autoflush for performance
142
+ * ensures reliable rollback on failure
143
+
144
+ ## Summary
145
+
146
+ This library intentionally focuses on infrastructure, not semantics.
147
+
148
+ It provides:
149
+ * reusable ORM mixins
150
+ * safe ingestion patterns
151
+ * validation scaffolding
152
+ * database-portable utilities
153
+
154
+ while leaving domain rules, business logic, and schema semantics to downstream libraries.
155
+
156
+ This makes it suitable as a shared foundation for:
157
+ * clinical data models
158
+ * research data marts
159
+ * registry schemas
160
+ * synthetic data pipelines
@@ -0,0 +1,149 @@
1
+ ## orm-loader
2
+
3
+ A lightweight, reusable foundation for building and validating SQLAlchemy-based clinical (and non-clinical) data models.
4
+
5
+ This library provides general-purpose ORM infrastructure that sits below any specific data model (OMOP, PCORnet, custom CDMs, etc.), focusing on:
6
+
7
+ * declarative base configuration
8
+ * bulk ingestion patterns
9
+ * file-based validation & loading
10
+ * table introspection
11
+ * model-agnostic validation scaffolding
12
+ * safe, database-portable operational helpers
13
+
14
+ It intentionally contains no domain logic and no assumptions about a specific schema.
15
+
16
+
17
+ ### What this library provides:
18
+
19
+ This library provides a small set of composable building blocks for defining, loading, inspecting, and validating SQLAlchemy-based data models.
20
+ All components are model-agnostic and can be selectively combined in downstream libraries.
21
+
22
+ 1. A minimal, opinionated ORM table base
23
+
24
+ ORMTableBase provides structural introspection utilities for SQLAlchemy-mapped tables, without imposing any domain semantics.
25
+
26
+ It supports:
27
+ * mapper access and inspection
28
+ * primary key discovery
29
+ * required (non-nullable) column detection
30
+ * consistent primary key handling across models
31
+ * simple ID allocation helpers for sequence-less databases
32
+
33
+ ```python
34
+ from orm_loader.tables import ORMTableBase
35
+
36
+ class MyTable(ORMTableBase, Base):
37
+ __tablename__ = "my_table"
38
+
39
+ ```
40
+ This base is intended to be inherited by all ORM tables, either directly or via higher-level mixins.
41
+
42
+ 2. CSV-based ingestion mixins
43
+
44
+ CSVLoadableTableInterface adds opt-in CSV loading support for ORM tables using pandas, with a focus on correctness and scalability.
45
+
46
+ Features include:
47
+ * chunked loading for large files
48
+ * optional per-table normalisation logic
49
+ * optional deduplication against existing database rows
50
+ * safe bulk inserts using SQLAlchemy sessions
51
+
52
+ ```python
53
+ class MyTable(CSVLoadableTableInterface, ORMTableBase, Base):
54
+ __tablename__ = "my_table"
55
+
56
+ ```
57
+
58
+ Downstream models may override:
59
+ * normalise_dataframe(...)
60
+ * dedupe_dataframe(...)
61
+ * csv_columns()
62
+ to implement table-specific ingestion policies.
63
+
64
+ 3. Structured serialisation and hashing
65
+
66
+ SerialisableTableInterface adds lightweight, explicit serialisation helpers for ORM rows.
67
+
68
+ It supports:
69
+ * conversion to dictionaries
70
+ * JSON serialisation
71
+ * stable row-level fingerprints
72
+ * iterator-style access to field/value pairs
73
+
74
+ ```python
75
+ row = session.get(MyTable, 1)
76
+ row.to_dict()
77
+ row.to_json()
78
+ row.fingerprint()
79
+ ```
80
+
81
+ This is useful for:
82
+
83
+ * debugging
84
+ * auditing
85
+ * reproducibility checks
86
+ * downstream APIs or exports
87
+
88
+
89
+ 4. Model registry and validation scaffolding
90
+
91
+ The library includes model-agnostic validation infrastructure, designed to compare ORM models against external specifications.
92
+
93
+ This includes:
94
+ * a model registry
95
+ * table and field descriptors
96
+ * validator contracts
97
+ * a validation runner
98
+ * structured validation reports
99
+ Specifications can be loaded from CSV today, with support for other formats (e.g. LinkML) planned.
100
+
101
+ ```python
102
+ registry = ModelRegistry(model_version="1.0")
103
+ registry.load_table_specs(table_csv, field_csv)
104
+ registry.register_models([MyTable])
105
+
106
+ runner = ValidationRunner(validators=always_on_validators())
107
+ report = runner.run(registry)
108
+ ```
109
+
110
+ Validation output is available as:
111
+ * human-readable text
112
+ * structured dictionaries
113
+ * JSON (for CI/CD integration)
114
+ * exit codes suitable for pipelines
115
+
116
+ 5. Database bootstrap helpers
117
+ The library provides lightweight helpers for schema creation and bootstrapping, without imposing a migration strategy.
118
+
119
+ ```python
120
+ from orm_loader.metadata import Base
121
+ from orm_loader.bootstrap import bootstrap
122
+
123
+ bootstrap(engine, create=True)
124
+ ```
125
+
126
+ 6. Safe bulk-loading utilities
127
+
128
+ A reusable context manager simplifies trusted bulk ingestion workflows:
129
+ * temporarily disables foreign key checks where supported
130
+ * suppresses autoflush for performance
131
+ * ensures reliable rollback on failure
132
+
133
+ ## Summary
134
+
135
+ This library intentionally focuses on infrastructure, not semantics.
136
+
137
+ It provides:
138
+ * reusable ORM mixins
139
+ * safe ingestion patterns
140
+ * validation scaffolding
141
+ * database-portable utilities
142
+
143
+ while leaving domain rules, business logic, and schema semantics to downstream libraries.
144
+
145
+ This makes it suitable as a shared foundation for:
146
+ * clinical data models
147
+ * research data marts
148
+ * registry schemas
149
+ * synthetic data pipelines
@@ -0,0 +1,35 @@
1
+ [project]
2
+ name = "orm-loader"
3
+ version = "0.1.0"
4
+ description = "Generic base classes to handle ORM functionality for multiple downstream datamodels"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "gkennos", email = "georgina.kennedy@unsw.edu.au" }
8
+ ]
9
+ requires-python = ">=3.12"
10
+ dependencies = [
11
+ "pandas>=2.3.3",
12
+ "sqlalchemy>=2.0.45",
13
+ ]
14
+
15
+ [build-system]
16
+ requires = ["uv_build>=0.9.2,<0.10.0"]
17
+ build-backend = "uv_build"
18
+
19
+ [dependency-groups]
20
+ dev = [
21
+ "mypy>=1.19.1",
22
+ "pytest>=9.0.2",
23
+ "ruff>=0.14.11",
24
+ ]
25
+
26
+ [tool.setuptools]
27
+ packages = ["orm_loader"]
28
+
29
+ [tool.ruff]
30
+ line-length = 100
31
+ target-version = "py311"
32
+
33
+ [tool.mypy]
34
+ python_version = "3.11"
35
+ strict = true
File without changes
@@ -0,0 +1,22 @@
1
+ from .errors import IngestError, ValidationError
2
+ from .logging import get_logger, configure_logging
3
+ from .bootstrap import bootstrap, create_db
4
+ from .sqlite import enable_sqlite_foreign_keys, explain_sqlite_fk_error
5
+ from .bulk import bulk_load_context
6
+ from .metadata import Base
7
+ from .discovery import get_model_by_tablename
8
+
9
+
10
+ __all__ = [
11
+ "IngestError",
12
+ "ValidationError",
13
+ "get_logger",
14
+ "configure_logging",
15
+ "bootstrap",
16
+ "create_db",
17
+ "enable_sqlite_foreign_keys",
18
+ "explain_sqlite_fk_error",
19
+ "bulk_load_context",
20
+ "Base",
21
+ "get_model_by_tablename",
22
+ ]
@@ -0,0 +1,13 @@
1
+ from .metadata import Base
2
+ import logging
3
+
4
+ logger = logging.getLogger(__name__)
5
+
6
+ def create_db(engine):
7
+ logger.debug("Creating database schema")
8
+ Base.metadata.create_all(engine)
9
+
10
+ def bootstrap(engine, *, create: bool = True):
11
+ logger.info("Bootstrapping schema (create=%s)", create)
12
+ if create:
13
+ create_db(engine)
@@ -0,0 +1,44 @@
1
+ from contextlib import contextmanager
2
+ from sqlalchemy import text
3
+ from sqlalchemy.orm import Session
4
+
5
+ @contextmanager
6
+ def bulk_load_context(
7
+ session: Session,
8
+ *,
9
+ disable_fk: bool = True,
10
+ no_autoflush: bool = True,
11
+ ):
12
+ engine = session.get_bind()
13
+ dialect = engine.dialect.name
14
+ fk_disabled = False
15
+
16
+ try:
17
+ if disable_fk:
18
+ if dialect == "postgresql":
19
+ session.execute(text(
20
+ "SET session_replication_role = replica"
21
+ ))
22
+ fk_disabled = True
23
+ elif dialect == "sqlite":
24
+ session.execute(text("PRAGMA foreign_keys = OFF"))
25
+ fk_disabled = True
26
+
27
+ if no_autoflush:
28
+ with session.no_autoflush:
29
+ yield
30
+ else:
31
+ yield
32
+
33
+ except Exception:
34
+ session.rollback()
35
+ raise
36
+
37
+ finally:
38
+ if fk_disabled:
39
+ if dialect == "postgresql":
40
+ session.execute(text(
41
+ "SET session_replication_role = DEFAULT"
42
+ ))
43
+ elif dialect == "sqlite":
44
+ session.execute(text("PRAGMA foreign_keys = ON"))
@@ -0,0 +1,9 @@
1
+ from typing import Type
2
+ from .metadata import Base
3
+
4
+ def get_model_by_tablename(tablename: str) -> Type | None:
5
+ tablename = tablename.lower().strip()
6
+ for cls in Base.__subclasses__():
7
+ if getattr(cls, "__tablename__", None) == tablename:
8
+ return cls
9
+ return None
@@ -0,0 +1,6 @@
1
+ class IngestError(Exception):
2
+ """Raised when ingestion fails for structural or runtime reasons."""
3
+
4
+
5
+ class ValidationError(Exception):
6
+ """Raised when schema or specification validation fails."""
@@ -0,0 +1,90 @@
1
+ from __future__ import annotations
2
+ import logging
3
+ from typing import Literal, Optional
4
+ import re
5
+
6
+ SENSITIVE_KEYS = {
7
+ "password",
8
+ "passwd",
9
+ "secret",
10
+ "token",
11
+ "key",
12
+ "dsn",
13
+ "uri",
14
+ "url",
15
+ }
16
+ LOGGING_NAMESPACE = "sql_loader"
17
+
18
+ def _coerce_log_level(level: int | str) -> int:
19
+ if isinstance(level, int):
20
+ return level
21
+
22
+ if isinstance(level, str):
23
+ s = level.strip().upper()
24
+ if s.isdigit():
25
+ return int(s)
26
+
27
+ mapping = logging.getLevelNamesMapping()
28
+ if s in mapping:
29
+ return mapping[s]
30
+
31
+ raise ValueError(f"Invalid log level: {level!r}")
32
+
33
+ raise TypeError(f"Invalid log level type: {type(level)}")
34
+
35
+
36
+ def get_logger(name: Optional[str] = None) -> logging.Logger:
37
+ """
38
+ Return a namespaced logger.
39
+
40
+ Examples:
41
+ get_logger() -> sql_loader
42
+ get_logger("loadable_table") -> sql_loader.loadable_table
43
+ """
44
+ full_name = LOGGING_NAMESPACE if name is None else f"{LOGGING_NAMESPACE}.{name}"
45
+ return logging.getLogger(full_name)
46
+
47
+
48
+ class RedactingFormatter(logging.Formatter):
49
+ def __init__(self, *args, **kwargs):
50
+ super().__init__(*args, **kwargs)
51
+ self._pattern = re.compile(
52
+ r"(?i)\\b(" + "|".join(SENSITIVE_KEYS) + r")\\b\\s*[:=]\\s*[^\\s,;]+"
53
+ )
54
+
55
+ def format(self, record):
56
+ msg = super().format(record)
57
+ return self._pattern.sub(r"\\1=<REDACTED>", msg)
58
+
59
+ def configure_logging(
60
+ *,
61
+ level: int | str = logging.INFO,
62
+ handler: Optional[logging.Handler] = None,
63
+ format: Optional[str] = None,
64
+ propagate: bool = True,
65
+ redact: bool = True,
66
+ ) -> None:
67
+ """
68
+ Enable logging output for omop_alchemy.
69
+
70
+ Safe to call multiple times.
71
+ """
72
+ logger = get_logger()
73
+ logger.setLevel(_coerce_log_level(level))
74
+
75
+ if handler is None:
76
+ handler = logging.StreamHandler()
77
+
78
+ if format is None:
79
+ format = "%(asctime)s | %(levelname)-8s | %(name)s | %(message)s"
80
+
81
+ formatter_cls = RedactingFormatter if redact else logging.Formatter
82
+ handler.setFormatter(formatter_cls(format))
83
+
84
+ if not any(isinstance(h, type(handler)) for h in logger.handlers):
85
+ logger.addHandler(handler)
86
+
87
+ logger.propagate = propagate
88
+
89
+
90
+ logging.getLogger(LOGGING_NAMESPACE).addHandler(logging.NullHandler())
@@ -0,0 +1,15 @@
1
+ from sqlalchemy import MetaData
2
+ from sqlalchemy.orm import DeclarativeBase
3
+
4
+ NAMING_CONVENTIONS = {
5
+ "ix": "ix_%(column_0_label)s",
6
+ "uq": "uq_%(table_name)s_%(column_0_name)s",
7
+ "ck": "ck_%(table_name)s_%(constraint_name)s",
8
+ "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
9
+ "pk": "pk_%(table_name)s",
10
+ }
11
+
12
+ metadata = MetaData(naming_convention=NAMING_CONVENTIONS)
13
+
14
+ class Base(DeclarativeBase):
15
+ metadata = metadata
@@ -0,0 +1,32 @@
1
+ from sqlalchemy import event, text
2
+ from sqlalchemy.engine import Engine
3
+ from sqlalchemy.exc import IntegrityError
4
+ import logging
5
+
6
+ logger = logging.getLogger(__name__)
7
+
8
+ @event.listens_for(Engine, "connect")
9
+ def enable_sqlite_foreign_keys(dbapi_connection, connection_record):
10
+ if dbapi_connection.__class__.__module__.startswith("sqlite3"):
11
+ logger.debug("Enabling SQLite foreign key enforcement")
12
+ cursor = dbapi_connection.cursor()
13
+ cursor.execute("PRAGMA defer_foreign_keys = ON;")
14
+ cursor.close()
15
+
16
+ def explain_sqlite_fk_error(session, exc: IntegrityError, raise_error: bool = True):
17
+ engine = session.get_bind()
18
+ if engine.dialect.name != "sqlite":
19
+ raise exc
20
+
21
+ with engine.connect() as conn:
22
+ rows = conn.execute(text("PRAGMA foreign_key_check")).fetchall()
23
+
24
+ if rows:
25
+ for r in rows:
26
+ logger.error(
27
+ "FK violation: table=%s rowid=%s references=%s fk_index=%s",
28
+ r[0], r[1], r[2], r[3]
29
+ )
30
+
31
+ if raise_error:
32
+ raise exc
File without changes
@@ -0,0 +1,67 @@
1
+ from .registry import ModelRegistry, ModelDescriptor, TableSpec, FieldSpec
2
+ from .validation_report import ValidationIssue, SeverityLevel
3
+ from .validation import Validator
4
+ from .validation_runner import ValidationRunner
5
+ from .validation_presets import always_on_validators
6
+
7
+ __all__ = [
8
+ "ModelRegistry",
9
+ "ModelDescriptor",
10
+ "TableSpec",
11
+ "FieldSpec",
12
+ "Validator",
13
+ "ValidationIssue",
14
+ "SeverityLevel",
15
+ "ValidationRunner",
16
+ "always_on_validators",
17
+ ]
18
+
19
+
20
+ """
21
+ Usage example:
22
+
23
+ registry = ModelRegistry(
24
+ model_version="5.4",
25
+ model_name="OMOP",
26
+ )
27
+
28
+ registry.load_table_specs(
29
+ table_csv=Path("specs/CDM_TABLE.csv"),
30
+ field_csv=Path("specs/CDM_FIELD.csv"),
31
+ )
32
+
33
+ registry.register_models([
34
+ Person,
35
+ VisitOccurrence,
36
+ ])
37
+
38
+ OR
39
+
40
+ registry.discover_models('omop_alchemy.cdm.model')
41
+
42
+ class MyCustomValidator:
43
+ def validate(self, *, model, spec=None, fields=None) -> list[ValidationIssue
44
+ # Custom validation logic here
45
+ return []
46
+
47
+ validators = always_on_validators() + [MyCustomValidator()]
48
+ runner = ValidationRunner(
49
+ validators=validators,
50
+ fail_fast=False,
51
+ )
52
+
53
+ report = runner.run(registry)
54
+
55
+ ### locally inspect report ###
56
+ print(report.summary())
57
+
58
+ if not report.is_valid():
59
+ print(report.render_text_report())
60
+
61
+
62
+ ### use in CI/CD pipeline ###
63
+
64
+ print(report.to_json())
65
+ sys.exit(report.exit_code())
66
+
67
+ """