Read-only Python tools for parsing binary CGM (ISO/IEC 8632) files and exporting image-related data as raw payloads, SVG, and JSON.
Project description
python-cgm
Read-only Python tools for parsing binary CGM (ISO/IEC 8632) files and exporting image-related data as raw payloads, SVG, and JSON.
This package focuses on binary CGM parsing and extraction of image-bearing
Cell Array elements, plus best-effort vector conversion for vector-oriented
CGM content. It does not support writing CGM files.
Installation
Install the latest version using pip:
pip install python-cgm
What It Does
- Parses binary CGM command streams.
- Finds
Cell Arrayelements (class 4, element 9). - Extracts raw payload bytes from each image-bearing element.
- Converts vector-like CGM drawing primitives into a best-effort SVG.
- Exports parsed element data, payload metadata, and embedded SVG as JSON.
Quick Start
from cgm import (
extract_data_json,
extract_raw_images,
extract_raw_images_to_directory,
extract_vector_svg,
)
images = extract_raw_images("drawing.cgm")
print(f"Found {len(images)} raster payload(s)")
for image in images:
print(
image.index,
image.element_offset,
image.width,
image.height,
len(image.payload),
)
written = extract_raw_images_to_directory("drawing.cgm", "./out")
print("Wrote", len(written), "payload file(s)")
svg = extract_vector_svg("drawing.cgm")
print("SVG length:", len(svg))
snapshot_json = extract_data_json("drawing.cgm")
print("JSON length:", len(snapshot_json))
CLI
After installation, use the CLI to extract payloads directly:
cgm-extract file.cgm ./out
Export vector SVG:
cgm-extract file.cgm ./out --svg
Export parsed data snapshot as JSON:
cgm-extract file.cgm ./out --json
Export both SVG and JSON in one run:
cgm-extract file.cgm ./out --svg --json
Optional flags:
cgm-extract file.cgm ./out --stem payload
cgm-extract file.cgm ./out --debug
API
extract_raw_images(file_path) -> list[RawImage]extract_raw_images_from_bytes(data) -> list[RawImage]extract_raw_images_to_directory(file_path, output_dir, stem="image") -> list[Path]extract_vector_svg(file_path) -> strextract_vector_svg_from_bytes(data) -> strextract_vector_svg_to_directory(file_path, output_dir, stem="image") -> Pathextract_data_json(file_path) -> strextract_data_json_from_bytes(data) -> strextract_data_json_to_directory(file_path, output_dir, stem="image") -> Path
RawImage fields:
index: zero-based image index.element_offset: byte offset of the CGM element in the source file.payload: raw image payload bytes.width/height: best-effort dimensions when present in common binary layouts.
Scope And Limitations
- Supports binary CGM streams.
- Provides raw payload extraction for raster data, not full pixel decoding to PNG/JPEG.
- SVG output is best effort and depends on CGM command patterns in the file.
- JSON output can be large because it includes full element parameter/payload hex data.
- Does not support CGM writing.
License
python-cgm (C) 2026 Kestin Goforth.
This project is licensed under the BSD 3-Clause License - see the license file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_cgm-0.1.0.tar.gz.
File metadata
- Download URL: python_cgm-0.1.0.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f36cda01d6bb6502dae26cdbca1df50befb66cdc11474577f97e04c57be34f31
|
|
| MD5 |
fa8ecbd92e5b4aa69e0c475304783cb4
|
|
| BLAKE2b-256 |
6beb2c03dacd26b5b94c87ecd9e8c4386d4943be7ae9d0b322b5b1cbc0248266
|
Provenance
The following attestation bundles were made for python_cgm-0.1.0.tar.gz:
Publisher:
publish-to-pypi.yml on kForth/python-cgm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_cgm-0.1.0.tar.gz -
Subject digest:
f36cda01d6bb6502dae26cdbca1df50befb66cdc11474577f97e04c57be34f31 - Sigstore transparency entry: 2164771543
- Sigstore integration time:
-
Permalink:
kForth/python-cgm@bd0f4dc692495a15811452e620c7a47219ccbe00 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kForth
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@bd0f4dc692495a15811452e620c7a47219ccbe00 -
Trigger Event:
push
-
Statement type:
File details
Details for the file python_cgm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_cgm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9846babe0371ce5016327cb592b0037cd3fd679da9b329adc771aff8e5be1c6
|
|
| MD5 |
de275fa818a8507d9d462fabf871c90f
|
|
| BLAKE2b-256 |
7fd71bb1f392ea5ba316039d14404395325bd7a49343457ee4fe036a78296256
|
Provenance
The following attestation bundles were made for python_cgm-0.1.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on kForth/python-cgm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_cgm-0.1.0-py3-none-any.whl -
Subject digest:
a9846babe0371ce5016327cb592b0037cd3fd679da9b329adc771aff8e5be1c6 - Sigstore transparency entry: 2164771557
- Sigstore integration time:
-
Permalink:
kForth/python-cgm@bd0f4dc692495a15811452e620c7a47219ccbe00 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kForth
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@bd0f4dc692495a15811452e620c7a47219ccbe00 -
Trigger Event:
push
-
Statement type: