Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Brick Ontology Python package

Build Documentation Status PyPI version

Documentation available at readthedocs

Installation

The brickschema package requires Python >= 3.11. It can be installed with pip:

pip install brickschema

brickschema ships two OWL 2 RL reasoners, both installed by default:

  • reasonable is a fast OWL 2 RL reasoner written in Rust. It is the default backend.
  • OWLRL is a pure-Python implementation. It delivers correct results but performs poorly on large or complex ontologies (we have observed minutes to hours).

Pick one explicitly with the backend argument to expand:

g.expand("owlrl")                      # reasonable (default)
g.expand("owlrl", backend="owlrl")     # pure-Python

Quickstart

The main Graph object is just a subclass of the excellent RDFlib Graph library, so all features on rdflib.Graph will also work here.

Brief overview of the main features of the brickschema package:

import brickschema

# creates a new rdflib.Graph with a recent version of the Brick ontology
# preloaded.
g = brickschema.Graph(load_brick=True)
# OR use the absolute latest Brick:
# g = brickschema.Graph(load_brick_nightly=True)
# OR create from an existing model
# g = brickschema.Graph(load_brick=True).from_haystack(...)

# load in data files from your file system
g.load_file("mbuilding.ttl")
# ...or by URL (using rdflib)
g.parse("https://brickschema.org/ttl/soda_brick.ttl", format="ttl")

# perform reasoning on the graph (edits in-place)
g.expand(profile="owlrl")
g.compile() # applies SHACL-AF rules; infers Brick classes from Brick tags

# validate your Brick graph against built-in shapes (or add your own)
valid, _, resultsText = g.validate()
if not valid:
    print("Graph is not valid!")
    print(resultsText)

# perform SPARQL queries on the graph
res = g.query("""SELECT ?afs ?afsp ?vav WHERE  {
    ?afs    a       brick:Air_Flow_Sensor .
    ?afsp   a       brick:Air_Flow_Setpoint .
    ?afs    brick:isPointOf ?vav .
    ?afsp   brick:isPointOf ?vav .
    ?vav    a   brick:VAV
}""")
for row in res:
    print(row)

# start a blocking web server with an interface for performing
# reasoning + querying functions
g.serve("localhost:8080")
# now visit in http://localhost:8080

Features

brickschema supports a number of optional features:

  • [all]: install all features below
  • [brickify]: install the brickify command for converting metadata from existing sources
  • [web]: allow serving of Brick models over HTTP + web interface
  • [merge]: initial support for merging Brick models with different identifiers together
  • [persistence]: support for saving and loading Brick models to/from disk
  • [orm]: SQLAlchemy ORM over a Brick model
  • [networkx]: export a Brick model as a NetworkX digraph
  • [bacnet]: scan a BACnet network into a Brick model
  • [topquadrant]: use the TopQuadrant SHACL engine

The shifty and pyshacl SHACL engines and both OWL 2 RL reasoners (reasonable and owlrl) are installed by default, so no extra is needed for validation, compile() or expand().

Inference

brickschema makes it easier to employ reasoning on your graphs. Simply call the expand method on the Graph object with one of the following profiles:

  • "rdfs": RDFS reasoning
  • "owlrl": OWL-RL reasoning (using 1 of 3 implementations below)
  • "vbis": add VBIS tags to Brick entities

SHACL-AF rules (which is how Brick infers classes from tags, among other things) are applied with compile() rather than expand():

g.compile()                      # uses the default engine
g.compile(engine="pyshacl")      # or name one explicitly
from brickschema import Graph

g = Graph(load_brick=True)
g.load_file("test.ttl")
g.expand(profile="owlrl")
print(f"Inferred graph has {len(g)} triples")

For the owlrl profile the package defaults to the fastest available implementation, reasonable.

  • OWLRL (default, native Python implementation): pip install brickschema

To use a specific reasoner, specify "reasonable" or "owlrl" as the value for the backend argument to graph.expand.

Haystack Translation

brickschema can produce a Brick model from a JSON export of a Haystack model. Then you can use this package as follows:

import json
from brickschema import Graph
model = json.load(open("haystack-export.json"))
g = Graph(load_brick=True).from_haystack("http://project-haystack.org/carytown#", model)
points = g.query("""SELECT ?point ?type WHERE {
    ?point rdf:type/rdfs:subClassOf* brick:Point .
    ?point rdf:type ?type
}""")
print(points)

VBIS Translation

brickschema can add VBIS tags to a Brick model easily

from brickschema import Graph
g = Graph(load_brick=True)
g.load_file("mybuilding.ttl")
g.expand(profile="vbis")

vbis_tags = g.query("""SELECT ?equip ?vbistag WHERE {
    ?equip  <https://brickschema.org/schema/1.1/Brick/alignments/vbis#hasVBISTag> ?vbistag
}""")

Web-based Interaction

brickschema now supports interacting with a Graph object in a web browser. Executing g.serve(<http address>) on a graph object from your Python script or interpreter will start a webserver listening (by default) at http://localhost:8080 . This uses Yasgui to provide a simple web interface supporting SPARQL queries and inference.

To use this feature, install brickschema with the web feature enabled:

pip install brickschema[web]

Brick model validation

validate() checks a model against the Brick shapes bundled in the graph plus any shapes you supply. It does not modify the graph.

from brickschema import Graph

g = Graph(load_brick=True)
g.load_file('myBuilding.ttl')
valid, _, _ = g.validate()
print(f"Graph is valid? {valid}")

# validating using externally-defined shapes
external = Graph()
external.load_file("other_shapes.ttl")
valid, _, report = g.validate(extra_graphs=[external])
print(f"Graph is valid? {valid}")

SHACL engines

Both validate() and compile() are backed by a pluggable SHACL engine, selected with the engine= keyword. When you do not name one, the first installed engine from this list is used:

engine package notes
"shifty" pyshifty (installed by default) default; Rust SHACL/SHACL-AF engine, runs rules to a fixed point
"topquadrant" brickschema[topquadrant] TopQuadrant's Java implementation
"pyshacl" pyshacl (installed by default) pure-Python reference implementation
valid, _, report = g.validate(engine="pyshacl")
g.compile(engine="shifty")

min_iterations and max_iterations bound how many rule passes are made; they apply to the pyshacl and topquadrant engines only, since shifty always runs to a fixed point.

Brickify

To use brickify, install brickschema with the [brickify] feature enabled:

pip install brickschema[brickify]

Usage:

$ brickify [OPTIONS] SOURCE

Arguments:

  • SOURCE: Path/URL to the source file [required]

Options:

  • --input-type TEXT: Supported input types: rac, table, rdf, haystack-v4
  • --brick PATH: Brick.ttl
  • --config PATH: Custom configuration file
  • --output PATH: Path to the output file
  • --serialization-format TEXT: Supported serialization formats: turtle, xml, n3, nt, pretty-xml, trix, trig and nquads [default: turtle]
  • --minify / --no-minify: Remove inferable triples [default: False]
  • --input-format TEXT: Supported input formats: xls, csv, tsv, url, turtle, xml, n3, nt, pretty-xml, trix, trig and nquads [default: turtle]
  • --building-prefix TEXT: Prefix for the building namespace [default: bldg]
  • --building-namespace TEXT: The building namespace [default: https://example.com/bldg#]
  • --site-prefix TEXT: Prefix for the site namespace [default: site]
  • --site-namespace TEXT: The site namespace [default: https://example.com/site#]
  • --install-completion: Install completion for the current shell.
  • --show-completion: Show completion for the current shell, to copy it or customize the installation.
  • --help: Show this message and exit.

Usage examples: brickify.

Development

Brick requires Python >= 3.11. We use pre-commit hooks to automatically run code formatters and style checkers when you commit.

Use uv to manage packaging and dependencies. After installing uv, create the environment and install all dependencies with:

uv sync --all-extras --dev   # or: make sync

uv run <command> executes a command inside that environment, so there is no separate activation step:

uv run python -c "import brickschema"

On first setup, make sure to install the pre-commit hooks for running the formatting and linting tools:

uv run pre-commit install

Run tests to make sure the build is not broken:

make test                      # 4 parallel workers by default
make test PYTEST_ARGS=""       # serial

Build the distribution artifacts with:

make build                     # uv build

uv.lock is committed and is the source of truth for the development environment. If you change a dependency in pyproject.toml, refresh it with:

make lock                      # uv lock

The uv-lock pre-commit hook does this automatically, and CI runs uv sync --locked, which fails if uv.lock and pyproject.toml disagree.

Docs

Docs are written in reStructured Text. Make sure that you add your package requirements to docs/requirements.txt

Release files for brickschema 0.8.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for brickschema 0.8.0a1
File Size Uploaded
brickschema-0.8.0a1.tar.gz 1.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for brickschema 0.8.0a1
File Interpreter ABI Platform
brickschema-0.8.0a1-py3-none-any.whl Python 3 none any Details

Total release size: 3.2 MB

Release files / brickschema-0.8.0a1.tar.gz

Download URL brickschema-0.8.0a1.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
ed35059be3d7fe123ec20011e00247f42513da5f59e3c52ee500405e6a508b14
BLAKE2b-256 checksum
How to use checksums
66b4e49d2ad10326c8aa59b4555afe3f941d23209107387ef6c2ca5ae4e9b2c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / brickschema-0.8.0a1-py3-none-any.whl

Download URL brickschema-0.8.0a1-py3-none-any.whl
Size 1.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
6e707512c9be36afb606cac12161493556d7c62c4d0706fb8144225f0a510d7e
BLAKE2b-256 checksum
How to use checksums
f5f799002b726d68be7e8d0869336488a7bb513e38852f7575441ec96578f910
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.8.0a1 This release

2 release files

0.7.9

2 release files

0.7.8

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page