# spd_view **Repository Path**: zhangsonggui/spd_view ## Basic Information - **Project Name**: spd_view - **Description**: spd是基于DL/T 2765-2024《输变电工程逻辑模型规范》的 Python 解析库,将四种 XML 文件格式(`.spd` / `.ipd` / `.cpd` / `.std`)反序列化为类型安全的 Pydantic 对象模型,并提供回写、交叉引用校验和命令行工具。 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-27 - **Last Updated**: 2026-06-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # spd — 输变电工程逻辑模型解析库 基于 [DL/T 2765-2024《输变电工程逻辑模型规范》](docs/architecture.md) 的 Python 解析库,将 `.spd` / `.ipd` / `.cpd` / `.std` 四种 XML 文件反序列化为类型安全的 Pydantic 对象模型,并支持回写、交叉引用校验与命令行工具。 ## 安装 ```bash uv sync ``` 要求 Python 3.12+,依赖 Pydantic v2。 ## 用法 ```python from spd import parse_spd, validate, write_spd # 解析 SPD 文件 spd = parse_spd("path/to/file.spd") # 变电站信息 print(spd.substation.name, spd.substation.desc) # 屏柜与装置 for region in spd.regions: for cubicle in region.cubicles: for device in cubicle.devices: print(device.name, device.class_) # 部件模板 for pt in spd.part_templates: print(pt.name, pt.class_, len(pt.components)) # 电缆 for cable in spd.cables: print(cable.name, cable.class_, cable.core_num) # 交叉引用校验 result = validate(spd) print("有效" if result.is_valid else f"{result.errors} 个错误") for issue in result.issues: print(f" [{issue.severity}] {issue.message} @ {issue.location}") # 回写 write_spd(spd, "output.spd") ``` 其他三种格式用法相同:`parse_ipd` / `parse_cpd` / `parse_std`,对应 `write_ipd` / `write_cpd` / `write_std`。 ## 命令行 ```bash uv run spd inspect path/to/file.spd # 打印结构树 uv run spd validate path/to/file.spd # 校验完整性(退出码 0/1) uv run spd convert in.spd out.spd # 解析后重新序列化 ``` ## 测试 ```bash uv run pytest # 全部 uv run pytest tests/test_parsers.py # 单文件 uv run pytest tests/test_parsers.py::test_xxx # 单用例 ``` ## 架构 详见 [docs/architecture.md](docs/architecture.md)。