CIM-Graph Library Structure¶
CIMantic Graphs uses the layered architecture shown below:

Database Layer¶
CIMantic Graphs supports the following files, databases and interfaces:
- CIM XML files, including models split into parts by an IEC 61970-552 metadata header (
XMLFile) - JSON-LD files (
JSONLDFile) - Blazegraph (
BlazegraphConnection) - GraphDB (
GraphDBConnection) - Neo4j (
Neo4jConnection) - MySQL, using the CIMTool SQL schema (
MySQLConnection) - RDFLib, for RDF files read into memory (
RDFlibConnection) - GridAPPS-D platform (
GridappsdConnection)
All upper-level calls and routines use the same syntax, so the database can be changed by creating a different connection and setting its environment variables, with no other changes to the application. File connections need no extra packages; each database needs its driver extra (see Installation).
Data Profile Layer¶
CIMantic Graphs supports any standard or custom CIM profile. Each UML class and attribute of the profile is a Python dataclass, which powers all of the routines and the unified API.
The built-in profiles (e.g. CIM16v33, CIM17v40, CIMHub 2023, GridAPPS-D RC4 2021, CGMES 3.0, CIM18) ship in the separate cimprofiles package, together with the Identity base class and the units. Custom profiles can be generated with CIMTool or Enterprise Architect Schema Composer, and several profiles can be merged at runtime. See Profiles Overview.
API Layer¶
Two core methods give access to any CIM class in any profile and database:
Access to labeled property graph objects:
network.graph[cim.ClassName]: the catalog of CIM objects stored in memory, keyed by class and then by identifier (aUUID).
Universal database query method:
network.get_all_edges(cim.ClassName): gets all attributes of the objects of the class, and all objects one edge away. It works for all CIM classes, CIM profiles, serialization formats and supported databases.
Graph models also create, modify and delete objects (create, modify, delete), record those changes as CIM difference models, and find objects by attribute (find_by_attribute, find_by_condition).
Knowledge Graph Layer¶
CIMantic Graphs offers three knowledge graph classes for different kinds of power system models:
BusBranchModel: transmission bus-branch models, commonly used for planning and power flow studiesNodeBreakerModel: transmission node-breaker models, commonly used in energy management systemsFeederModel: distribution feeder models, with support for the single-phase unbalanced networks used in North America
Models can be centralized or distributed. A centralized model is a single labeled property graph of the network. A distributed model uses nested DistributedArea graphs for the equipment inside each Substation, VoltageLevel, Bay, Feeder and switch-delimited topological area of a combined T+D model. See Graph Models.
Application Layer¶
T+D applications access all of the power system objects through the knowledge graph, with no need to connect to the database or write custom I/O.
Package Layout¶
| Package | Contents |
|---|---|
cimgraph.databases |
The connections (XMLFile, JSONLDFile, BlazegraphConnection, GraphDBConnection, Neo4jConnection, MySQLConnection, RDFlibConnection, GridappsdConnection) and their ConnectionInterface base class |
cimgraph.queries |
SPARQL, Cypher and RDFLib queries, built at runtime for any CIM profile and class |
cimgraph.models |
GraphModel and its subclasses FeederModel, NodeBreakerModel, BusBranchModel and DistributedArea |
cimgraph.updaters |
What changes a model: the CIM difference model builder (incremental_builder), GridAPPS-D difference messages (incremental_json), measurement value streams (measurement_json) and applying them to a model (measurement_updater) |
cimgraph.utils |
Shortcuts: bulk queries (get_all_line_data, get_all_data, ...), file writers (write_xml, write_json_ld) and Mermaid diagrams (get_mermaid, get_mermaid_path) |
cimgraph.core |
Settings from the CIMG_* environment variables (get_cim_profile, ...), per-object serialization and input validation |
cimprofiles |
Separate package: the CIM profiles, Identity, units and profile merging |
cimgraph.data_profile is the pre-0.6 home of the profiles. Its imports still work, with a DeprecationWarning: identity, units and merge stay for all of 1.x, while the profile packages (cimgraph.data_profile.cim17v40 etc.) are removed in 1.0.
<style>
['pre { line-height: 125%; }\ntd.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }\nspan.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }\ntd.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }\nspan.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }\n.highlight-ipynb .hll { background-color: var(--jp-cell-editor-active-background) }\n.highlight-ipynb { background: var(--jp-cell-editor-background); color: var(--jp-mirror-editor-variable-color) }\n.highlight-ipynb .c { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment */\n.highlight-ipynb .err { color: var(--jp-mirror-editor-error-color) } /* Error */\n.highlight-ipynb .k { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword */\n.highlight-ipynb .o { color: var(--jp-mirror-editor-operator-color); font-weight: bold } /* Operator */\n.highlight-ipynb .p { color: var(--jp-mirror-editor-punctuation-color) } /* Punctuation */\n.highlight-ipynb .ch { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Hashbang */\n.highlight-ipynb .cm { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Multiline */\n.highlight-ipynb .cp { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Preproc */\n.highlight-ipynb .cpf { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.PreprocFile */\n.highlight-ipynb .c1 { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Single */\n.highlight-ipynb .cs { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Special */\n.highlight-ipynb .kc { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Constant */\n.highlight-ipynb .kd { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Declaration */\n.highlight-ipynb .kn { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Namespace */\n.highlight-ipynb .kp { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Pseudo */\n.highlight-ipynb .kr { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Reserved */\n.highlight-ipynb .kt { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Type */\n.highlight-ipynb .m { color: var(--jp-mirror-editor-number-color) } /* Literal.Number */\n.highlight-ipynb .s { color: var(--jp-mirror-editor-string-color) } /* Literal.String */\n.highlight-ipynb .ow { color: var(--jp-mirror-editor-operator-color); font-weight: bold } /* Operator.Word */\n.highlight-ipynb .pm { color: var(--jp-mirror-editor-punctuation-color) } /* Punctuation.Marker */\n.highlight-ipynb .w { color: var(--jp-mirror-editor-variable-color) } /* Text.Whitespace */\n.highlight-ipynb .mb { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Bin */\n.highlight-ipynb .mf { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Float */\n.highlight-ipynb .mh { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Hex */\n.highlight-ipynb .mi { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Integer */\n.highlight-ipynb .mo { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Oct */\n.highlight-ipynb .sa { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Affix */\n.highlight-ipynb .sb { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Backtick */\n.highlight-ipynb .sc { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Char */\n.highlight-ipynb .dl { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Delimiter */\n.highlight-ipynb .sd { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Doc */\n.highlight-ipynb .s2 { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Double */\n.highlight-ipynb .se { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Escape */\n.highlight-ipynb .sh { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Heredoc */\n.highlight-ipynb .si { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Interpol */\n.highlight-ipynb .sx { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Other */\n.highlight-ipynb .sr { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Regex */\n.highlight-ipynb .s1 { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Single */\n.highlight-ipynb .ss { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Symbol */\n.highlight-ipynb .il { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Integer.Long */']
</style>