ghee for Python
pip install ghee-render: one package, two surfaces. It embeds the
ghee renderer, and it provides the
Python sugar for writing a
procedural scene.
Build the wheel yourself with maturin:
maturin build --release --compatibility linux
Use
To use the ghee renderer:
import ghee
h = ghee.open(
"scene.json", # a path, the JSON text of a scene, or a dict
output="st7789", # a driver name, "kms", or None for headless
opts={"width": 240, "height": 240, "backlight": 26},
width=None, height=None, # a headless size, a panel states its own
fps=30, # pace cap, None runs free
stats=8090, # console port, ("0.0.0.0", 8090) binds elsewhere
stream_max=None, # h264 stream cap: pixels, or a fraction of the render size
verbose=False,
timestep=None, # pin time to frame*S for a reproducible render
)
h.set_param("gain", 1.5) # a scene param
h.set_param("snap", 1.0, pass_="hold") # the param of one pass
h.set_param("hold.snap", 1.0) # the same param, dotted
h.feed("level", bars) # bytes, bytearray, memoryview, array, numpy, numbers
tick = h.frame() # {"frame": 12, "time": 0.4, "dt": 0.0166}
tick = h.skip() # the same tick, with no draw
h.size # (width, height)
h.components # 3 for RGB, 4 for RGBA
h.pixels() # the last frame, row-major (height, width, components)
h.close() # also a context manager
What each call does
set_param sets a live uniform, no recompile. A bare name is the scene
param, else the param of the first pass that declares it.
feed holds the data for one declared array, and the next frame consumes
it once. A uint8 buffer reaches the texture as byte / 255, a float32
buffer passes through. An array keeps its texture data until a feed
changes it.
frame draws and hands the frame to the output. time is the wall clock
since the first frame, dt is the measured frame period, and timestep
pins both to frame * S.
skip takes the tick and draws nothing, the panel keeps its last frame.
stats serves the console on 127.0.0.1, and a (host, port) pair binds
it elsewhere. Anyone who reaches the port can change params, so bind beyond
loopback only on a network you trust.
docs/http.md
holds the API. This console renders the one
scene its host opened, param changes apply, and scene switching and
recompiles are refused. The video stream advances with frame(): viewers
see a new frame only when the host draws one.
Rules
ghee is thread-affine: open a handle on one thread and use it on that same thread, a call from another thread raises RuntimeError.
A scene, GLSL or param error raises ValueError, a driver or system error raises RuntimeError.
A frame releases the GIL, so the host's other threads run while it renders.
Python scenes
The shim is used to write a procedural scene. A PEP 723 scene should
declare ghee-render inline:
#!/usr/bin/env -S uv run --script
# /// script
# dependencies = ["ghee-render"]
# ///
The shim gives:
ghee.Scene / Pass / Param / ArrayInput / Channel: build the sceneghee.Arg,ghee.args([...]): argument declarations, and the-- --helpanswer@ghee.feed("name"): the values of a named array, each tick. A uint8 buffer,bytesor a numpy uint8 array@ghee.tick: a hook for each tick, withghee.set_param(name, value)andghee.skip()ghee.run(scene): the handshake, then the tick loop
Direct mode
The same scene file runs two ways. When ghee starts it, as ghee render spectrum.py or from a scenes directory, run() feeds ghee over the
wire protocol.
When you run the file itself, run() opens the embedded renderer and
renders directly:
./spectrum.py --output kms --frames 300
./spectrum.py --bins 32 --output none --size 320x240 --frames 1
run() tells the two apart by GHEE_WIRE=1, which ghee sets in every
process it starts.
The scene takes its own arguments first, then these:
--output NAME: a driver name,kms, ornonefor a headless render (defaultkms)--size WxH: the render size. A display or a panel states its own--fps N,--stats PORT,--timestep S: asghee rendertakes them--frames N: 0 runs until SIGINT or SIGTERM (default 0)
The feeds, the hooks and ghee.skip() work the same. The tick keeps its
wire shape, with params empty. If one of your own arguments collides with
these names, argparse says so.
What the wire carries
The wire suits small per-frame data. Megabyte-scale data costs a
serialization and two copies for each frame, and on a small Pi that shows
up as a low frame rate. A data-heavy host takes ghee.open instead: the
renderer in the same process, no pipe.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ghee_render-0.3.0.tar.gz.
File metadata
- Download URL: ghee_render-0.3.0.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdcbdb57e0db960cea10176383f7cb88507c04e2be3eff891b26ed609883947d
|
|
| MD5 |
921bbef4fec1308dc410d26af9823e6f
|
|
| BLAKE2b-256 |
7af816f929b445515bb5bb03d01571e94754f60a585fbceb23f407f8641e9192
|
Provenance
The following attestation bundles were made for ghee_render-0.3.0.tar.gz:
Publisher:
release.yml on holofermes/ghee
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ghee_render-0.3.0.tar.gz -
Subject digest:
bdcbdb57e0db960cea10176383f7cb88507c04e2be3eff891b26ed609883947d - Sigstore transparency entry: 2340725956
- Sigstore integration time:
-
Permalink:
holofermes/ghee@3bf255acd8554666ba27335c208409e08a2d0032 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/holofermes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3bf255acd8554666ba27335c208409e08a2d0032 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ghee_render-0.3.0-cp39-abi3-manylinux_2_36_aarch64.whl.
File metadata
- Download URL: ghee_render-0.3.0-cp39-abi3-manylinux_2_36_aarch64.whl
- Upload date:
- Size: 843.5 kB
- Tags: CPython 3.9+, manylinux: glibc 2.36+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6875bd20b411c8b9230b10205201dd9fb62c925bf110b859fb76e2743f539250
|
|
| MD5 |
a52377fa8fd07e34f512e316aa10a6df
|
|
| BLAKE2b-256 |
c9a0c53168bbd8c5a93ef25115c8ec979f4a96fb8ee9a6ff52174eb0e5ce860b
|
Provenance
The following attestation bundles were made for ghee_render-0.3.0-cp39-abi3-manylinux_2_36_aarch64.whl:
Publisher:
release.yml on holofermes/ghee
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ghee_render-0.3.0-cp39-abi3-manylinux_2_36_aarch64.whl -
Subject digest:
6875bd20b411c8b9230b10205201dd9fb62c925bf110b859fb76e2743f539250 - Sigstore transparency entry: 2340725970
- Sigstore integration time:
-
Permalink:
holofermes/ghee@3bf255acd8554666ba27335c208409e08a2d0032 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/holofermes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3bf255acd8554666ba27335c208409e08a2d0032 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ghee_render-0.3.0-cp39-abi3-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: ghee_render-0.3.0-cp39-abi3-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 989.7 kB
- Tags: CPython 3.9+, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5d2671bcaed4872170c2a004a90978384a562944820e5ff114939ab98396652
|
|
| MD5 |
77a46e9980696ca2ff351700b24bc623
|
|
| BLAKE2b-256 |
c1957dc8ce299690fb6596c24a2a6539e1c8cb4a2e03deb0ee8543b3426c0f98
|
Provenance
The following attestation bundles were made for ghee_render-0.3.0-cp39-abi3-manylinux_2_35_x86_64.whl:
Publisher:
release.yml on holofermes/ghee
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ghee_render-0.3.0-cp39-abi3-manylinux_2_35_x86_64.whl -
Subject digest:
f5d2671bcaed4872170c2a004a90978384a562944820e5ff114939ab98396652 - Sigstore transparency entry: 2340725983
- Sigstore integration time:
-
Permalink:
holofermes/ghee@3bf255acd8554666ba27335c208409e08a2d0032 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/holofermes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3bf255acd8554666ba27335c208409e08a2d0032 -
Trigger Event:
release
-
Statement type: