{"id":6234,"library":"schemdraw","title":"Schemdraw","description":"Schemdraw is a Python package for producing high-quality electrical circuit schematic diagrams. It allows users to create diagrams by adding circuit elements one at a time using Python methods. It supports a wide range of components including resistors, capacitors, diodes, transistors, opamps, logic gates, and can also generate timing diagrams, state machine diagrams, and flowcharts. The current version is 0.22 and it has an active development and release cadence.","status":"active","version":"0.22","language":"en","source_language":"en","source_url":"https://github.com/RonSheely/schemdraw","tags":["electrical engineering","circuit design","schematics","diagrams","plotting","drawing","education"],"install":[{"cmd":"pip install schemdraw","lang":"bash","label":"Basic Installation"},{"cmd":"pip install schemdraw[matplotlib]","lang":"bash","label":"With Matplotlib backend dependencies"},{"cmd":"pip install schemdraw[svgmath]","lang":"bash","label":"With Ziamath for SVG math rendering"}],"dependencies":[{"reason":"Required Python version","package":"python","optional":false},{"reason":"Optional backend for drawing output","package":"matplotlib","optional":true},{"reason":"Optional for SVG backend math rendering","package":"ziamath","optional":true}],"imports":[{"symbol":"schemdraw","correct":"import schemdraw"},{"symbol":"schemdraw.elements","correct":"import schemdraw.elements as elm"},{"note":"Older versions (pre-0.7, pre-PEP8) used 'SchemDraw' with a capital 'S'. The current recommended import is lowercase 'schemdraw'.","wrong":"import SchemDraw","symbol":"SchemDraw","correct":"import schemdraw"}],"quickstart":{"code":"import schemdraw\nimport schemdraw.elements as elm\n\nwith schemdraw.Drawing(file='basic_rc_circuit.svg') as d:\n    d += elm.Resistor().right().label('1Ω')\n    d += elm.Capacitor().down().label('10μF')\n    d += elm.Line().left()\n    d += elm.SourceSin().up().label('10V')\n# The drawing is automatically saved to 'basic_rc_circuit.svg' upon exiting the 'with' block.","lang":"python","description":"This quickstart code creates a simple RC circuit diagram and saves it as an SVG file. The `with schemdraw.Drawing():` context manager is the recommended modern approach for creating and saving drawings, handling display and saving automatically upon exit."},"warnings":[{"fix":"Upgrade to schemdraw version 0.14 or newer. Alternatively, for older versions, instantiate `Drawing` directly and use `d.add()` or `d +=` followed by `d.draw()` and `d.save()` outside a `with` block.","message":"The `Drawing` class introduced a context manager (`with schemdraw.Drawing():`) in version 0.14. Using the context manager syntax with older versions will result in an `AttributeError: __enter__`.","severity":"breaking","affected_versions":"<0.14"},{"fix":"To prevent this, set the Matplotlib backend to a non-GUI option (e.g., `matplotlib.use('Agg')`) *before* importing schemdraw. Instead of `d.draw()`, use `d.save('filename.svg')` to save the output or `d.get_imagedata()` to retrieve image data.","message":"When running schemdraw on headless servers or environments without a GUI display, calling `d.draw()` can lead to failures as it attempts to open an interactive Matplotlib window.","severity":"gotcha","affected_versions":"all"},{"fix":"Refactor custom `ElementCompound` subclasses to move segment definitions from `__init__` to a `setup` method.","message":"As of version 0.18, subclasses of `ElementCompound` must define their `Segments` within a `setup` method instead of the `__init__` method.","severity":"breaking","affected_versions":">=0.18"},{"fix":"Call `logicparse` directly, e.g., `d = logicparse('expression')`, and then call `d.draw()` or `d.save()` on the returned Drawing object.","message":"The `schemdraw.logic.logicparse` function returns a `Drawing` object itself and should *not* be placed inside a `with schemdraw.Drawing():` context manager. Doing so can result in blank output or unexpected behavior.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}