Brick ORMο
Tip
To use this feature, install brickschema with the βormβ feature: pip install brickschema[orm] or pip install brickschema[all]
Currently, the ORM models Locations, Points and Equipment and the basic relationships between them.
Please see the SQLAlchemy docs for detailed information on how to interact with the ORM. use the
orm.session
instance variable to interact with the ORM connection.
See querying docs for how to use the SQLalchemy querying mechanisms
Exampleο
from brickschema.graph import Graph
from brickschema.namespaces import BRICK
from brickschema.orm import SQLORM, Location, Equipment, Point
# loads in default Brick ontology
g = Graph(load_brick=True)
# load in our model
g.load_file("test.ttl")
# put the ORM in a SQLite database file called "brick_test.db"
orm = SQLORM(g, connection_string="sqlite:///brick_test.db")
# get the points for each equipment
for equip in orm.session.query(Equipment):
print(f"Equpiment {equip.name} is a {equip.type} with {len(equip.points)} points")
for point in equip.points:
print(f" Point {point.name} has type {point.type}")
# filter for a given name or type
hvac_zones = orm.session.query(Location)\
.filter(Location.type==BRICK.HVAC_Zone)\
.all()
print(f"Model has {len(hvac_zones)} HVAC Zones")