ORIONIS API REFERENCE

THE ORIONIS API

Build with clarity.

Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.

class documentation

Define active-record models and persist them through the query builder.

Concrete models declare their columns with the fluent schema types and interact with the database exclusively through the Orionis query builder; the underlying SQL engine never surfaces. Class-level entry points such as where or orderBy start a builder implicitly.

Class Method _newFromDatabase Hydrate a model instance from a database row.
Class Method addGlobalScope Register a constraint applied to every query of this model.
Async Class Method all Retrieve every row of the model table.
Async Class Method create Create, persist, and return a new model.
Async Class Method destroy Delete the models matching the given primary keys.
Async Class Method find Retrieve a model by its primary key.
Async Class Method findOrFail Retrieve a model by primary key or raise when absent.
Async Class Method first Retrieve the first row of the model table.
Async Class Method firstOrFail Retrieve the first row or raise when the table is empty.
Class Method freshTimestamp Produce the current timestamp for persistence operations.
Class Method getConnection Resolve the connection configured for this model.
Class Method newUniqueId Produce a client-generated primary key value.
Class Method query Start a new query builder bound to this model.
Class Method removeGlobalScope Unregister a previously added global scope.
Method __getattr__ Serve column values and accessor-backed attributes.
Method __init__ Initialize a new, unsaved model instance.
Method __repr__ Return a concise developer representation of the model.
Method __setattr__ Route column assignments into the attribute store.
Async Method _performForceDelete Remove the persisted row permanently.
Async Method _performInsert Insert the model attributes as a new row.
Async Method _performUpdate Write the dirty attributes of an existing model.
Method _persistenceConnection Keep a hydrated row's writes on the connection that supplied it.
Method _primaryKeyValue Return the primary key value identifying the stored row.
Async Method delete Delete the model row, honoring soft deletes when enabled.
Async Method save Persist the model, inserting or updating as appropriate.
Async Method update Mass assign the given attributes and persist the model.
Constant CREATED_AT Timestamp column names, overridable per model.
Constant DELETED_AT deleted_at.
Constant UPDATED_AT updated_at.
Class Variable __abstract__ Abstract flag used by Model.
Class Variable __meta__ Metadata attached by the metaclass.
Class Variable __slots__ Declare the instance attribute slots reserved by this class.
Class Variable appends Accessor-backed attributes added to the serialized output.
Class Variable casts Attribute casts applied on hydration and assignment.
Class Variable connection Named connection; the default connection is used when None.
Class Variable fillable Mass assignment whitelist; every column is fillable when empty.
Class Variable guarded Mass assignment blacklist; supports the "*" wildcard.
Class Variable hidden Attributes omitted from serialization.
Class Variable incrementing Whether the primary key is generated by the database.
Class Variable primary_key Primary key name; discovered from column flags when None.
Class Variable soft_deletes Whether deletes stamp a column instead of removing the row.
Class Variable table Logical table name; derived from the class name when None.
Class Variable table_definition Versioned table definition shared with schema migrations.
Class Variable timestamps Whether creation/update timestamps are maintained automatically.
Class Variable uuids Whether the primary key is a client-generated unique identifier.
Instance Variable _changes Changes produced by deepcopy.
Instance Variable _exists Exists flag used by Model.

Inherited from AttributesMixin:

Method exclude Return every attribute except the given keys.
Method fill Mass assign the given attributes honoring the assignment rules.
Method getAttribute Return a single attribute value through its accessor.
Method hasAccessor Report whether an attribute is served by an accessor.
Method only Return a subset of attributes limited to the given keys.
Method serialize Serialize the model for collection-level serialization.
Method setAttribute Assign a single attribute applying its mutator and cast.
Method toDict Serialize the visible attributes into a dictionary.
Method toJson Serialize the visible attributes into a JSON string.

Inherited from StateMixin (via AttributesMixin):

Method getChanges Return the attributes persisted by the last save operation.
Method getDirty Return the attributes modified since the last sync.
Method getOriginal Return the original attribute snapshot or a single original value.
Method isClean Report whether no attribute changed since the last sync.
Method isDirty Report whether any attribute changed since the last sync.
Method syncOriginal Snapshot the current attributes as the new original state.
Method wasChanged Report whether the last save operation changed any attribute.

Inherited from EventsMixin (via AttributesMixin, StateMixin):

Class Method flushEvents Remove registered listeners from the model.
Class Method observe Register every lifecycle method exposed by an observer.
Class Method registerEvent Register a listener for a model lifecycle event.
Async Method fireEvent Dispatch a lifecycle event to its listeners.

Inherited from SoftDeletesMixin (via AttributesMixin, StateMixin, EventsMixin):

Async Method _performSoftDelete Stamp the soft delete column of the persisted row.
Async Method forceDelete Delete the row permanently, ignoring soft deletes.
Async Method restore Bring a soft deleted row back by clearing its delete stamp.
Method trashed Report whether the instance is currently soft deleted.
def _newFromDatabase(cls: type[Self], row: dict[str, Any]) -> Self: (source)

Hydrate a model instance from a database row.

Parameters
row:dictRaw row values keyed by column name. The mapping is not shared with any other caller, so it is adopted and mutated in place instead of being copied.
Returns
orionis.orm.ModelExisting model instance with casts applied.
def addGlobalScope(cls: type[Self], name: str, scope: Callable[[ModelQueryBuilder[Self]], None]) -> type[Self]: (source)

Register a constraint applied to every query of this model.

Parameters
name:strName the scope is registered under, used to disable it later with withoutGlobalScope.
scope:collections.abc.CallableCallable receiving the builder and constraining it in place.
Returns
typeThe model class, enabling fluent chaining.
async def all(cls: type[Self]) -> Collection[Self]: (source)

Retrieve every row of the model table.

Returns
collections.abc.CollectionCollection of hydrated model instances.
async def create(cls: type[Self], attributes: dict[str, Any]) -> Self: (source)

Create, persist, and return a new model.

Parameters
attributes:dictAttributes to mass assign honoring the fillable rules.
Returns
orionis.orm.ModelModel instance, left unsaved if a before-write listener vetoes it.
Raises
orionis.orm.exceptions.MassAssignmentExceptionIf an attribute violates the mass assignment rules.
orionis.database.QueryExceptionIf the insert statement fails.
async def destroy(cls: type[Self], *keys: Any) -> int: (source)

Delete the models matching the given primary keys.

Parameters
*keys:typing.AnyPrimary key values to delete.
Returns
intNumber of deleted rows.
async def find(cls: type[Self], key: Any) -> Self | None: (source)

Retrieve a model by its primary key.

Parameters
key:typing.AnyPrimary key value to look up.
Returns
orionis.orm.Model or NoneMatching model, or None when absent.
async def findOrFail(cls: type[Self], key: Any) -> Self: (source)

Retrieve a model by primary key or raise when absent.

Parameters
key:typing.AnyPrimary key value to look up.
Returns
orionis.orm.ModelMatching model.
Raises
orionis.orm.exceptions.ModelNotFoundExceptionIf no record matches the key.
async def first(cls: type[Self]) -> Self | None: (source)

Retrieve the first row of the model table.

Returns
orionis.orm.Model or NoneFirst model, or None when the table is empty.
async def firstOrFail(cls: type[Self]) -> Self: (source)

Retrieve the first row or raise when the table is empty.

Returns
orionis.orm.ModelFirst model.
Raises
orionis.orm.exceptions.ModelNotFoundExceptionIf the table has no rows.
def freshTimestamp(cls: type[Self]) -> datetime: (source)

Produce the current timestamp for persistence operations.

Persistence normalizes this instant to UTC for each target column.

Returns
datetime.datetimeCurrent timestamp in the application timezone.
def getConnection(cls: type[Self]) -> IConnection: (source)

Resolve the connection configured for this model.

Returns
orionis.database.contracts.IConnectionConnection used for model queries and persistence.
Raises
orionis.orm.exceptions.OrmConfigurationExceptionIf no connection manager has been installed.
orionis.database.ConnectionNotFoundExceptionIf the configured connection is not declared.
def newUniqueId(cls: type[Self]) -> Any: (source)

Produce a client-generated primary key value.

Overridable by models needing a different identifier scheme, such as ULIDs or prefixed keys.

Returns
typing.AnyFresh unique identifier.
def query(cls: type[Self]) -> ModelQueryBuilder[Self]: (source)

Start a new query builder bound to this model.

Returns
orionis.orm.query.ModelQueryBuilderFresh builder targeting the model table.
def removeGlobalScope(cls: type[Self], name: str) -> type[Self]: (source)

Unregister a previously added global scope.

Parameters
name:strName the scope was registered under.
Returns
typeThe model class, enabling fluent chaining.
def __getattr__(self: Self, key: str) -> Any: (source)

Serve column values and accessor-backed attributes.

Parameters
key:strAttribute name being accessed.
Returns
typing.AnyAttribute value; None for declared but unloaded columns.
Raises
AttributeErrorIf the name is neither loaded, a declared column, nor an accessor-backed attribute.
def __init__(self: Self, attributes: dict[str, Any] | None = None): (source)

Initialize a new, unsaved model instance.

Parameters
attributes:dict or None, optionalAttributes to mass assign honoring the fillable rules.
Returns
NoneNo return value.
Raises
orionis.orm.exceptions.MassAssignmentExceptionIf an attribute violates the mass assignment rules.
def __repr__(self: Self) -> str: (source)

Return a concise developer representation of the model.

Returns
strRepresentation including the class name and primary key.
def __setattr__(self: Self, key: str, value: Any): (source)

Route column assignments into the attribute store.

Parameters
key:strAttribute name being assigned.
value:typing.AnyValue to assign.
Returns
NoneNo return value.
async def _performForceDelete(self: Self) -> bool: (source)

Remove the persisted row permanently.

Returns
boolTrue when a row was removed.
Raises
orionis.database.QueryExceptionIf the statement fails to execute.
async def _performInsert(self: Self) -> bool: (source)

Insert the model attributes as a new row.

Returns
boolTrue when the insert succeeds.
Raises
orionis.database.QueryExceptionIf the statement fails to execute.
async def _performUpdate(self: Self) -> bool: (source)

Write the dirty attributes of an existing model.

Returns
boolTrue when a row was written or nothing changed, False when no stored row matched the primary key.
Raises
orionis.database.QueryExceptionIf the statement fails to execute.
def _persistenceConnection(self: Self) -> IConnection: (source)

Keep a hydrated row's writes on the connection that supplied it.

New instances use the overridable class connection hook. Models hydrated by a query retain that query's connection, including explicit overrides.

Returns
orionis.database.contracts.IConnectionConnection owning the stored row, or the class-selected connection.
def _primaryKeyValue(self: Self) -> Any: (source)

Return the primary key value identifying the stored row.

The original value is preferred so a dirty primary key still targets the persisted row.

Returns
typing.AnyPrimary key value.
async def delete(self: Self) -> bool: (source)

Delete the model row, honoring soft deletes when enabled.

Models declaring soft_deletes stamp their delete column instead of removing the row; every other model is deleted permanently.

Returns
boolTrue when a row was deleted or stamped, False for unsaved models, missing rows, or a listener veto.
Raises
orionis.database.QueryExceptionIf the statement fails to execute.
async def save(self: Self) -> bool: (source)

Persist the model, inserting or updating as appropriate.

New models are inserted, receiving their generated primary key; existing models write only their dirty attributes. Timestamps are maintained automatically when enabled, and the saving, creating/updating, created/updated and saved events are dispatched around the write.

Returns
boolTrue when the operation succeeds or nothing changed, False when a listener vetoed the write or no stored row matched.
Raises
orionis.database.QueryExceptionIf the statement fails to execute.
async def update(self: Self, attributes: dict[str, Any]) -> bool: (source)

Mass assign the given attributes and persist the model.

Parameters
attributes:dictAttributes to assign honoring the fillable rules.
Returns
boolTrue when the operation succeeds or nothing changed.
Raises
orionis.orm.exceptions.MassAssignmentExceptionIf an attribute violates the mass assignment rules.
orionis.database.QueryExceptionIf the statement fails to execute.

Timestamp column names, overridable per model.

Value
'created_at'

deleted_at.

Value
'deleted_at'

updated_at.

Value
'updated_at'
__abstract__: bool = (source)

Abstract flag used by Model.

Metadata attached by the metaclass.

__slots__: tuple[str, ...] = (source)

Declare the instance attribute slots reserved by this class.

Accessor-backed attributes added to the serialized output.

Attribute casts applied on hydration and assignment.

Named connection; the default connection is used when None.

Mass assignment whitelist; every column is fillable when empty.

Mass assignment blacklist; supports the "*" wildcard.

Attributes omitted from serialization.

incrementing: ClassVar[bool] = (source)

Whether the primary key is generated by the database.

primary_key: ClassVar[str | None] = (source)

Primary key name; discovered from column flags when None.

soft_deletes: ClassVar[bool] = (source)

Whether deletes stamp a column instead of removing the row.

Logical table name; derived from the class name when None.

Versioned table definition shared with schema migrations.

Whether creation/update timestamps are maintained automatically.

Whether the primary key is a client-generated unique identifier.

_changes = (source)

Changes produced by deepcopy.

Exists flag used by Model.