{"id":2498,"library":"ezdxf","title":"ezdxf - DXF Drawing Manipulation","description":"ezdxf is a comprehensive Python package designed for creating, reading, modifying, and writing DXF (Drawing Exchange Format) documents. It supports a wide range of DXF versions from R12 to R2018 and aims to hide complex DXF details while providing extensive capabilities. The library is actively maintained, with frequent updates for bug fixes and new features, currently at version 1.4.3.","status":"active","version":"1.4.3","language":"en","source_language":"en","source_url":"https://github.com/mozman/ezdxf","tags":["CAD","DXF","drawing","geometry","vector graphics","automation"],"install":[{"cmd":"pip install ezdxf","lang":"bash","label":"Install core package"},{"cmd":"pip install ezdxf[draw]","lang":"bash","label":"Install with drawing add-on (for matplotlib/PyQt support)"}],"dependencies":[{"reason":"Required for type annotations in Python versions older than 3.10.","package":"typing_extensions","optional":false},{"reason":"Used for parsing DXF files.","package":"pyparsing","optional":false},{"reason":"Used for mathematical operations, especially in geometry and rendering.","package":"numpy","optional":false},{"reason":"Used for font metric calculation and rendering, particularly with the drawing add-on.","package":"fontTools","optional":false}],"imports":[{"note":"While 'from ezdxf import *' might work, it's generally discouraged in production code due to potential namespace pollution and difficulty in tracing origins. Sticking to 'import ezdxf' and using 'ezdxf.function()' is clearer.","wrong":"from ezdxf import *","symbol":"ezdxf","correct":"import ezdxf"}],"quickstart":{"code":"import ezdxf\n\n# 1. Create a new DXF R2010 document\ndoc = ezdxf.new(\"R2010\")\n\n# 2. Add entities to the modelspace (the main drawing area)\nmsp = doc.modelspace()\n\n# 3. Add a line from (0,0) to (10,0)\nmsp.add_line((0, 0), (10, 0))\n\n# 4. Add a circle with center (0,0) and radius 5\nmsp.add_circle((0, 0), 5)\n\n# 5. Save the DXF document\ndoc.saveas(\"my_first_drawing.dxf\")\nprint(\"Created 'my_first_drawing.dxf'\")","lang":"python","description":"This quickstart demonstrates how to create a new DXF document, add basic geometric entities (a line and a circle) to its modelspace, and save it to a DXF file. This is the fundamental workflow for generating DXF drawings with ezdxf."},"warnings":[{"fix":"Rename your script to something else, like 'my_dxf_script.py'.","message":"Naming your Python script 'ezdxf.py' will cause a circular import error (e.g., 'AttributeError: partially initialized module 'ezdxf' has no attribute 'readfile'').","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use layout methods like `layout.add_line()`, `layout.add_circle()`, etc., to create and add entities.","message":"Do not directly instantiate DXF entity classes (e.g., `Line(...)`) and try to add them to layouts. Always use the factory methods provided by the layout objects (e.g., `msp.add_line(...)`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of the target DXF version when saving. If preserving all data is critical, save to the same or a newer DXF version, or verify compatibility manually.","message":"Saving an existing DXF document to an older DXF version can lead to loss of data and attributes that are not supported in the target older version. ezdxf is not a DXF converter.","severity":"breaking","affected_versions":"All versions"},{"fix":"Understand that these specific entity types cannot be programmatically generated or altered by ezdxf. They will be preserved if loaded from an existing file, but not editable.","message":"ezdxf does not support creating or editing ACIS (3DSOLID, REGION, SURFACE) data or OLE objects. These are proprietary formats, and ezdxf only reads/preserves them without modification capabilities.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Wrap `ezdxf.readfile()` calls in a `try-except` block for `IOError` and `ezdxf.DXFStructureError`. For untrusted or potentially flawed files, use `doc, auditor = ezdxf.recover.readfile('messy.dxf')`.","message":"For DXF files with structural flaws or minor corruption, directly using `ezdxf.readfile()` may raise exceptions. The `ezdxf.recover` module provides functions (`recover.readfile()`) to load such files by repairing flaws, but it is a slower process.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the 'New Entity System' and 'API changes' sections in the v0.10 release notes if migrating from pre-0.10 versions. Rely on the high-level API for robustness.","message":"Version 0.10 introduced a complete rewrite of the entity system. While high-level API changes were minimized, users interacting directly with internal tag lists or migrating from very old versions might experience breaking changes. Unknown group codes will be lost if a modified DXF drawing is saved.","severity":"breaking","affected_versions":"<0.10 to >=0.10"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}