Quickstart

Parsing datasets

The parser is invoked using the parse function:

cimpyorm.parse(dataset, backend=<class 'cimpyorm.backends.SQLite'>, schema=None, log_to_file=False, silence_tqdm=False)[source]

Parse a database into a database backend and yield a database session to start querying on with the classes defined in the model namespace_name.

Afterwards, the database can be queried using SQLAlchemy query syntax, providing the CIM classes contained in the Namespace return value.

Parameters
  • dataset (Union[str, Path]) – Path to the cim snapshot.

  • backend – Database backend to be used (defaults to a SQLite on-disk database in the dataset location).

  • schema (Union[str, Path, None]) – Location of the RDF schema to be used to parse the dataset (Folder of multiple RDF schemata or a single schema file).

  • log_to_file (Union[bool, Path, str]) – Pass logging output to a file for this ingest only.

  • silence_tqdm (bool) – Silence tqdm progress bars

Return type

Tuple[Session, Namespace]

Returns

sqlalchemy.orm.session.Session, argparse.Namespace

Loading datasets

Alternatively, an already parsed dataset can be loaded from on-disk files (using SQLite) or from a client-server database using the load function:

cimpyorm.load(path_to_db, echo=False)[source]

Load an already parsed database from disk or connect to a server and yield a database session to start querying on with the classes defined in the model namespace_name.

Afterwards, the database can be queried using SQLAlchemy query syntax, providing the CIM classes contained in the Namespace return value.

Parameters
  • path_to_db (Union[Engine, str]) – Path to the cim snapshot or a Engine.

  • echo (bool) – Echo the SQL sent to the backend engine (SQLAlchemy option).

Return type

Tuple[Session, Namespace]

Returns

sqlalchemy.orm.session.Session, argparse.Namespace

Querying datasets

Queries for CIM objects are performed on the Session objects provided by the parse() and load() functions, e.g.:

db_session, model = parse(r"path_to_dataset")
acl = db_session.query(model.ACLineSegment).first()

to obtain the first CIM:ACLineSegment from the model.

The objects properties can subsequently be accessed as usual:

acl.r # Print the ACLineSegment's resistance

The CIM classes’ inherited properties (to explore the model’s classes and properties see Exploring) are also available:

acl.shortName # shortName is a property of CIM:IdentifiedObjects, which ACLineSegments inherit from

Relationships can be accessed by their name:

bv = acl.BaseVoltage # Yields the CIM:BaseVoltage object associated with the CIM:ACLineSegment

The model also allows for reverse lookup of relationships that are unidirectional in the CIM standard:

terminals = acl.Terminals # In the standard, a CIM:ACLineSegment (or rather its base class
                          # CIM:ConductingEquipment) is referenced by a CIM:Terminal definition,
                          # however, cimpyorm adds their inversion for convenience
                          # (the inverse property names are defined in the schema definition)