Registry / serialization / schemdraw

schemdraw

JSON →
library0.23pypypi✓ verified 90d ago

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.

pip install schemdraw
INSTALL
IMPORT
SIG · SCHEMDRAW
S
schemdraw
serializationpythonv0.23
Install
3.8s avg
Import
1369ms
Disk
55MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.23 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.960 runs
installs and imports cleanly · install 0.0s · import 1.415s · 22.9MB
glibc
py 3.10–3.960 runs
installs and imports cleanly · install 3.8s · import 1.323s · 23MB
55MB installed
● package 55MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

schemdraw
✓ import schemdraw
schemdraw.elements
✓ import schemdraw.elements as elm
SchemDraw
✓ import schemdraw
✗ import SchemDraw
Older versions (pre-0.7, pre-PEP8) used 'SchemDraw' with a capital 'S'. The current recommended import is lowercase 'schemdraw'.

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.

import schemdraw import schemdraw.elements as elm with schemdraw.Drawing(file='basic_rc_circuit.svg') as d: d += elm.Resistor().right().label('1Ω') d += elm.Capacitor().down().label('10μF') d += elm.Line().left() d += elm.SourceSin().up().label('10V') # The drawing is automatically saved to 'basic_rc_circuit.svg' upon exiting the 'with' block.
schemdraw --version
Debug
Known issues
breakingThe `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__`.
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.
affects: <0.14
gotchaWhen 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.
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.
affects: all
breakingAs of version 0.18, subclasses of `ElementCompound` must define their `Segments` within a `setup` method instead of the `__init__` method.
fix
Refactor custom `ElementCompound` subclasses to move segment definitions from `__init__` to a `setup` method.
affects: >=0.18
gotchaThe `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.
fix
Call `logicparse` directly, e.g., `d = logicparse('expression')`, and then call `d.draw()` or `d.save()` on the returned Drawing object.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'schemdraw'
The schemdraw package has not been installed in the current Python environment.
fix
pip install schemdraw
NameError: name 'Resistor' is not defined
Circuit elements like `Resistor` are not directly available after `import schemdraw` and must be explicitly imported from `schemdraw.elements`.
fix
from schemdraw.elements import Resistor
RuntimeError: No backend specified, and no matplotlib backend found.
Schemdraw requires a rendering backend (like Matplotlib) to be installed and available to draw diagrams.
fix
pip install matplotlib
AttributeError: 'Resistor' object has no attribute 'draw'
Individual circuit elements do not have `draw()` or `save()` methods; they must be added to a `schemdraw.Drawing` object, which then handles the rendering.
fix
import schemdraw; from schemdraw.elements import Resistor; d = schemdraw.Drawing(); d += Resistor(); d.draw()
Upgrade
Version history
0.23latest on PyPI · released May 29, 2026
Audit
Dependencies
pythonrequiredRequired Python version
matplotliboptionalOptional backend for drawing output
ziamathoptionalOptional for SVG backend math rendering
Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
2
Resources
schemdraw — pip install schemdraw · libregistry