Skip to main content
Pre-release

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

CIM-Loader

Automated scripts for

  • uploading and downloading CIM files from various databases
  • converting CIM files between common formats (XML, TTL, etc.)

Installation

The library can be pip installed from PyPi using pip install cim-loader

To install a specific branch, clone the repo and install it using

git clone https://github.com/PNNL-CIM-Tools/CIM-Loader.git -b develop
pip install -e CIM-Loader

Usage

CIM-Loader provides a consistent API for uploading CIM data to various databases. All uploaders support multiple RDF formats and can transfer data between databases using CIMantic Graphs.

Basic File Upload

All uploaders use a consistent API: upload_from_file(filepath, filename)

import os
from cimloader.uploaders import BlazegraphUploader

# Configure via environment variables
os.environ['CIMG_URL'] = 'http://localhost:8889/bigdata/namespace/kb/sparql'

# Create uploader and upload file
loader = BlazegraphUploader()
loader.upload_from_file(filepath='./test_models', filename='ieee13_seto.xml')

Example: Upload to Different Databases

import os

# Blazegraph
os.environ['CIMG_URL'] = 'http://localhost:8889/bigdata/namespace/kb/sparql'
from cimloader.uploaders import BlazegraphUploader
blazegraph = BlazegraphUploader()
blazegraph.upload_from_file(filepath='./models', filename='grid.xml')

# Neo4j
os.environ['CIMG_URL'] = 'neo4j://localhost:7687'
os.environ['CIMG_USERNAME'] = 'neo4j'
os.environ['CIMG_PASSWORD'] = 'password'
from cimloader.uploaders import Neo4jUploader
neo4j = Neo4jUploader()
neo4j.upload_from_file(filepath='./models', filename='grid.xml')

# Oxigraph
os.environ['CIMG_URL'] = 'http://localhost:7878/query'
from cimloader.uploaders import OxigraphUploader
oxigraph = OxigraphUploader()
oxigraph.upload_from_file(filepath='./models', filename='grid.xml')

Database Migration

Transfer data between databases using CIMantic Graphs:

from cimgraph.models import FeederModel
from cimgraph.databases import BlazegraphConnection
from cimloader.uploaders import Neo4jUploader
import cimgraph.data_profile.rc4_2021 as cim

# Load from Blazegraph
os.environ['CIMG_URL'] = 'http://localhost:8889/bigdata/namespace/kb/sparql'
blazegraph = BlazegraphConnection()
feeder = cim.Feeder(mRID='feeder-123')
source = FeederModel(container=feeder, connection=blazegraph)

# Upload to Neo4j
os.environ['CIMG_URL'] = 'neo4j://localhost:7687'
neo4j = Neo4jUploader()
neo4j.upload_from_graphmodel(source.graph)

See the examples/ directory for complete migration and merging examples.

Format Support

Format is auto-detected from the file extension. Pass any of the supported extensions to upload_from_file:

  • RDF/XML.xml, .rdf
  • Turtle.ttl, .turtle
  • N-Triples.nt, .ntriples
  • N-Quads.nq, .nquads
  • JSON-LD.jsonld, .json-ld (Blazegraph, Neo4j)
  • TriG.trig (Blazegraph, Neo4j)
uploader.upload_from_file(filepath='./models', filename='grid.xml')
uploader.upload_from_file(filepath='./models', filename='grid.ttl')

See design/UPLOADER_API.md for full API details and design/STYLE_GUIDE.md for coding conventions.

Databases Supported

Currently supported:

  • Blazegraph
  • Neo4j
  • Oxigraph
  • AWS Neptune (experimental — see docs/NEPTUNE.md)

Planned (see design/TODO.md):

  • Apache AGE (PostgreSQL graph extension — replacing the legacy MySQL connector)
  • GraphDB

Support may be added in the future for:

  • Apache Tinkerpop
  • SQlite
  • AVEVA PI Historian
  • Others as requested

Testing

CIM-Loader uses pytest for integration testing. Tests verify functionality against real database instances running in Docker containers.

Setup Test Environment

  1. Install test dependencies:
pip install -e ".[test]"
  1. Start database services:
docker-compose up -d

This starts all database services:

  • Blazegraph on port 8889
  • Neo4j on ports 7474 (HTTP) and 7687 (Bolt)
  • Oxigraph on port 7878

Running Tests

Run all integration tests:

pytest tests/ -v

Run tests for a specific database:

pytest tests/test_blazegraph.py -v
pytest tests/test_neo4j.py -v
pytest tests/test_oxigraph.py -v
pytest tests/test_mysql.py -v

Run tests using markers:

pytest -m blazegraph -v
pytest -m neo4j -v
pytest -m oxigraph -v
pytest -m mysql -v

Skip slow tests:

pytest -m "not slow" -v

Run with coverage report:

pytest --cov=cimloader --cov-report=html

Test Organization

  • tests/conftest.py - Shared fixtures and test configuration
  • tests/test_blazegraph.py - Blazegraph triplestore tests
  • tests/test_neo4j.py - Neo4j graph database tests
  • tests/test_oxigraph.py - Oxigraph triplestore tests
  • tests/test_mysql.py - MySQL relational database tests
  • tests/test_models/ - Sample CIM XML files for testing

CI/CD

Tests can be integrated into CI/CD pipelines. Make sure Docker is available and services are started before running tests.

Example GitHub Actions workflow:

- name: Start services
  run: docker-compose up -d
- name: Wait for services
  run: sleep 10
- name: Run tests
  run: pytest tests/ -v

Attribution and Disclaimer

This software was created under a project sponsored by the U.S. Department of Energy’s Office of Electricity, an agency of the United States Government. Neither the United States Government nor the United States Department of Energy, nor Battelle, nor any of their employees, nor any jurisdiction or organization that has cooperated in the development of these materials, makes any warranty, express or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness or any information, apparatus, product, software, or process disclosed, or represents that its use would not infringe privately owned rights.

Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United States Government or any agency thereof, or Battelle Memorial Institute. The views and opinions of authors expressed herein do not necessarily state or reflect those of the United States Government or any agency thereof.

PACIFIC NORTHWEST NATIONAL LABORATORY operated by BATTELLE for the UNITED STATES DEPARTMENT OF ENERGY under Contract DE-AC05-76RL01830

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cim_loader-0.2.0a0.tar.gz (241.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cim_loader-0.2.0a0-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file cim_loader-0.2.0a0.tar.gz.

File metadata

  • Download URL: cim_loader-0.2.0a0.tar.gz
  • Upload date:
  • Size: 241.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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}

File hashes

Hashes for cim_loader-0.2.0a0.tar.gz
Algorithm Hash digest
SHA256 8e4f8ec413cdb639a1adf20d95f27c08c80258fbbd4cfe3cd9d2eead55e5aab6
MD5 537c3236c52f48efd3e009897216ee1e
BLAKE2b-256 8a969029934f94f68ecb7d0a8a6e1a3972ab5f5ea44400d096e0232a4d13a83e

See more details on using hashes here.

File details

Details for the file cim_loader-0.2.0a0-py3-none-any.whl.

File metadata

  • Download URL: cim_loader-0.2.0a0-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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}

File hashes

Hashes for cim_loader-0.2.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 faac8e52aaf9d3ba764a92b87c419d85d3c18f54a155c9374cceb424c25f85d1
MD5 e2cbb15bf442f0f88c8c61e15f054c38
BLAKE2b-256 7f8fb24bbaf933dc5f57401520749a9ecbcae0e8764f021f762930e44a1a6152

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0a0 This release

2 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