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

Uploaded CPython 3.9+Windows x86-64

rpiclang-0.8.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.8.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.8.0.tar.gz.

File metadata

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

File hashes

Hashes for rpiclang-0.8.0.tar.gz
Algorithm Hash digest
SHA256 ca1c21efcd383240c6b5b1e7654cc3017ce78b158f92414122ff10124f927fc6
MD5 ade79c3efc8b1962e3961308367d2e0d
BLAKE2b-256 4693faf7ec1a6fa2eccef294b6fa06a037805338603b33df20315791bb62a34f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: rpiclang-0.8.0-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.8.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5ba52bb6d172007ebfa974402163ca4358b3ed4cbb8917807045f132875f69e8
MD5 de9ce42bd9b17ff4a46621c9e5fc1153
BLAKE2b-256 3a904ef11b91225c9e77381187a494e9236597da322e849618f1b6ad723bdaeb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rpiclang-0.8.0-cp39-abi3-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 7f814bf2298cc3152f65477dc9f333f0d0f74fe1c5fbe3d434779b24e728686b
MD5 3245cf55af3e050c886c3b236e9aba85
BLAKE2b-256 ca6d7f4a21fe25d5f15346b37f36012fc6b01ed48cb68a720f460963f4103130

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rpiclang-0.8.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d53a188fb34d76784b3a4bd09ab0c2860280ab3dcca461b4846d4cb776b58226
MD5 b00a3293454c952c4d4c3f713ae672a4
BLAKE2b-256 b0fb42cd7705c1a783459bb994f0a6bfa7287156af5f01cbfaa578307f3d1964

See more details on using hashes here.

Provenance

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