A fast SXF parser, SFC writer and drawing converter for Python, powered by Rust and PyO3. Python 3.9 or later is supported.
日本語: SXF 形式の図面(SFC・P21)を Python で読み、編集し、書き出すライブラリです。説明はこのページの下にあります。
- Parse P21/SFC from a file path, text or bytes, with strict or lenient recovery.
- Create, edit and save SFC geometry, text, styles, groups, dimensions and hatches.
- Add elements, fills and shared parts in a single validated batch; export P21/P2Z with dimensions, hatches, attributes and images.
- Deliver drawings with SAF attributes and TIFF/JPEG dependencies.
- Export DXF or plot drawings with the optional matplotlib backend.
python -m pip install ezsxfFor plotting:
python -m pip install "ezsxf[plot]"The core package has no runtime Python dependencies. Prebuilt wheels are available for Linux x86-64/ARM64, Windows x86-64 and macOS x86-64/ARM64. Building from source requires Rust; see Contributing.
import ezsxf
doc = ezsxf.new_sfc("drawing.sfc", name="Drawing", paper="A1", orientation="landscape")
layer = doc.add_layer("Structure")
color = doc.add_color((32, 96, 160))
doc.add_line((10, 10), (100, 50), layer=layer, color=color)
doc.add_circle((50, 50), 10, layer=layer)
doc.add_text("SXF 日本語", (10, 80), height=3.5) # estimates a monospaced box width
doc.save("drawing.sfc")
doc.save_p21("drawing.p21")
parsed = ezsxf.parse_sfc("drawing.sfc", strict=True)
ezsxf.write_sfc(parsed, "copy.sfc")
print(len(parsed["typed_features"]))Use parse_p21 for P21 input. For existing SFC edits, start with edit_sfc(parsed).
SFC output uses CP932 and validates the complete model before saving. Excess
precision or unencodable text raises an error. Drawings with external SAF/image
files should be delivered with the bundle APIs.
python -m ezsxf parse sfc drawing.sfc --pretty
python -m ezsxf to-dxf drawing.sfc drawing.dxf
python -m ezsxf resave-sfc drawing.sfc copy.sfc
python -m ezsxf to-p21 drawing.sfc drawing.p21Run python -m ezsxf --help or see the CLI guide.
| Format | Support |
|---|---|
| SFC | All 34 SXF Ver.3.1 feature types are parsed with resolved hierarchy, style codes and attribute attachments. Saving and supported editing APIs retain the SFC model. |
| P21/P2Z output | AP202 output from SFC models includes curves/cubic splines, point markers, text, dimensions/leaders, fills/hatches, styles, subfigures and attributes. P21 bundles and P2Z include validated SAF/images. See P21 writing and bulk authoring/preflight. |
Model preservation and third-party CAD display/re-export have separate limits. See compatibility for Japanese text, backslashes, groups, SAF and images. The package does not claim OCF certification.
Start with the documentation index, or choose a guide:
- Reading P21/SFC and parse results
- Saving existing SFC drawings
- Basic SFC creation, editing and style codes
- P21 export and interoperability checks
- Complex elements, groups, dimensions and hatches
- SAF attributes, images and bundle delivery
- Title-block attribute names
- DXF conversion and plotting
ezsxf は、SXF 形式の図面(SFC・P21)を Python で読み、編集し、書き出すライブラリです。SXF は、国土交通省の電子納品で使われる CAD データ交換の形式です。中身は Rust で、CAD ソフトは要りません。
- 読む: SFC と P21(ファイル、文字列、バイト列から。厳密に読むか、読めない箇所を飛ばして読むかを選べる)
- 作る・直す: SFC の図形、文字、線種と色、グループ、寸法、ハッチ
- 書き出す: SFC、P21・P2Z(寸法、ハッチ、属性、画像を含む)、DXF
- 表示する: matplotlib での描画(
ezsxf[plot])
python -m pip install ezsxfimport ezsxf
parsed = ezsxf.parse_sfc("drawing.sfc", strict=True) # P21 は parse_p21
print(len(parsed["typed_features"]))
ezsxf.write_sfc(parsed, "copy.sfc")コマンドラインでは python -m ezsxf to-dxf drawing.sfc drawing.dxf で DXF に、python -m ezsxf to-p21 drawing.sfc drawing.p21 で P21 にできます。
OCF 検定を受けたソフトではありません。ほかの CAD での表示と再保存については compatibility を見てください。
関連するライブラリ: Jw_cad の JWW は ezjww、DWG は ezdwg、複数の形式を 1 つの中間表現で扱うなら cad2d-ir。インストールせずにブラウザで SFC・P21 を開く・変換するなら zumen-gate が使えます。
See Contributing for source setup and checks, and Code of Conduct for participation guidelines. MIT licensed; see LICENSE.