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.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.stemis the drawing's file name without extension (you can passstem=...). A/or\in a sheet name becomes_. - One bad sheet never stops the others. The summary has
doneandskipped(lists of names),failed(name -> error text) andsheets(one dict per sheet:ok,error,files,ms,render_ms,encode_ms,write_ms,width,height,warnings,stats). threads=Noneuses all cores.threads=1is one core.sheets=[...]renders only these sheets. A name that is not in the file is listed infailed.skip_existing=Trueleaves 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, 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.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cadrender-0.1.0.tar.gz | 649.3 kB | With provenance | Details for cadrender-0.1.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| cadrender-0.1.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for cadrender-0.1.0-cp310-abi3-win_amd64.whl |
| cadrender-0.1.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.1.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| cadrender-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details for cadrender-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| cadrender-0.1.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for cadrender-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
| cadrender-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details for cadrender-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl |
Total release size: 12.8 MB
Release files / cadrender-0.1.0.tar.gz
| Download URL | cadrender-0.1.0.tar.gz |
|---|---|
| Size | 649.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8228be40f26cab9983dfa2e8b3ce166b781b2ceea4effcc0cb0e80174c0e0bfd
|
|
BLAKE2b-256 checksum How to use checksums |
cad0dd9d1f7c1d0892612e2426329092fe7c5f2bdc7c2ec5e124da3523673f91
|
| 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 14, 2026.
Transparency logRelease files / cadrender-0.1.0-cp310-abi3-win_amd64.whl
| Download URL | cadrender-0.1.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ba6e5a0df78f24724c64650edf35d9b22ed9e21d1a119f0d5fc5509f736d9cbd
|
|
BLAKE2b-256 checksum How to use checksums |
eaad018c5621793f6f912e2d6a3dbb4ac12b2f069463eb7d8688e59dc2c882f1
|
| 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 14, 2026.
Transparency logRelease files / cadrender-0.1.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | cadrender-0.1.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
b65d38bca67def95760b028163f06676780a0ec4c86a08c935f862cc13d99102
|
|
BLAKE2b-256 checksum How to use checksums |
4b64ef9db602e4b90fb873fef4306e84b1c610c2f51192895809795e4cdd6642
|
| 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 14, 2026.
Transparency logRelease files / cadrender-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | cadrender-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
d9dad1596b5f32d2a83e012a68c5e67d4d1a10f16b7bef7fbb762dd47d5fd3a1
|
|
BLAKE2b-256 checksum How to use checksums |
16b312b55a2647e372191a359991a2c2a98311e7333c1d71ec8b111917602ad9
|
| 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 14, 2026.
Transparency logRelease files / cadrender-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | cadrender-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
25d7af36efd214fb6f1778a47cd905a1d70d4586da0138e5d866fd9a769916b8
|
|
BLAKE2b-256 checksum How to use checksums |
eb6cc95720ad17dd2fc01aaf59487dc46f2f4934937cbd5e0dbaddbea94757c3
|
| 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 14, 2026.
Transparency logRelease files / cadrender-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | cadrender-0.1.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 |
97eeea3693063f38cea251b012ddd285541310a7be5827bae6393dcac7a96149
|
|
BLAKE2b-256 checksum How to use checksums |
2f65ea9c21f6a5adc87e019a3b12e5f209e086616cfa7ef970718436061c8a40
|
| 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 14, 2026.
Transparency logSecurity for cadrender 0.1.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.
Attestation for cadrender-0.1.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 14, 2026.
Transparency logA 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.