lumix.utils.orm.LXORMModel

class lumix.utils.orm.LXORMModel(*args, **kwargs)[source]

Structural protocol for any ORM model.

This protocol defines the minimal interface that an ORM model must satisfy to be used with LumiX. Any class with an ‘id’ attribute automatically satisfies this protocol through structural typing.

The protocol is runtime-checkable, meaning you can use isinstance() to verify if an object satisfies the protocol at runtime.

id

Unique identifier for the model instance. Can be any type (int, str, UUID, etc.)

Examples

SQLAlchemy model automatically satisfies the protocol:

from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Product(Base):
    __tablename__ = 'products'
    id = Column(Integer, primary_key=True)
    name = Column(String)

# Product automatically satisfies LXORMModel
assert isinstance(Product(), LXORMModel)

Plain dataclass also works:

from dataclasses import dataclass

@dataclass
class Customer:
    id: int
    name: str

# Customer satisfies the protocol
assert isinstance(Customer(1, "Alice"), LXORMModel)

Note

This is a structural Protocol (PEP 544), not a base class. You don’t need to inherit from it - any object with an ‘id’ attribute satisfies it.

__init__(*args, **kwargs)

Methods

__init__(*args, **kwargs)

Attributes

id

id: Any
__init__(*args, **kwargs)