OGM API Reference
Note: This is a manually-maintained API reference. For the authoritative API, read the source on GitHub.
runic.ogm is a lightweight graph OGM for Cypher-based graph databases. It follows a SQLAlchemy-style architecture: driver → session → mapper → repository. FalkorDB, ArcadeDB, and any Bolt-compatible database are supported via the GraphDriver abstraction.
runic.ogm.core — Models & Fields
Node
runic.ogm.core.models.Node
Base class for graph node models.
__label__— graph label for the node (defaults to the class name)__fields__— mapping of field names toFieldDescriptorinstancessave()— persist the node to the graphdelete()— remove the node from the graphto_dict()— serialize the node to a plain dictionary
Edge
runic.ogm.core.models.Edge
Base class for graph edge (relationship) models.
__type__— relationship type (defaults to the class name uppercased)__fields__— mapping of field names toFieldDescriptorinstancessource— the source node of the edgetarget— the target node of the edgeto_dict()— serialize the edge to a plain dictionary
Field
runic.ogm.core.descriptors.Field
Factory function that declares a node or edge property field. Returns a FieldDescriptor.
class Person(Node):
name: str = Field(default=None)
age: int = Field(default=0)Relation
runic.ogm.core.descriptors.Relation
Factory function that declares a relationship attribute on a node. Returns a FieldDescriptor configured as a relation.
class Person(Node):
friends: list[Person] = Relation("FRIEND_OF", target=Person)FieldDescriptor
runic.ogm.core.descriptors.FieldDescriptor
Internal descriptor class that backs Field() and Relation() declarations.
field_name— name of the field on the model classfield_info— the associatedFieldInfometadata object__get__()— descriptor getter; returns the field value or triggers lazy load__set__()— descriptor setter; validates and stores the value
FieldInfo
runic.ogm.core.descriptors.FieldInfo
Metadata container for a declared field.
default— default value or factoryconverter— optionalTypeConverterfor serialisation/deserialisationis_relation—Trueif this field represents a relationshiprelation_type— Cypher relationship type string (for relations)target_model— target node class (for relations)
runic.ogm.core — MetaData
MetaData
runic.ogm.core.metadata.MetaData
Registry that tracks all Node and Edge model classes.
register(cls)— register a model classnodes— dict of label →NodeMetaedges— dict of type →EdgeMetaget_node_meta(label)— returnNodeMetafor the given labelget_edge_meta(type_)— returnEdgeMetafor the given type
NodeMeta
runic.ogm.core.metadata.NodeMeta
Metadata record for a registered node class.
label— graph label stringmodel_cls— the Python classfields— mapping of field name →FieldInfo
EdgeMeta
runic.ogm.core.metadata.EdgeMeta
Metadata record for a registered edge class.
type_— relationship type stringmodel_cls— the Python classfields— mapping of field name →FieldInfo
get_metadata
runic.ogm.core.metadata.get_metadata
Module-level function that returns the global MetaData singleton.
runic.ogm.core — Type Converters
TypeConverter
runic.ogm.core.types.TypeConverter
Abstract base class for field type converters.
to_db(value)— convert a Python value to its graph-database representationfrom_db(value)— convert a graph-database value back to Python
DatetimeConverter
runic.ogm.core.types.DatetimeConverter
Converter for datetime fields. Serialises to ISO-8601 strings and deserialises back to datetime objects.
to_db(value)— returns ISO-8601 stringfrom_db(value)— returnsdatetime
EnumConverter
runic.ogm.core.types.EnumConverter
Converter for Enum fields. Serialises to the enum value and deserialises back to the enum member.
to_db(value)— returnsvalue.valuefrom_db(value)— returnsEnumClass(value)
Vector
runic.ogm.core.types.Vector
Native type for vector (embedding) fields. Wraps a list of floats and carries optional dimension metadata.
values— the underlying list of floatsdimensions— expected vector length (optional)
VectorConverter
runic.ogm.core.types.VectorConverter
Converter that serialises Vector instances to lists and back.
to_db(value)— returnslist[float]from_db(value)— returnsVector
GeoLocation
runic.ogm.core.types.GeoLocation
Native type for geographic coordinate fields.
latitude— floatlongitude— float
GeoLocationConverter
runic.ogm.core.types.GeoLocationConverter
Converter that serialises GeoLocation instances to dicts and back.
to_db(value)— returns{"latitude": ..., "longitude": ...}from_db(value)— returnsGeoLocation
runic.ogm.driver — Drivers & Dialects
FalkorDBDriver
runic.ogm.driver.falkordb.FalkorDBDriver
Synchronous driver for FalkorDB.
execute(query, params)— run a Cypher query and return aGraphResultclose()— release the connection
AsyncFalkorDBDriver
runic.ogm.driver.falkordb.AsyncFalkorDBDriver
Asynchronous driver for FalkorDB.
execute(query, params)— coroutine; run a Cypher query and return aGraphResultclose()— coroutine; release the connection
FalkorDBDialect
runic.ogm.driver.falkordb.FalkorDBDialect
Cypher dialect customisations for FalkorDB.
render_create_node(label, props)— returns FalkorDB-compatible CREATE clauserender_index(label, field)— returns FalkorDB-compatible index DDL
BoltDriver
runic.ogm.driver.bolt.BoltDriver
Generic Bolt-protocol driver; compatible with Neo4j and ArcadeDB Bolt endpoint.
execute(query, params)— run a Cypher query and return aGraphResultclose()— release the connection
ArcadeDBDialect
runic.ogm.driver.arcadedb.ArcadeDBDialect
Cypher dialect customisations for ArcadeDB.
render_create_node(label, props)— returns ArcadeDB-compatible CREATE clause
AGEDriver
runic.ogm.driver.age.AGEDriver
Driver for Apache AGE (PostgreSQL graph extension).
execute(query, params)— run a Cypher query via AGE and return aGraphResultclose()— release the connection
AGEDialect
runic.ogm.driver.age.AGEDialect
Cypher dialect customisations for Apache AGE.
wrap_query(graph_name, query)— wraps a Cypher query in theag_catalog.cypher()call
create_falkordb_driver
runic.ogm.driver.falkordb.create_falkordb_driver
Factory function. Creates and returns a FalkorDBDriver (or AsyncFalkorDBDriver) from connection parameters.
create_arcadedb_driver
runic.ogm.driver.arcadedb.create_arcadedb_driver
Factory function. Creates and returns a BoltDriver configured for ArcadeDB.
create_age_driver
runic.ogm.driver.age.create_age_driver
Factory function. Creates and returns an AGEDriver from connection parameters.
create_driver
runic.ogm.driver.factory.create_driver
Generic factory function. Inspects the connection URL scheme and returns the appropriate driver instance.
runic.ogm.session — Session
Session
runic.ogm.session.session.Session
Synchronous unit-of-work session. Wraps a GraphDriver and tracks entity state.
add(entity)— stage a node or edge for insertiondelete(entity)— stage a node or edge for deletionflush()— write staged changes to the databasecommit()— flush and finalise the transactionrollback()— discard all staged changesclose()— release the driver connection
AsyncSession
runic.ogm.session.async_session.AsyncSession
Asynchronous counterpart to Session. All mutating methods are coroutines.
add(entity)— stage a node or edge for insertiondelete(entity)— stage a node or edge for deletionflush()— coroutine; write staged changescommit()— coroutine; flush and finaliserollback()— coroutine; discard staged changesclose()— coroutine; release the driver connection
ConnectionManager
runic.ogm.session.connection_pool.ConnectionManager
Synchronous connection pool manager.
acquire()— return an availableSessionrelease(session)— return a session to the poolclose_all()— close every pooled session
AsyncConnectionManager
runic.ogm.session.connection_pool.AsyncConnectionManager
Asynchronous connection pool manager.
acquire()— coroutine; return an availableAsyncSessionrelease(session)— coroutine; return a session to the poolclose_all()— coroutine; close every pooled session
runic.ogm.repository — Repository
Repository
runic.ogm.repository.repository.Repository
Generic synchronous repository for a single Node or Edge model.
get(id)— fetch an entity by primary keyfind(**filters)— fetch entities matching keyword filtersfind_one(**filters)— fetch the first matching entityadd(entity)— persist a new entitydelete(entity)— remove an entityquery()— return aQueryBuilderscoped to this model
AsyncRepository
runic.ogm.repository.async_repository.AsyncRepository
Asynchronous counterpart to Repository. All methods are coroutines.
get(id)— coroutine; fetch an entity by primary keyfind(**filters)— coroutine; fetch entities matching keyword filtersfind_one(**filters)— coroutine; fetch the first matching entityadd(entity)— coroutine; persist a new entitydelete(entity)— coroutine; remove an entityquery()— return anAsyncQueryBuilderscoped to this model
runic.ogm.schema — Index Declarations
IndexSpec
runic.ogm.schema.index_manager.IndexSpec
Declares a single index on a node label and field.
label— graph label the index applies tofield— field name to indexindex_type—"exact","fulltext", or"vector"
extract_declared_specs
runic.ogm.schema.index_manager.extract_declared_specs
Function that inspects all registered models and returns the list of IndexSpec instances derived from their field declarations.
runic.migrate.schema — Index & Schema Management
IndexManager
runic.migrate.schema.IndexManager
Manages index creation, deletion, and drift detection against a live database.
apply(specs)— create any missing indexes from a list ofIndexSpecdrop(specs)— drop indexes matching the given specsdiff(specs)— return specs that are declared but not yet present in the db
ValidationResult
runic.migrate.schema.ValidationResult
Result object returned by schema validation operations.
is_valid—Trueif no issues were foundmissing— list ofIndexSpecmissing from the databaseextra— list of database indexes not covered by any declared spec
SchemaManager
runic.migrate.schema.SchemaManager
High-level facade for schema lifecycle operations.
validate()— return aValidationResultcomparing declared specs against the live dbsync()— apply missing indexes and remove undeclared onesexport()— return a serialisable dict of the current schema state
runic.ogm.exceptions
OrmError
runic.ogm.exceptions.OrmError
Base exception for all runic OGM errors.
EntityNotFoundError
runic.ogm.exceptions.EntityNotFoundError
Raised when a requested node or edge does not exist in the graph.
DetachedEntityError
runic.ogm.exceptions.DetachedEntityError
Raised when an operation is attempted on an entity that is no longer associated with a session.
LazyLoadError
runic.ogm.exceptions.LazyLoadError
Raised when a lazy-loaded relation cannot be resolved (e.g. because the session is closed).
FieldValidationError
runic.ogm.exceptions.FieldValidationError
Raised when a value assigned to a field fails type or constraint validation.
MetadataError
runic.ogm.exceptions.MetadataError
Raised when model metadata is missing, duplicated, or otherwise inconsistent.
See also
migration/api — Migration API reference (runic.migrate)
runic.ogm.query
select
runic.ogm.query.select
Entry-point function for building a query. Returns a QueryBuilder pre-scoped to the given model class.
q = select(Person).where(Person.age > 30).limit(10)QueryBuilder
runic.ogm.query.builder.QueryBuilder
Fluent query builder for synchronous Cypher queries.
where(expr)— add a filter expressionorder_by(expr)— add an ordering expressionlimit(n)— limit result countskip(n)— skip the first n resultstraverse(step)— add aTraversalStepall()— execute and return all matching entitiesone()— execute and return the first matching entitycount()— execute and return the result count
AsyncQueryBuilder
runic.ogm.query.specialised.AsyncQueryBuilder
Asynchronous counterpart to QueryBuilder. all(), one(), and count() are coroutines.
FulltextQueryBuilder
runic.ogm.query.specialised.FulltextQueryBuilder
Specialised QueryBuilder for fulltext index queries.
search(text)— perform a fulltext search against declared fulltext indexes
VectorQueryBuilder
runic.ogm.query.specialised.VectorQueryBuilder
Specialised QueryBuilder for vector similarity queries.
near(vector, k)— perform a k-NN search against declared vector indexes
TraversalStep
runic.ogm.query.traversal.TraversalStep
Represents one hop in a graph traversal.
relation_type— the Cypher relationship type to traversetarget_model— expected model class at the targetdirection—"outgoing","incoming", or"both"depth— fixed depth or(min, max)range tuple
Expr
runic.ogm.query.expressions.Expr
Abstract base class for all query expression types.
FilterExpr
runic.ogm.query.expressions.FilterExpr
A simple binary filter expression (e.g. field == value).
field— the field nameoperator— comparison operator string ("=",">","<", etc.)value— the comparison value
CompoundExpr
runic.ogm.query.expressions.CompoundExpr
Combines two expressions with AND or OR.
left— left-handExprright— right-handExproperator—"AND"or"OR"
NegatedExpr
runic.ogm.query.expressions.NegatedExpr
Wraps an expression with NOT.
inner— theExprto negate
OrderExpr
runic.ogm.query.expressions.OrderExpr
Represents an ORDER BY clause.
field— the field to order bydirection—"ASC"or"DESC"
AggExpr
runic.ogm.query.expressions.AggExpr
Represents an aggregate expression (e.g. COUNT, AVG).
function— aggregate function namefield— field the aggregate applies to
count
runic.ogm.query.expressions.count
Helper function. Returns an AggExpr for COUNT(field).
avg
runic.ogm.query.expressions.avg
Helper function. Returns an AggExpr for AVG(field).
sum_
runic.ogm.query.expressions.sum_
Helper function. Returns an AggExpr for SUM(field).
min_
runic.ogm.query.expressions.min_
Helper function. Returns an AggExpr for MIN(field).
max_
runic.ogm.query.expressions.max_
Helper function. Returns an AggExpr for MAX(field).
collect
runic.ogm.query.expressions.collect
Helper function. Returns an AggExpr for COLLECT(field).