Skip to main content

Python bindings for rpic — the pic graphics language → SVG/PNG/PDF with animation.

Project description

rpiclang (Python)

Python bindings for rpic — the pic graphics language rendered to SVG / PNG / PDF, with animation manifests.

pip install rpiclang        # distribution name; you `import rpic`
import rpic

svg = rpic.render_svg('box "hi"; arrow; circle "x"')
open("out.png", "wb").write(rpic.render_png("box \"hi\"", scale=2.0))
open("out.pdf", "wb").write(rpic.render_pdf("box \"hi\""))

# circuit library (or write `copy "circuits"` in the source itself):
svg = rpic.render_svg('A:(0,0); B:(2,0)\nresistor(A,B)', circuits=True)

# TeX math labels, exactly like `rpic -t`:
svg = rpic.render_svg('box "$-\\frac{T}{2}$" fit', texlabels=True)

# the parsed bundle: svg + animation manifest + diagnostics + warnings
bundle = rpic.compile('box\nanimate last box with "pop"')
bundle["animations"]   # [{"id": "s0", "effect": "pop", ...}]
bundle["diagnostics"]  # lines emitted by pic `print`
bundle["warnings"]     # structured warnings (ignored attributes, ...)
bundle["objects"]      # per-object geometry: {"id": "s0", "kind": "box",
                       #   "bbox": {x,y,w,h} | None, "line", "col", ...}
# (compile_json returns the same as a JSON string)

# `copy "file"` includes resolve relative to `base`:
svg = rpic.render_svg('copy "shim.pic"\nbox', base="path/to/dir")

# compiling untrusted source? fence or disable filesystem includes
# ("sandboxed" = only files inside `base`; "deny" = none at all;
#  the embedded `copy "circuits"` library always works):
svg = rpic.render_svg(user_source, base="jobs/42", include_policy="sandboxed")

Compile errors raise rpic.CompileError (a ValueError subclass, so old except ValueError code keeps working). str(exc) is the readable message; exc.info is the structured diagnostic for editors:

try:
    rpic.render_svg("bxo", circuits=True)
except rpic.CompileError as exc:
    exc.info  # {"message": ..., "line": 1, "col": 1, "end_col": 4,
              #  "file": None, "kind": "expected_token", "found": "`bxo`",
              #  "expected": "an object", "hint": "did you mean `box`?"}

Positions are always relative to your source — with circuits=True an error on your line 1 reports line 1, and a problem inside a copy include names it in info["file"] (None means your own input).

Test

maturin develop --release && pytest tests -q

Build

pip install maturin
cd bindings/python
maturin develop --release     # installs into the current environment
# or: maturin build --release  → wheels in target/wheels/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rpiclang-0.7.0.tar.gz (591.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rpiclang-0.7.0-cp39-abi3-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.9+Windows x86-64

rpiclang-0.7.0-cp39-abi3-manylinux_2_35_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.35+ x86-64

rpiclang-0.7.0-cp39-abi3-macosx_11_0_arm64.whl (5.5 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file rpiclang-0.7.0.tar.gz.

File metadata

  • Download URL: rpiclang-0.7.0.tar.gz
  • Upload date:
  • Size: 591.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rpiclang-0.7.0.tar.gz
Algorithm Hash digest
SHA256 48de4c585ebd66b245626264d1a7084d442ef0f2d125ee5708b34d9649589cb5
MD5 166873b2363092976340871ada9e92b0
BLAKE2b-256 d72509667bc4fde2608d378de0c14c8d3d82810b4fdc3cd9f6d0e5a0d073dad7

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpiclang-0.7.0.tar.gz:

Publisher: python.yml on milkway/rpic-lang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rpiclang-0.7.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: rpiclang-0.7.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 5.3 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rpiclang-0.7.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ef7df717c3136fc31127aeec324eee47b43f3a551300f2e89e73ee36f3bd9c3d
MD5 420ac442ca33e957c9ebd0e89c62b2d6
BLAKE2b-256 f04fcdcadc5b26dc7213f0c2ba473071c58c1fa6675e7a1164a7070b2f75cdbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpiclang-0.7.0-cp39-abi3-win_amd64.whl:

Publisher: python.yml on milkway/rpic-lang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rpiclang-0.7.0-cp39-abi3-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for rpiclang-0.7.0-cp39-abi3-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 7fad8dab8f20236bc3be6004d0975ee34a558017e643c0a6dcadd07b986b3964
MD5 7d5fca831289fa621c0d3dbcaeefb222
BLAKE2b-256 797aed71d2e52b454e252d1506929ba2b063394a338ed2c6d6253d5645a9469c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpiclang-0.7.0-cp39-abi3-manylinux_2_35_x86_64.whl:

Publisher: python.yml on milkway/rpic-lang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rpiclang-0.7.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rpiclang-0.7.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1f49dc875cbe03dd46c8a6ec6d7c0bcc40528d88182c3dae61551b3f2d548b9e
MD5 b543ea7ac61ec766bd8a6cd59bad8907
BLAKE2b-256 d056e6cdaade0f270604b011aa8d3af577e44fd23519052a93041b0154194113

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpiclang-0.7.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: python.yml on milkway/rpic-lang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page