yaml-to-schemdraw
Generate schemdraw diagrams from YAML files or Python dictionaries.
pip install yaml-to-schemdraw
The following YAML spec:
V1:
- elements.SourceV
- label: ["5V"]
line1:
- elements.Line
- right: [0.75]
S1:
- elements.SwitchSpdt2: [{ action: close }]
- up
- anchor: ["b"]
- label: ["$t=0$", { loc: rgt }]
line2:
- elements.Line
- right: [0.75]
- at: ["S1.c"]
R1:
- elements.Resistor
- down
- label: ["$100\\Omega$"]
- label: [["+", "$v_o$", "-"], { loc: bot }]
line3:
- elements.Line
- to: ["V1.start"]
C1:
- elements.Capacitor
- at: ["S1.a"]
- toy: ["V1.start"]
- label: ["1$\\mu$F"]
- dot
Represents the equivalent Python code:
with schemdraw.Drawing() as d:
V1 = elm.SourceV().label('5V')
elm.Line().right(d.unit*.75)
S1 = elm.SwitchSpdt2(action='close').up().anchor('b').label('$t=0$', loc='rgt')
elm.Line().right(d.unit*.75).at(S1.c)
elm.Resistor().down().label(r'$100\Omega$').label(['+','$v_o$','-'], loc='bot')
elm.Line().to(V1.start)
elm.Capacitor().at(S1.a).toy(V1.start).label(r'1$\mu$F').dot()
And can be loaded with this library as follows:
Usage
from yaml_to_schemdraw import from_yaml_file
# "from_yaml_string" and "from_dict" are also available
diagram = from_yaml_file("diagram.yaml")
You can now call diagram.draw() or diagram.save("diagram.svg") as usual.
Why?
Schemdraw was always intended to be used as a Python library, with developers manually writing diagrams in code.
However, when it comes to accepting diagram definitions provided by clients through the network or originating from an untrusted environment, the naive approach of running arbitrary Python code with a function like exec() poses a significant security risk.
This module proposes an alternative, declarative way to represent Schemdraw diagrams as a YAML file or a Python dictionary.
How it works
The module parses the dictionary and resolves the function calls against the schemdraw library.
Internally, it uses getattr() to resolve function calls, with an attribute allowlist to prevent module escalation.
It can easily and safely parse most of the schemdraw circuit gallery.
If you encounter any valid diagrams that cannot be parsed (or easily adapted into something that this module can parse), please open an issue.
Metadata
Release files for yaml-to-schemdraw 0.1.2
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 |
|---|---|---|---|---|
| yaml_to_schemdraw-0.1.2.tar.gz | 9.4 kB | Without provenance | Details for yaml_to_schemdraw-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yaml_to_schemdraw-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for yaml_to_schemdraw-0.1.2-py3-none-any.whl |
Total release size: 17.5 kB
Release files / yaml_to_schemdraw-0.1.2.tar.gz
| Download URL | yaml_to_schemdraw-0.1.2.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5abd2ff5cdf8b9eae9317659e7d6a6434eb7a2eaeda651c00ec57cf3bd52b55c
|
|
BLAKE2b-256 checksum How to use checksums |
63d1270eaf7e12730f3487af87f9310fd4f147172700c76d9a67e1f63bb50e12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / yaml_to_schemdraw-0.1.2-py3-none-any.whl
| Download URL | yaml_to_schemdraw-0.1.2-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d0bb3b6e330df667a760fbf59fee7b26cf5f13c63af00a08d96b6ddfa094e595
|
|
BLAKE2b-256 checksum How to use checksums |
385daa44c6f4f6352ff2c801169a50dc59479debbd04b01d2993138223cc3479
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for yaml-to-schemdraw 0.1.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.