Python schematic rendering library
Project description
PySchem
Describe schematics in Python. Render them as SVG.
PySchem is a Python library for building electronic schematics programmatically and exporting them as clean, readable SVG diagrams. No schematic editor required — just Python.
- Free software: MIT license
- Documentation: docs/development.md
Highlights
Clean SVG output: Automatic wire routing with obstacle avoidance, junction detection, and fit-to-content viewBox. Renders directly to SVG — no external tools needed.
KiCad symbol support: Load parts directly from KiCad .kicad_sym libraries. Works with any standard KiCad symbol collection.
Flexible styling: Control wire colors, label placement, pin visibility, component rotation, and more via a unified Style system.
Quick Example
A two-transistor RTL AND gate:
from pyschem import (
Part, Junction, NetLabel, GroundNet, NC, Schematic, Style,
RenderTemplate, WireStyle, connect, configure_default_symbols,
)
from pathlib import Path
symbol_dir = Path(__file__).resolve().parent / "kicad-symbols"
configure_default_symbols(symbol_paths=[str(symbol_dir)], preload=True)
sch = Schematic("and_gate")
q1 = Part("Transistor_BJT:Q_PNP_CBE", ref="Q1")
q2 = Part("Transistor_BJT:Q_PNP_CBE", ref="Q2")
r1 = Part("Device:R", ref="R1", value="10K")
r2 = Part("Device:R", ref="R2", value="10K")
r3 = Part("Device:R", ref="R3", value="10K")
r4 = Part("Device:R", ref="R4", value="10K")
r5 = Part("Device:R", ref="R5", value="10K")
nl_a = NetLabel("A", direction="left")
nl_b = NetLabel("B", direction="left")
nl_out = NetLabel("A_AND_B", direction="right")
vcc_q1 = NetLabel("VCC", direction="top")
vcc_q2 = NetLabel("VCC", direction="top")
gnd_l = GroundNet()
gnd_r = GroundNet()
nc_q2e = NC(q2.pin("E")) # Explicitly mark an intentionally floating pin.
sch.place(r1, x=20, y=25)
sch.place(r2, x=20, y=75)
sch.place(q1, x=65, y=50)
sch.place(q2, x=155, y=50)
# ... (place remaining parts and labels)
sch.add_part(nc_q2e)
# PySchem supports two equivalent connection styles:
# pin.connect(other) — concise two-pin form
# connect(pin_a, pin_b, ...) — multi-pin form, useful for tee junctions
nl_a.label_pin.connect(r1.pin("2"))
nl_b.label_pin.connect(r2.pin("1"))
connect(r1.pin("1"), r2.pin("2"), q1.pin("B")) # tee junction
q1.pin("C").connect(r4.pin("2"))
r4.pin("1").connect(q2.pin("B"))
q2.pin("C").connect(nl_out.label_pin)
template = RenderTemplate.from_style(Style(wire=WireStyle(color="#1565c0")))
sch.export_svg("out/and_gate.svg", template=template)
See examples/transistor_and_gate_svg.py for the full working example.
BOM Export
Add purchasing metadata to physical parts with bom_fields, then export a
grouped UTF-8 CSV BOM for spreadsheet tools:
r1 = Part(
"Device:R",
ref="R1",
value="10k",
footprint="Resistor_SMD:R_0603_1608Metric",
bom_fields={"Manufacturer": "Yageo", "MPN": "RC0603FR-0710KL"},
)
sch.export_bom("out/bom.csv")
Parts with the same value, footprint, library ID, and purchasing fields are combined into one row with a quantity and comma-separated reference list.
Installation
pip install pyschem
Or install from source:
git clone https://github.com/eirikr-zhong/pyschem.git
cd pyschem
pip install -e .
Getting Started
- Run the example:
cd examples && python3 transistor_and_gate_svg.py— output appears inexamples/out/ - Read the dev guide:
docs/development.mdcovers project structure, style system, and conventions
Features
| Feature | Status |
|---|---|
| KiCad symbol library support | ✅ |
| Automatic wire routing | ✅ |
| Obstacle avoidance | ✅ |
| SVG export with fit-to-content | ✅ |
| Custom viewBox override | ✅ |
| Debug overlay mode | ✅ |
| DOT graph export | ✅ |
| ERC (Electrical Rules Check) | 🚧 planned |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyschem-0.2.0.tar.gz.
File metadata
- Download URL: pyschem-0.2.0.tar.gz
- Upload date:
- Size: 223.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a66cc3ec7d893f9c157fb6ed0a38c92f189fe584d2035fb3995a24c81f4869d9
|
|
| MD5 |
7f3b9bad58101cd58354841accb1d00b
|
|
| BLAKE2b-256 |
0cc9688df9b9ad89be7306d244e6a9e5d633bec9d3c39045c8ae9a3d9425adb3
|
File details
Details for the file pyschem-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pyschem-0.2.0-py3-none-any.whl
- Upload date:
- Size: 68.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eed30cadee47d7bd78030a61c63d202a7cd7bfff44f6b4bdcdd1aa58059deadd
|
|
| MD5 |
668f107f9267026356e05c2b8fa32275
|
|
| BLAKE2b-256 |
1c71eb3f48a57c24318109062157638e256f547a22d401926bd22ad3a65f1169
|