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 Model(AttributesMixin, StateMixin, RelationsMixin, EventsMixin, SoftDeletesMixin): (source)
Constructors: Model._newFromDatabase(row), Model.create(attributes), Model.findOrFail(key), Model.firstOrFail(), Model(attributes)
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 | _new |
Hydrate a model instance from a database row. |
| Class Method | add |
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 | find |
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 | first |
Retrieve the first row or raise when the table is empty. |
| Class Method | fresh |
Produce the current timestamp for persistence operations. |
| Class Method | get |
Resolve the connection configured for this model. |
| Class Method | new |
Produce a client-generated primary key value. |
| Class Method | query |
Start a new query builder bound to this model. |
| Class Method | remove |
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 | _perform |
Remove the persisted row permanently. |
| Async Method | _perform |
Insert the model attributes as a new row. |
| Async Method | _perform |
Write the dirty attributes of an existing model. |
| Method | _persistence |
Keep a hydrated row's writes on the connection that supplied it. |
| Method | _primary |
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 |
Timestamp column names, overridable per model. |
| Constant | DELETED |
deleted_at. |
| Constant | UPDATED |
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 |
Primary key name; discovered from column flags when None. |
| Class Variable | soft |
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 |
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 | get |
Return a single attribute value through its accessor. |
| Method | has |
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 | set |
Assign a single attribute applying its mutator and cast. |
| Method | to |
Serialize the visible attributes into a dictionary. |
| Method | to |
Serialize the visible attributes into a JSON string. |
Inherited from StateMixin (via AttributesMixin):
| Method | get |
Return the attributes persisted by the last save operation. |
| Method | get |
Return the attributes modified since the last sync. |
| Method | get |
Return the original attribute snapshot or a single original value. |
| Method | is |
Report whether no attribute changed since the last sync. |
| Method | is |
Report whether any attribute changed since the last sync. |
| Method | sync |
Snapshot the current attributes as the new original state. |
| Method | was |
Report whether the last save operation changed any attribute. |
Inherited from EventsMixin (via AttributesMixin, StateMixin):
| Class Method | flush |
Remove registered listeners from the model. |
| Class Method | observe |
Register every lifecycle method exposed by an observer. |
| Class Method | register |
Register a listener for a model lifecycle event. |
| Async Method | fire |
Dispatch a lifecycle event to its listeners. |
Inherited from SoftDeletesMixin (via AttributesMixin, StateMixin, EventsMixin):
| Async Method | _perform |
Stamp the soft delete column of the persisted row. |
| Async Method | force |
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. |
Hydrate a model instance from a database row.
| Parameters | |
row:dict | Raw 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.Model | Existing model instance with casts applied. |
type[ Self], name: str, scope: Callable[ [ ModelQueryBuilder[ Self]], None]) -> type[ Self]:
(source)
¶
Register a constraint applied to every query of this model.
| Parameters | |
name:str | Name the scope is registered under, used to disable it later with withoutGlobalScope. |
scope:collections.abc.Callable | Callable receiving the builder and constraining it in place. |
| Returns | |
type | The model class, enabling fluent chaining. |
Retrieve every row of the model table.
| Returns | |
collections.abc.Collection | Collection of hydrated model instances. |
Create, persist, and return a new model.
| Parameters | |
attributes:dict | Attributes to mass assign honoring the fillable rules. |
| Returns | |
orionis.orm.Model | Model instance, left unsaved if a before-write listener vetoes it. |
| Raises | |
orionis.orm.exceptions.MassAssignmentException | If an attribute violates the mass assignment rules. |
orionis.database.QueryException | If the insert statement fails. |
Delete the models matching the given primary keys.
| Parameters | |
*keys:typing.Any | Primary key values to delete. |
| Returns | |
int | Number of deleted rows. |
Retrieve a model by its primary key.
| Parameters | |
key:typing.Any | Primary key value to look up. |
| Returns | |
orionis.orm.Model or None | Matching model, or None when absent. |
Retrieve a model by primary key or raise when absent.
| Parameters | |
key:typing.Any | Primary key value to look up. |
| Returns | |
orionis.orm.Model | Matching model. |
| Raises | |
orionis.orm.exceptions.ModelNotFoundException | If no record matches the key. |
Retrieve the first row of the model table.
| Returns | |
orionis.orm.Model or None | First model, or None when the table is empty. |
Retrieve the first row or raise when the table is empty.
| Returns | |
orionis.orm.Model | First model. |
| Raises | |
orionis.orm.exceptions.ModelNotFoundException | If the table has no rows. |
Produce the current timestamp for persistence operations.
Persistence normalizes this instant to UTC for each target column.
| Returns | |
datetime.datetime | Current timestamp in the application timezone. |
Resolve the connection configured for this model.
| Returns | |
orionis.database.contracts.IConnection | Connection used for model queries and persistence. |
| Raises | |
orionis.orm.exceptions.OrmConfigurationException | If no connection manager has been installed. |
orionis.database.ConnectionNotFoundException | If the configured connection is not declared. |
Produce a client-generated primary key value.
Overridable by models needing a different identifier scheme, such as ULIDs or prefixed keys.
| Returns | |
typing.Any | Fresh unique identifier. |
Start a new query builder bound to this model.
| Returns | |
orionis.orm.query.ModelQueryBuilder | Fresh builder targeting the model table. |
Serve column values and accessor-backed attributes.
| Parameters | |
key:str | Attribute name being accessed. |
| Returns | |
typing.Any | Attribute value; None for declared but unloaded columns. |
| Raises | |
AttributeError | If the name is neither loaded, a declared column, nor an accessor-backed attribute. |
Initialize a new, unsaved model instance.
| Parameters | |
attributes:dict or None, optional | Attributes to mass assign honoring the fillable rules. |
| Returns | |
None | No return value. |
| Raises | |
orionis.orm.exceptions.MassAssignmentException | If an attribute violates the mass assignment rules. |
Return a concise developer representation of the model.
| Returns | |
str | Representation including the class name and primary key. |
Route column assignments into the attribute store.
| Parameters | |
key:str | Attribute name being assigned. |
value:typing.Any | Value to assign. |
| Returns | |
None | No return value. |
Remove the persisted row permanently.
| Returns | |
bool | True when a row was removed. |
| Raises | |
orionis.database.QueryException | If the statement fails to execute. |
Insert the model attributes as a new row.
| Returns | |
bool | True when the insert succeeds. |
| Raises | |
orionis.database.QueryException | If the statement fails to execute. |
Write the dirty attributes of an existing model.
| Returns | |
bool | True when a row was written or nothing changed, False when no stored row matched the primary key. |
| Raises | |
orionis.database.QueryException | If the statement fails to execute. |
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.IConnection | Connection owning the stored row, or the class-selected connection. |
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.Any | Primary key value. |
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 | |
bool | True when a row was deleted or stamped, False for unsaved models, missing rows, or a listener veto. |
| Raises | |
orionis.database.QueryException | If the statement fails to execute. |
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 | |
bool | True when the operation succeeds or nothing changed, False when a listener vetoed the write or no stored row matched. |
| Raises | |
orionis.database.QueryException | If the statement fails to execute. |
Mass assign the given attributes and persist the model.
| Parameters | |
attributes:dict | Attributes to assign honoring the fillable rules. |
| Returns | |
bool | True when the operation succeeds or nothing changed. |
| Raises | |
orionis.orm.exceptions.MassAssignmentException | If an attribute violates the mass assignment rules. |
orionis.database.QueryException | If the statement fails to execute. |