Skip to main content

cadrender for Python

cadrender turns DXF and DWG drawings into PNG and SVG pictures, one picture per sheet (layout tab). It is written in Rust and is very fast: about 10 ms per sheet, so a drawing with 16 sheets takes well under half a second.

This package is a thin Python layer over the Rust library. It uses PyO3 (a tool to call Rust from Python) and maturin (a tool to build a Python wheel from Rust). A wheel is the file pip installs.

pip install cadrender

Quick start

import cadrender

doc = cadrender.open("drawing.dxf")        # read the file once (.dxf or .dwg)
print(doc.sheets)                          # ['01', '02', ...] in tab order
print(doc.info["version"], doc.info["parse_ms"])

png = doc.render("01", width=2000)         # bytes of a PNG file
doc.render_to("01", "out/01.png")          # or straight into a file
doc.render_to("01", "out/01.svg")          # SVG: the format comes from the extension

summary = doc.render_all("out/", threads=4)    # all sheets, in parallel
print(summary["done"], summary["failed"])
for s in summary["sheets"]:
    print(s["sheet"], s["ms"], s["files"])

The API

Call What it does
cadrender.open(path, font=None) Read a drawing. font: "auto" (Arial if installed, else Liberation Sans), "liberation", or a .ttf path.
doc.sheets Sheet names in tab order. Model space is not a sheet.
doc.info A dict: version, size_bytes, parse_ms, font, counts, skipped_types, reader_warnings.
doc.sheet_info() Sheets in tab order: sheet, order, paper (size_mm, margins_mm, limits, units_per_mm, psltscale).
doc.attributes(sheet=None) Block attributes: one dict per INSERT with attributes (sheet, block, layer, handle, position, values = {tag: value}). "Model" = model space.
doc.texts(sheet=None, layers=None) TEXT, MTEXT and MULTILEADER texts as plain text (sheet, layer, type, handle, text, position).
doc.render(sheet, width=2000, format="png", **options) One sheet as bytes.
doc.render_to(sheet, path, width=2000, format=None, **options) One sheet into a file. The format comes from the file extension. Returns the sheet's result dict.
doc.render_all(out_dir, width=2000, formats=("png",), threads=None, sheets=None, skip_existing=False, on_sheet=None, **options) Many sheets in parallel. Returns a summary dict.

render_all details:

  • File names are <stem>__<sheet>.png. stem is the drawing's file name without extension (you can pass stem=...). A / or \ in a sheet name becomes _.
  • One bad sheet never stops the others. The summary has done and skipped (lists of names), failed (name -> error text) and sheets (one dict per sheet: ok, error, files, ms, render_ms, encode_ms, write_ms, width, height, warnings, stats).
  • threads=None uses all cores. threads=1 is one core.
  • sheets=[...] renders only these sheets. A name that is not in the file is listed in failed.
  • skip_existing=True leaves a sheet alone when its files already exist.
  • on_sheet(name, result) is called after each sheet. It runs in a worker thread. If it raises, sheets that have not started are cancelled, and the exception is raised at the end.

Files are written to a temporary name first and then renamed. So a file never exists half written, even if the process is killed.

Options

Give options as keyword arguments, or as a RenderOptions object, or both (keyword arguments win):

from cadrender import RenderOptions

opts = RenderOptions(preset="none", color="true", background="#202020", full_detail=True)
png = doc.render("01", options=opts, lineweight="hairline")
Option Values
preset "preview" (default: grey look, paper lineweights, the Defpoints layer left out) or "none" (true colour, no clean rules)
color "mono" (grey levels) or "true" (real colours)
background "#RRGGBB", "#RRGGBBAA", "white", "black", "transparent" or (r, g, b[, a])
lineweight "paper" (true plot width), "preview" (ezdxf's rule, uses dpi), "hairline"
default_lw, min_lw_px, dpi default lineweight (1/100 mm), thinnest pen (px), dpi for the "preview" rule
frame, margin, max_height "extents" or "paper"; margin around the extents (0.05 = 5 %); highest picture height
full_detail True = no level-of-detail shortcuts (no dots, no grey bars for tiny text, no tint for dense hatches)
lod single limits, for example {"dot_px": 0.5}
clean False (no clean rules), True (the preset's), or {"layers": [...], "block_keywords": [...]}
draw_order, text_masks, wipeout_frames, parallel_viewports True / False
max_depth, max_visits safety limits for very deep or very big block trees

A wrong name or value raises cadrender.OptionsError. Typos are never ignored silently. The font is chosen in open(), because fonts are part of the opened drawing.

Errors

All errors are subclasses of cadrender.Error:

Error When Also a
OpenError the file cannot be read as a drawing OSError
DrawingNotFoundError the file does not exist FileNotFoundError
UnsupportedFormatError a file type cadrender does not read OpenError
SheetNotFoundError no sheet with that name KeyError
OptionsError a wrong option name or value ValueError
RenderError one sheet could not be drawn or written (render, render_to)

SVG: cadrender.SVG_AVAILABLE is True in every release build. format="svg" (or a .svg file name) writes SVG with real <text> elements.

Threads and the GIL

The GIL is Python's global lock: only one thread runs Python code at a time. cadrender lets go of the GIL while it reads, draws and writes. So other Python threads keep running, and you can call render on the same Document from many threads at once. on_sheet takes the GIL again, only for the call.

Speed

Measured on an Apple M4 (best of 3, width 2000, PNG):

Drawing Sheets 1 thread all threads CLI, all threads
real-world drawing, 12 MB DXF 10 0.17 s 0.06 s 0.09 s
real-world drawing, 52 MB DXF 16 0.43 s 0.18 s 0.21 s

For comparison, an ezdxf + matplotlib pipeline took 162 s for one hatch-heavy sheet of the second drawing. The PNG files are byte for byte the same as the CLI's.

Build and test

You need Rust (stable) and uv (or pip).

cd crates/cadrender-py
uv venv .venv --python 3.12                      # .venv is gitignored
uv pip install --python .venv/bin/python "maturin>=1.9.4,<2" pytest
.venv/bin/maturin build --release --out dist -i .venv/bin/python
uv pip install --python .venv/bin/python --reinstall dist/cadrender-*.whl
.venv/bin/python -m pytest -q                    # tests use the installed wheel
CADRENDER_SAMPLES=/path/to/folder .venv/bin/python -m pytest -q tests/test_real_samples.py   # opt-in

The wheel is abi3: one wheel works on every CPython from 3.10 up. The release workflow (.github/workflows/release.yml) builds wheels for Linux x86_64 and aarch64 (manylinux), macOS x86_64 and arm64, and Windows x86_64.

CADRENDER_SAMPLES is optional: point it at a folder with your own .dxf and .dwg files, and the test renders every sheet of every file.

The test drawing tests/data/three_sheets.dxf is made by tests/data/gen.py. The tests also open every hand-made DXF in crates/*/tests/data/.

Files

Cargo.toml, build.rs      Rust crate (PyO3); never links libpython
pyproject.toml            maturin settings: module cadrender._cadrender
src/lib.rs                open(), module setup
src/doc.rs                Document: sheets, info, metadata, render, render_to, render_all
src/batch.rs              render_all: rayon threads, callbacks, summary
src/render.rs             one sheet -> bytes / files, result dicts
src/options.rs            option dict -> RenderOptions (checks every key)
src/svg.rs                the SVG switch
python/cadrender/         the Python API, errors, RenderOptions, stubs
tests/                    pytest

Metadata

Release files for cadrender 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cadrender 0.2.0
File Size Uploaded Provenance Actions
cadrender-0.2.0.tar.gz 684.6 kB With provenance Details for cadrender-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for cadrender 0.2.0
File Actions
cadrender-0.2.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for cadrender-0.2.0-cp310-abi3-win_amd64.whl
cadrender-0.2.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for cadrender-0.2.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
cadrender-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for cadrender-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
cadrender-0.2.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for cadrender-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
cadrender-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for cadrender-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 13.2 MB

Release files / cadrender-0.2.0.tar.gz

Download URL cadrender-0.2.0.tar.gz
Size 684.6 kB
Tags Source
SHA-256 checksum
How to use checksums
da1c126da7de580796e234085a915bf6606d3ec9b5342e5200889933c6db2eaa
BLAKE2b-256 checksum
How to use checksums
37a4332c6a6d29f4ba58148b87c4b4f12bd225918f9637fc0412ad3222912204
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / cadrender-0.2.0-cp310-abi3-win_amd64.whl

Download URL cadrender-0.2.0-cp310-abi3-win_amd64.whl
Size 1.5 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d51ecb7588bb78c11ca8fc91ba0e307869ca4bb662f6b99a8c3e599a7763f74e
BLAKE2b-256 checksum
How to use checksums
ac3ea7a4920083f5573026e768e32441de446f2f3c1eb25f93dc4f91c91969a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / cadrender-0.2.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL cadrender-0.2.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 4.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
33edc9e9a67cea788fed58d270e4b9f4687f99b61a4ce0129315b7e899830119
BLAKE2b-256 checksum
How to use checksums
b1a8ca794968c4b6f6a6c270f8a042546f8c8d7a51b9b3acb097fb49b1e26caf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / cadrender-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL cadrender-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 3.8 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
54b9f5f5c584e18361b1478579f365dfecc8282d9d89b793170e55392c2c75c2
BLAKE2b-256 checksum
How to use checksums
c29884abafe83f343abe433275ae86802b73ef775f001b73ea3e56e04dd81784
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / cadrender-0.2.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL cadrender-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.5 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7945b19d8ad8626451c1cde8817f15957342319dd38dea2f51df40236d1a03ec
BLAKE2b-256 checksum
How to use checksums
be549b17aa036663bfcfda29ff23472227f6a32cd8725d173e8557a3813db9cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / cadrender-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL cadrender-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.5 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d61f0e2790061dd57f7a48ed4fb66282b157900e5fad364c1580fdc4bebb1f7b
BLAKE2b-256 checksum
How to use checksums
36030476fc98874a8bd2908d9f5300e8b368157a96cc10cdf8a2c6b1ad9e1f3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for cadrender 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for cadrender-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

6 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page