Skip to main content

Parse, query and export CIM RDF/XML power-grid data as triplet DataFrames (pandas, polars, DuckDB)

Project description

About:

  • Parses CIM RDF/XML data to pandas dataframe with 4 columns [ID, KEY, VALUE, INSTANCE_ID] (triplestore like)
  • The solution does not care about CIM version nor namespaces
  • Input files can be xml or zip files (containing one or mutiple xml files)
  • All files are parsed into one and same Pandas DataFrame, thus if you want single file or single data model, you need to filter on INSTANCE_ID column

Documentation:

https://haigutus.github.io/triplets

Upgrading from 0.0.x? See docs/migration_0.0_to_0.1.md.

To get started:

# Core (python_lxml_pandas engine, no extra deps)
pip install triplets

# With pyarrow (enables python_lxml_arrow + cython_pugixml_arrow engines, ~12x faster)
pip install triplets[arrow]
import pandas
import triplets

path = "CGMES_v2.4.15_RealGridTestConfiguration_v2.zip"
data = pandas.read_RDF([path])

Result:

image

You can then query a dataframe of all same type elements and its parameters across all [EQ, SSH, TP, SV etc.] instance files, where parameters are columns and index is object ID-s

data.tableview_by_type("ACLineSegment")

image

Export:

data.export_to_cimxml(
    rdf_map=schemas.ENTSOE_CGMES_2_4_15_552_ED1,
    export_type=ExportType.XML_PER_INSTANCE_ZIP_PER_XML,
)

Look into examples folders for more

Parser engines

Three parser engines with automatic fallback (fastest available):

Engine Install Speed
python_lxml_pandas pip install triplets 1x baseline, always works
python_lxml_arrow pip install triplets[arrow] ~1x, better interop
cython_pugixml_arrow pip install triplets[arrow] (included in wheels) 12x faster

The cython_pugixml_arrow engine is a compiled C++ extension included in published wheels. It requires pyarrow at runtime, so install with triplets[arrow] to enable it.

The cython engine is pre-built in published wheels — no compilation needed.

Polars

import polars
import triplets

data = polars.read_rdf(["grid_EQ.xml", "data.zip"])   # returns polars DataFrame

data.triplets.get_types_count()
data.triplets.tableview_by_type("ACLineSegment")
data.triplets.filter_triplets(KEY="Type", VALUE=".*Generator.*", regex=True)
data.triplets.export_to_csv(export_to_memory=True)
data.triplets.export_to_nquads("/tmp/output.nq")

DuckDB

import duckdb
import triplets

data = duckdb.connect()                              # in-memory
data = duckdb.connect("grid.duckdb")                 # persistent (no re-parsing next session)

data.read_rdf(["grid_EQ.xml", "data.zip"])           # parse via Arrow (zero-copy into DuckDB)
data.get_types_count()                                     # → dict
data.tableview_by_type("ACLineSegment").df()             # → pandas DataFrame
data.tableview_by_type("ACLineSegment").pl()             # → polars DataFrame
data.filter_triplets(KEY="Type", VALUE=".*Sub.*", regex=True).df()
data.filter_triplets_by_type("Terminal").df()
data.references_to("some-uuid").df()
data.export_to_nquads("/tmp/output.nq")

# Direct SQL (full DuckDB SQL on the triplets table)
data.sql("SELECT VALUE, COUNT(*) FROM triplets WHERE KEY = 'Type' GROUP BY VALUE").df()

# The same tools are also on the `.triplets` namespace (parity with pandas/polars)
data.triplets.tableview_by_type("ACLineSegment").df()
data.triplets.get_types_count()

Accessor namespace

pandas and polars DataFrames use df.triplets.*; a DuckDB connection uses con.triplets.*. The same method names are available on both (DuckDB returns relations — add .df() or .pl() when needed):

# pandas / polars
df.triplets.tableview_by_type("ACLineSegment")
df.triplets.export_to_nquads("/tmp/output.nq")

# DuckDB
con.triplets.tableview_by_type("ACLineSegment").df()
con.triplets.get_types_count()

Root-level methods (df.type_tableview(...), con.filter_triplets(...)) still work for backwards compatibility.

CLI tools

cim-spreadsheet -i model.xml -o output.xlsx
cim-diff original.xml modified.xml

Performance (RealGrid, 1.14M rows)

Operation pandas polars DuckDB
Parse (cython engine) 128ms 156ms 283ms
tableview_by_type 72ms 21ms 53ms
filter_triplets_by_type 103ms 9ms 50ms
get_types_count 21ms 11ms 18ms

The old rdf_parser.py functions still work but emit deprecation warnings. See docs/migration_0.0_to_0.1.md for renames and breaking changes.

Project details


Download files

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

Source Distribution

triplets-0.1.0.tar.gz (2.6 MB view details)

Uploaded Source

Built Distributions

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

triplets-0.1.0-cp313-cp313-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.13Windows x86-64

triplets-0.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

triplets-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

triplets-0.1.0-cp312-cp312-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.12Windows x86-64

triplets-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

triplets-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

triplets-0.1.0-cp311-cp311-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.11Windows x86-64

triplets-0.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

triplets-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file triplets-0.1.0.tar.gz.

File metadata

  • Download URL: triplets-0.1.0.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for triplets-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b93bd88aecf918dbc0ea64c063aaf88611a2d8e046f0aefc6404321b419f2912
MD5 c745d45e6dcb2adb8459b5ede704cd04
BLAKE2b-256 96997bd034d0f228baf64bdb50724a5578d157387f576fb27802089cc0aeaa9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplets-0.1.0.tar.gz:

Publisher: build-wheels.yml on Haigutus/triplets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file triplets-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: triplets-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for triplets-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0c74fbf1c4e36cd5919cd80a41f9676958ea69e7bdec9dc515674811366dae9c
MD5 264785d7acdde8c1c6d723ddbbce6422
BLAKE2b-256 10ce3720c5e1bea747f269d0e3591fece41c81a3b393b7c7d93f0bf2ddc65921

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplets-0.1.0-cp313-cp313-win_amd64.whl:

Publisher: build-wheels.yml on Haigutus/triplets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file triplets-0.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for triplets-0.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ded701a6254e241bb51dd72741084e8361172929883865c36c83512cdf71ec0d
MD5 647f89b147c70e2ce54d4cbf95a4bedf
BLAKE2b-256 f64b3fe5403a170d66d90afeacc16c65be46a259c23199472d3216ef6d0786dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplets-0.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on Haigutus/triplets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file triplets-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for triplets-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c06f7109ab683236f1ddfecb1defc6f7fc1afcb5f81105e6fa337f542970adc2
MD5 d380667c6609df7be10d630ff676c135
BLAKE2b-256 31ec2668376b07c34ecd9e4da18bb7b7920b526cdaa6652393f63ef365597874

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplets-0.1.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on Haigutus/triplets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file triplets-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: triplets-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for triplets-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 962efa2bc9aebb5d877650bdde7a352bf9373c97b087239827da9718cccdf803
MD5 4c65c6d988e27f595bf6700ebdd52d17
BLAKE2b-256 2f64f7831733251c9a4e8c48706a988e72cc8373e0accd7090a102a3953b6021

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplets-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: build-wheels.yml on Haigutus/triplets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file triplets-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for triplets-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 018ed3c7431069a0ef1bcebc46332e353b53c8af5f8b9ecce959f28be3fded9d
MD5 fb15a0093ec5ee227660f1915092a20b
BLAKE2b-256 67bf50450db88eebf803f7fd8447680ffc3fbbcb6699b9fd7cd8ad321c3854c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplets-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on Haigutus/triplets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file triplets-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for triplets-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 56271be7dceeffd7af73c0e8085b73dd73e2624e26e2746368ccc393bfc3997c
MD5 a0c710fcbe468aa0c538d6081749563e
BLAKE2b-256 7d0faf90c3750d57241911ae9f4494046ae4c176bef1005d4c01355d4e58fbf1

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplets-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on Haigutus/triplets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file triplets-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: triplets-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for triplets-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f2b69499cc6c7b4f2cf090f9b3c06706fccbd966c1a2d8d4e82b77a736c0ad92
MD5 5c20e975e167813ce4a51c8b1c9ceaca
BLAKE2b-256 bdefc9b70dfa3f52d88bf815e70f6ded23a2793d17be6af07b38f691dd156587

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplets-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: build-wheels.yml on Haigutus/triplets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file triplets-0.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for triplets-0.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2d0d7357288e8886be47075416ad8e9c56373322cba808c723ab1974072bf04c
MD5 23992a777ffa025a4ba44cc4b3a35d33
BLAKE2b-256 19ef32bfe9606bc1ae9da7837c160d254330137b2230814ed5528c2f040a542c

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplets-0.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on Haigutus/triplets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file triplets-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for triplets-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6cb598aca4d195e4f4388b2248590013d20ba31c6036836d1f3ef1c5309ef74f
MD5 771211475321d13f4c5d8aa4e6b169bf
BLAKE2b-256 44f90d6c15e3604a40cb4f8541353637df84500c93e01d2b38985aeac52df03e

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplets-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on Haigutus/triplets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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