Skip to main content

PyPI version Python Versions License: MIT Code style: black codecov

CIMSPARQL Query CIM data using sparql

This Python package provides functionality for reading cim data from triple stores such as GraphDB, BlazeGraph or Rdf4j into Python memory as pandas dataframes.

The package provides a set of predefined functions/queries to load CIM data such as generator, demand or branch data, though the user can easily define their own queries.

Usage

Load data using predefined functions/queries

>>> from cimsparql.graphdb import ServiceConfig
>>> from cimsparql.model import get_single_client_model
>>> model = get_single_client_model(ServiceConfig(limit=3))
>>> ac_lines = model.ac_lines()
>>> print(ac_lines[['name', 'x', 'r', 'bch']])
         name       x       r       bch
0  <branch 1>  1.9900  0.8800  0.000010
1  <branch 2>  1.9900  0.8800  0.000010
2  <branch 3>  0.3514  0.1733  0.000198

In the example above the client will query repo "" in the default server GraphDB for AC line values.

Inspect/view predefined queries

See the sparql templates folder (cimsparql/sparql) to the query used.

Load data using user specified queries

>>> from string import Template
>>> query = 'PREFIX cim:<${cim}>\nPREFIX rdf: <${rdf}>\nSELECT ?mrid where {?mrid rdf:type cim:ACLineSegment}'
>>> query_result = model.get_table_and_convert(model.template_to_query(Template(query)))
>>> print(query_result)

Prefix and namespace

Available namespace for current graphdb client (gdbc in the examples above), which can be used in queries (such as rdf and cim) can by found by

>>> print(model.prefixes)
{'wgs': 'http://www.w3.org/2003/01/geo/wgs84_pos#',
 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
 'owl': 'http://www.w3.org/2002/07/owl#',
 'cim': 'http://iec.ch/TC57/2010/CIM-schema-cim15#',
 'gn': 'http://www.geonames.org/ontology#',
 'xsd': 'http://www.w3.org/2001/XMLSchema#',
 'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
 'SN': 'http://www.statnett.no/CIM-schema-cim15-extension#',
 'ALG': 'http://www.alstom.com/grid/CIM-schema-cim15-extension#'}

Running Tests Against Docker Databases

Tests can be run against RDF4J databases if a container with the correct images are available.

docker pull eclipse/rdf4j-workbench

Launch one or both containers and specify the following environment variables

RDF4J_URL = "localhost:8080/rdf4j-server"

Note 1: The port numbers may differ depending on your local Docker configurations. Note 2: You don't have to install RDF4J or BlazeGraph. Tests requiring these will be skipped in case they are not available. They will in any case be run in the CI pipeline on GitHub (where both always are available).

Test models

  1. micro: MicroGrid/Type1_T1/CGMES_v2.4.15_MicroGridTestConfiguration_T1_NL_Complete_v2
  2. small: See separate documentation

Rest APIs

CimSparql mainly uses SparqlWrapper to communicate with the databases. However, there are certain operations which are performed directly via REST calls. Since there are small differences between different APIs you may have to specify which API you are using. This can be done when initializing the ServiceCfg class or by specifying the SPARQL_REST_API environment variable. Currently, RDF4J and blazegraph is supported (if not given RDF4J is default).

export SPARQL_REST_API=RDF4J  # To use RDF4J
export SPARQL_REST_API=BLAZEGRAPH  # To use BlazeGraph

Contributing

Contributions are always welcome and encouraged! Whether it's reporting a bug, suggesting an enhancement, or submitting a pull request, your input helps improve the project.

Development

Dependencies are managed through uv, install with uv sync.

It's recommended to install the pre-commit hooks so checks are run automatically on every commit. After installing pre-commit itself, install the hooks with pre-commit install. Checks are normally only run on modified files when committing, but you can run all checks on all files with pre-commit run --all.

Download files

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

Source Distribution

cimsparql-9.16.0.tar.gz (644.3 kB view details)

Uploaded Source

Built Distribution

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

cimsparql-9.16.0-py3-none-any.whl (69.7 kB view details)

Uploaded Python 3

File details

Details for the file cimsparql-9.16.0.tar.gz.

File metadata

  • Download URL: cimsparql-9.16.0.tar.gz
  • Upload date:
  • Size: 644.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cimsparql-9.16.0.tar.gz
Algorithm Hash digest
SHA256 eae0155748f60833aec9595fd2c1b35abec5ea64fcf3da0fa21fb3adba14acfe
MD5 80bde1e4a75b7d13b6c6f3e0a871e24e
BLAKE2b-256 c0772578c2947107513cc679ca710f53cdb4b9f0c20223c941606349dd2f5283

See more details on using hashes here.

File details

Details for the file cimsparql-9.16.0-py3-none-any.whl.

File metadata

  • Download URL: cimsparql-9.16.0-py3-none-any.whl
  • Upload date:
  • Size: 69.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cimsparql-9.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25d0d93d2e5dfe4cb8a0f5399212bc6cb4c9e3da5cf61b23621d805e51cd3919
MD5 7bccb12d5f36422abd8fa1dc1596de6a
BLAKE2b-256 b1ec48fdb9cf70e803bbe9713015dc642c8f2a7b47608192cb4d959909926510

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

9.16.0 This release

2 files

9.15.1

2 files

9.15.0

2 files

9.14.0

2 files

9.13.1

2 files

9.13.0

2 files

9.12.2

2 files

9.12.1

2 files

9.12.0

2 files

9.11.2

2 files

9.11.1

2 files

9.11.0

2 files

9.10.0

2 files

9.9.0

2 files

9.8.1

2 files

9.8.0

2 files

9.7.1

2 files

9.7.0

2 files

9.6.0

2 files

9.5.0

2 files

9.4.1

2 files

9.4.0

2 files

9.3.0

2 files

9.2.1

2 files

9.2.0

2 files

9.1.0

2 files

9.0.0

2 files

8.4.9

2 files

8.4.8

2 files

8.4.3

2 files

8.4.2

2 files

8.4.1

2 files

8.4.0

2 files

8.3.5

2 files

8.3.4

2 files

8.3.3

2 files

8.3.2

2 files

8.3.1

2 files

8.3.0

2 files

8.2.10

2 files

8.2.9

2 files

8.1.0

2 files

8.0.0

2 files

7.1.0

2 files

7.0.5

2 files

7.0.0

2 files

6.3.0

2 files

6.2.0

2 files

6.1.0

2 files

6.0.0

2 files

5.2.0

2 files

5.1.3

2 files

5.1.2

2 files

5.1.1

2 files

5.1.0

2 files

5.0.0

2 files

4.4.3

2 files

4.4.2

2 files

4.4.1

2 files

4.4.0

2 files

4.3.1

2 files

4.3.0

2 files

4.2.1

2 files

4.2.0

2 files

4.1.2

2 files

4.1.1

2 files

4.1.0

2 files

4.0.0

2 files

3.3.1

2 files

3.2.1

2 files

3.2.0

2 files

3.1.0

2 files

3.0.0

2 files

2.17.0

2 files

2.16.0

2 files

2.15.0

2 files

2.14.0

2 files

2.13.0

2 files

2.12.1

2 files

2.12.0

2 files

2.11.0

2 files

2.10.2

2 files

2.10.1

2 files

2.10.0

2 files

2.9.0

2 files

2.8.0

2 files

2.7.3

2 files

2.7.2

2 files

2.7.1

2 files

2.7.0

2 files

2.6.7

2 files

2.6.6

2 files

2.6.5

2 files

2.6.4

2 files

2.6.3

2 files

2.6.2

2 files

2.6.1

2 files

2.6.0

2 files

2.5.1

2 files

2.5.0

2 files

2.4.2

2 files

2.4.1

2 files

2.4.0

2 files

2.3.3

2 files

2.3.2

2 files

2.3.1

2 files

2.3.0

2 files

2.2.2

2 files

2.2.1

2 files

2.1.1

2 files

2.1.0

2 files

2.0.1

2 files

1.12.1

2 files

1.12.0

2 files

1.10.3

2 files

1.10.1

2 files

1.10.0

2 files

1.9.1

2 files

1.9.0

2 files

1.8.1

2 files

1.8.0

2 files

1.7.1

2 files

1.7.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page