A toolkit for graph-based decision support system prototypes in building management
Project description
BTwin
BTwin (Building Twin) is a Python toolkit for modeling buildings as semantic knowledge graphs. It is designed for researchers and practitioners who need to prototype graph-based decision support systems in building management — connecting spatial data, equipment inventories, sensor readings, and performance indicators into a single, queryable graph structure.
What it does
A building in BTwin is represented as a directed graph. Every element — a room, an air handling unit, a temperature sensor, an energy KPI — becomes a node. Relationships between elements (a sensor belongs to a space, a space belongs to a floor, a floor belongs to a building) become edges. This graph can be validated against semantic schemas, exported to standard formats, and used as the backbone for analysis and decision support workflows.
The package is built around three principles:
- Semantic grounding: every type and relationship is drawn from established building ontologies (Brick, BOT, IFC) or domain-specific standards (SOSA for sensors, EM-KPIO for energy KPIs). Objects serialize to JSON-LD with full ontology context, making them interoperable with other linked data tools.
- Practical data ingestion: alongside the Python API, BTwin provides Excel templates and batch importers so that equipment inventories and sensor observations can be loaded from spreadsheets without writing code.
- Graph-first analysis: the graph layer (built on NetworkX) supports subgraph extraction by type or UID, schema validation, compact representations of property sets and KPI sets, and export to Neo4j or RDF/Turtle for SPARQL querying.
Modules
| Module | What it models |
|---|---|
SpatialElement |
Spatial hierarchy: sites, buildings, storeys, spaces, zones |
Equipment |
Building assets and systems with location and feeding relationships |
Point |
Sensor and measurement points (Brick point types, SOSA semantics) |
Observation |
Timeseries sensor readings stored and queried via SQLite |
PropertySet / Property |
IFC property sets attached to any spatial or equipment element |
KPISet / KPI |
Performance indicators with evaluation periods, units, and scenarios |
Scenario |
Hypothetical building states for comparative analysis |
Document |
References to external files (BIM models, databases, reports) |
NetworkX |
Graph construction, validation, subgraph queries, Neo4j/JSON export |
RDF |
Conversion of JSON-LD graphs to RDFLib and Turtle serialization |
Serialization |
JSON-LD document assembly with ontology context |
Plot |
Graph visualization via Matplotlib (static) and Plotly (interactive) |
Schema |
Canonical ontology types and allowed relationship patterns |
Ontologies
BTwin maps to these open standards:
- Brick Schema — building metadata schema for equipment and sensor types
- BOT (Building Topology Ontology) — W3C standard for spatial hierarchy
- IFC (Industry Foundation Classes) — buildingSMART property model
- SOSA — W3C Sensor, Observation, Sample and Actuator ontology
- EM-KPIO — Energy Management Key Performance Indicators Ontology
Installation
pip install btwin
Optional extras:
pip install btwin[viz] # visualization (matplotlib, plotly)
pip install btwin[neo4j] # Neo4j graph database export
pip install btwin[dev] # development (pytest, ruff)
pip install btwin[docs] # documentation (mkdocs, mkdocstrings)
Quick Start
from btwin import SpatialElement, Equipment, NetworkX, Serialization
import networkx as nx
# Build a spatial hierarchy
site = SpatialElement.Constructor("site-01", "bot:Site", name="Campus")
building = SpatialElement.Constructor("bldg-01", "bot:Building", name="Main Hall")
storey = SpatialElement.Constructor("storey-01", "bot:Storey", name="Ground Floor")
space = SpatialElement.Constructor("space-01", "bot:Space", name="Room 101")
SpatialElement.SetLocationRelationship(building, linkedObject=site)
SpatialElement.SetLocationRelationship(storey, linkedObject=building)
SpatialElement.SetLocationRelationship(space, linkedObject=storey)
# Add equipment
ahu = Equipment.Constructor("ahu-01", "brick:Air_Handling_Unit", name="AHU 1")
Equipment.SetLocationRelationship(ahu, linkedObject=space)
# Build the graph
G = nx.DiGraph()
for obj in [site, building, storey, space, ahu]:
NetworkX.AddEdgesByObject(G, obj)
print(f"Nodes: {G.number_of_nodes()}, Edges: {G.number_of_edges()}")
# Export to JSON-LD
Serialization.JSONLODByObjects(
[site, building, storey, space, ahu],
savePath="my_building.json"
)
Documentation
Full documentation is built with MkDocs and lives under docs/. It includes a getting started guide, per-module user guides, hands-on tutorials, and an auto-generated API reference from docstrings. To build it locally:
pip install btwin[docs]
mkdocs serve
References
BTwin's theoretical framework, design logic, and applications are presented in:
Massafra, Angelo. Buildings as Networks: Modelling Built Heritage Knowledge Through Graphs. Bologna: Bologna University Press, 2026, 329 pp.
DOI: 10.30682/9791254777954 — Open Access
License
BTwin is free for non-commercial use (research, education, personal projects) under the PolyForm Noncommercial License 1.0.0 — see LICENSE.
For commercial use, contact massafra.angelo95@gmail.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file btwin-0.5.2.tar.gz.
File metadata
- Download URL: btwin-0.5.2.tar.gz
- Upload date:
- Size: 92.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e424a18ff25f03d09843fa5e5991ef2ed1dc0daa9e97ded64c2814f1d9d60e0b
|
|
| MD5 |
5b9d121a79523635c404d20cb8ec1128
|
|
| BLAKE2b-256 |
e5f3a63d6924b67ee12e84b4fb703dbe5fae3f077578b87f62e31c8a408de861
|
File details
Details for the file btwin-0.5.2-py3-none-any.whl.
File metadata
- Download URL: btwin-0.5.2-py3-none-any.whl
- Upload date:
- Size: 82.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a16224d8d412b499d0a8ecf0ae47d998ad2785cb66d46f92a9b25bead820908c
|
|
| MD5 |
4c81ca24a5a79953874bc18455baba78
|
|
| BLAKE2b-256 |
a9e7854993b4b5e30eb20a2613df623e4e7412cfb9b63e096cdcc4e75c54766b
|