pin-derive for Python
Python bindings for pin-derive, a small bidirectional constraint engine: declare cells and multidirectional relations, pin any subset, and the rest derive from the same network.
The TypeScript engine in the repository root is the reference implementation. This
package runs the Rust/wasm core through the wasmtime Python runtime and is held to
the same conformance fixtures.
Install
Once published:
pip install pin-derive
For development from this repository:
cd rust/python
pip install -e .
Usage
from pin_derive import PinDerive
engine = PinDerive() # loads the bundled wasm binary
snapshot = engine.solve({
"cells": [
{"id": "profit", "init": {"lo": 0, "hi": None}},
{"id": "price", "init": {"lo": 0, "hi": None}},
{"id": "margin", "init": {"lo": 0, "hi": None}},
],
"relations": [
{"type": "product", "z": "profit", "x": "price", "y": "margin"},
],
"pins": [
{"cell": "price", "value": {"lo": 50, "hi": 50}},
{"cell": "margin", "value": {"lo": 0.2, "hi": 0.2}},
],
})
print(snapshot["cells"])
# profit is derived as 10; price and margin are pinned.
Pass an explicit wasm path only when testing a freshly built development artifact:
engine = PinDerive("../target/wasm32-unknown-unknown/release/pin_derive_wasm.wasm")
Bundled wasm
The wheel includes pin_derive/_pin_derive_wasm.wasm as package data. The wasm is
platform-independent, so one pure-Python wheel can work across platforms while
wasmtime supplies the runtime. The binary is committed into the package source and
rebuilt/copied by release CI before building the wheel; this keeps pip install pin-derive from requiring a Rust toolchain.
To refresh it locally:
cd ../
cargo build --target wasm32-unknown-unknown --release
cp target/wasm32-unknown-unknown/release/pin_derive_wasm.wasm \
python/src/pin_derive/_pin_derive_wasm.wasm
Full project
See the main repository README for the engine model, TypeScript API, Rust port, and interactive docs site: https://github.com/nightwork-dev/pin-derive.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 pin_derive-0.4.1.tar.gz.
File metadata
- Download URL: pin_derive-0.4.1.tar.gz
- Upload date:
- Size: 91.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a0462aea4ab4c7cf1715588c15fe2847f76a4f418002d3f1a62ed9790f01484
|
|
| MD5 |
8cb096e8678bd9d5a5e047cc31b0b804
|
|
| BLAKE2b-256 |
47ad6a86a6a30e523c259d255339ab4735c74eb71ecf0e5b5b18f9e9909944a2
|
File details
Details for the file pin_derive-0.4.1-py3-none-any.whl.
File metadata
- Download URL: pin_derive-0.4.1-py3-none-any.whl
- Upload date:
- Size: 89.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf4ddc70cd8b6546b189f2607d33a8d306fdb88fc72197d0427945181dd5bb8f
|
|
| MD5 |
1104933f4bc10d3a4a89c904186049ec
|
|
| BLAKE2b-256 |
6dc99a801774a93cde3779306db4d0b4a6b04505a295c72605d560afad683822
|