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")

# you can also cap evaluator work for pasted/shared documents:
svg = rpic.render_svg(user_source, max_loop_iterations=10_000, max_shapes=50_000)

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.11.1.tar.gz (629.0 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.11.1-cp39-abi3-win_amd64.whl (5.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

rpiclang-0.11.1-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.11.1-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.11.1.tar.gz.

File metadata

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

File hashes

Hashes for rpiclang-0.11.1.tar.gz
Algorithm Hash digest
SHA256 6d68634442d9f4da84c5e4355ab4dde1359b7f09a364022baa1c25aa23b35f12
MD5 e09b79c3eacb5f862b680e0895cc1244
BLAKE2b-256 456cbab57225711c4bb245e7528e1f5c6fd0757a1016f391024e9dfc71d344cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpiclang-0.11.1.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.11.1-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: rpiclang-0.11.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 5.4 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.11.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1f9482f4b7bd09bcc22d87ffee9cf7da0f8f2abc745770083b3850fbba7cc322
MD5 af052707d585d45fd1b6758725e5b92a
BLAKE2b-256 1f4566cc1a0aa1fa7b9dc42b433944a7ee08afa12e0658ebd1c38563758e647c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpiclang-0.11.1-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.11.1-cp39-abi3-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for rpiclang-0.11.1-cp39-abi3-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 6ee4546ddf8f4b3be5ee9d0d7bede4721ad4d9fad521980b0fd813836fed6838
MD5 2e1561359dffa52ded4047b20dee34de
BLAKE2b-256 8dc2877e69a1a746b87ec1d0b7b10a705aab0493871513da567f933e27b738dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpiclang-0.11.1-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.11.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rpiclang-0.11.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c9c750142d9daf28eac75941d3d6102a4ecbcd7e979c54bf7a8b4c0b37a65fde
MD5 bfc71681721601a96189df075db14628
BLAKE2b-256 1cf605ea43a345267b53622ad23307dfa5aa267c49fd57097142e67cfee7f2b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpiclang-0.11.1-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