triplets.parser¶
CIM/RDF XML parser package.
Provides pluggable engines for parsing CIM RDF/XML to DataFrames or Arrow tables: - python_lxml_pandas (pure Python + lxml → pd.DataFrame, always available, default) - python_lxml_arrow (pure Python + lxml → Arrow RecordBatch, needs pyarrow) - cython_pugixml_arrow (Cython + pugixml C++ → Arrow RecordBatch, needs build + pyarrow)
Fallback: cython_pugixml_arrow → python_lxml_arrow → python_lxml_pandas
- Usage:
from triplets.parser import parse, read_rdf df = parse([“file.xml”, “data.zip”], engine=”python_lxml_pandas”) df = parse(path, engine=”auto”) # best available table = parse(path, return_type=”arrow”)
- triplets.parser.register_engine(name: str, module_or_factory: Any) None[source]¶
Register a custom engine for future extensibility.
- triplets.parser.get_engine(name: str = 'auto')[source]¶
Resolve engine name (with aliases) and return its module.
- triplets.parser.parse(list_of_paths_to_zip_globalzip_xml: str | List | Any, debug: bool = False, max_workers: int | None = None, engine: str = 'auto', return_type: str = 'pandas', categorical_columns: Sequence[str] | None = ('INSTANCE_ID', 'KEY'), **kwargs: Any) Any[source]¶
Main entry: parse CIM RDF/XML (or zips) using chosen engine.
- Parameters:
debug (bool, default False) – Enable verbose debug output (file discovery, row counts, timing in some engines, etc.). When False but the logger is at DEBUG level (logging.basicConfig(level=logging.DEBUG) or getLogger(“triplets.parser”).setLevel(logging.DEBUG)), debug output is auto-enabled.
engine (str, default "auto") – Parser engine. “auto” picks best available. Options: “python_lxml_pandas”, “python_lxml_arrow”, “cython_pugixml_arrow”.
return_type (str, default "pandas") – Output format: “pandas”, “arrow”, or “polars”.
categorical_columns (tuple or None, default ("INSTANCE_ID", "KEY")) – Columns to dictionary-encode for memory savings. Pass None to disable.
- triplets.parser.read_rdf(*args: Any, **kwargs: Any) Any[source]¶
Alias for parse (for pandas.read_rdf registration).
triplets.parser.python_lxml_pandas¶
python_lxml_pandas engine: pure Python + lxml → list-of-tuples → pandas DataFrame.
The default parser engine. Requires only lxml + pandas (core deps, no pyarrow). Restored from the original rdf_parser.py load_RDF_to_list logic with fixes: - rdf:nodeID support (parity with arrow engines) - Empty string instead of None for missing values (parity with arrow engines) - Namespace map None key → “” (lxml uses None for default namespace)
- triplets.parser.python_lxml_pandas.load_rdf_to_dataframe(path_or_fileobject: str | IO, debug: bool = False) DataFrame[source]¶
Parse single RDF/XML file to pandas DataFrame using lxml + list-of-tuples.
This is the old proven path: lxml parse → iterate → build Python list → pd.DataFrame. No pyarrow dependency.
triplets.parser.python_lxml_arrow¶
triplets.parser.utils¶
Shared utilities for CIM/RDF XML parsers (python_lxml and cython_pugixml).
Extracted/adapted from rdf_parser.py and rdf_parser_lxml_arrow.py cues.
- triplets.parser.utils.clean_ID(ID: Any) str[source]¶
Removes ID prefixes used in CIM - urn:uuid:, #_, _ .