symdef
Standard-agnostic toolkit for graphical-symbol data. Symbols are TOML files; the toolkit loads them, resolves composition, lints the wiring contract, renders SVG, and builds a resolved JSON bundle plus a gallery. Data packages hold only data and reuse the toolkit and its gates, for any standard or your own; the toolkit is compatible with IEC.
Two doors: symdef is what a consumer draws with (load, orient, render, measure), and
symdef.authoring is what a library's author builds with (build, check, init, lint,
write_build, stale_build, RULES, finding_key, LibraryConfig). No name is on both.
Status: alpha. The toolkit the spec below describes is built: reading, resolving, linting, SVG and
the build, with every lint rule and gate proven by a failing fixture. Published on PyPI from v0.4.0;
v0.1.0 to v0.3.0 were git tags named graphical-symbols.
Every example symbol in this repository, the docs and the gallery included, is drawn
independently in the style of a published standard (for the S000xx numbers). None
is copied from a standard's own symbol database or drawings. Each is marked
status = "unverified": nobody has checked it against the standard.
Documentation: https://olejbondahl.github.io/symdef/ (tutorial, guide, symbol interface, API reference and a gallery).
Install
uv add symdef
or pip install symdef.
Python 3.14 or later. The one runtime dependency is fonttools, which measures a font's TrueType files.
The functions in symdef.files, symdef.project and symdef.cli read or write files, or
print. Everything else is pure: the same input gives the same output, with no file I/O, clock,
randomness or global state. The top-level symdef namespace re-exports both kinds. More
depth: docs/GUIDE.md.
The design
src/symdef/docs/SYMBOL_INTERFACE.html
is the binding, final spec. Open it in a browser; it ships as package data, readable at runtime
through importlib.resources.files("symdef").joinpath("docs/SYMBOL_INTERFACE.html").
The key ideas:
- A symbol is a definition: no tag, terminal numbers, position or orientation. Those belong to the placement in a drawing library.
- Port ids are roles (
in,out,anode, ...), never terminal markings (13,A1). - Electrical function is data: nodes and typed paths, so a consumer can netlist without per-symbol knowledge.
- Text lives in slots: the symbol reserves boxes for tags and terminal markings.
- Module units (M = 2.5 mm), a 0.125 M drawing grid and a 1 M wiring grid. A strict wiring contract is linted in all 8 orientations.
- Composition mirrors the standard: composites reference parts by anchor, no copied coordinates.
What is here
The data model and orient, the boxes and repeat, the TOML reader with its JSON Schema
(src/symdef/schema/symbol.schema.json), the composition resolver, 37 lint rules, plain and annotated SVG,
and the build (resolved JSON per symbol, the bundle, SVGs, a gallery README). Decisions the spec
leaves open, and concerns about the spec, are in docs/DECISIONS.md.
Use
A data repo has library.toml and symbols/<number>.toml; root below is its directory.
from symdef import load_library
from symdef.authoring import lint
from symdef.lint import RULES
library = load_library(root) # raises LibraryError, listing every problem in the files
contact = library.get("make-contact") # by number; iterating a library is sorted by number
assert (
len(RULES) == 37
) # the spec's 33 rules plus lead-off-port (D40), stretch-cut, element-outside-body (D98) and port-pattern (D104)
findings = lint(contact) # all 37 rules, geometric ones in all 8 orientations
assert findings == () # the spec's make contact lints clean
for finding in findings: # each has .rule, .severity, .message, .location, .orientation
print(finding.rule, finding.location, finding.message)
Symbols are immutable; orient, translate and repeat return new ones. A repeated symbol is
an ordinary symbol with ports such as 1.in and 3.out.
from symdef import Orientation, keepout_box, orient, repeat, to_svg
breaker = orient(repeat(contact, 3, port_format=library.port_format), Orientation.R0)
print(keepout_box(breaker))
svg = to_svg(breaker, annotate=True, texts={"tag": "-Q1"})
keepout_box is the body united with its bound leads; a slot is a text slot and never enlarges
it. only_ports(symbol, ports) keeps the listed ports with their leads and marking slots and drops
the rest, and stretch_to_ports(symbol, axis, edge, n) gives the length and offsets that
stretch takes to put n ports of an edge on the wire pitch. A port marked pattern repeats n
times along its edge, pattern_ports expands it; the guide has an example of each.
write_build writes build/ and src/<package>/bundle.json under the repo; stale_build lists
the files that differ from what it would write, so a test can fail when a committed build is out
of date. load_bundle reads a bundle back without the sources. <package> is the standard's
normalised name (lowercase letters and digits, D8): the example's standard is Example set, so its
package is exampleset.
from symdef import load_bundle
from symdef.authoring import stale_build, write_build
write_build(library, root)
assert stale_build(library, root) == ()
assert len(load_bundle(root / "src" / "exampleset" / "bundle.json")) == len(library)
Development
uv sync
just ci # format check, ruff, ty, vulture, purity gate, pytest with coverage
Coverage must stay at 100% (--cov-fail-under=100), so a partial run such as
uv run pytest tests/test_units.py fails on coverage alone: add --no-cov for one.
tests/test_readme.py runs the examples above and those in docs/GUIDE.md, so
they stay true. Agents: start at AGENTS.md.
License
MIT, see LICENSE.
Metadata
Release files for symdef 0.31.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 |
|---|---|---|---|---|
| symdef-0.31.0.tar.gz | 1.2 MB | With provenance | Details for symdef-0.31.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| symdef-0.31.0-py3-none-any.whl | Python 3 | none | any | Details for symdef-0.31.0-py3-none-any.whl |
Total release size: 1.3 MB
Release files / symdef-0.31.0.tar.gz
| Download URL | symdef-0.31.0.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3301db6a6299a90bc1e4c5a8a0e0118348bfa831282f77f4c00456e91c663e9e
|
|
BLAKE2b-256 checksum How to use checksums |
749fa9f46df0437cf8c77418246d2d0c0599890cff1cd62ebc7fa6574de78f43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 2, 2026.
Transparency logRelease files / symdef-0.31.0-py3-none-any.whl
| Download URL | symdef-0.31.0-py3-none-any.whl |
|---|---|
| Size | 166.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
085d00fc655c2004072df8619a927475249f94b6c9f27930695c2656303ab118
|
|
BLAKE2b-256 checksum How to use checksums |
0d86e29551eb7d276de2b3a620feec898f6107e56c3424eda0b383138c256a8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 2, 2026.
Transparency logSecurity for symdef 0.31.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
Both files in this release have been uploaded with provenance metadata.
Attestation for symdef-0.31.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 2, 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.