Skip to main content

manedpy

Call .mnd scripts from Python, in-process — the JSON document /run.json returns, minus the socket.

from manedpy import maned as mnd

payload = {"x": [[2, 0], [0, 2]], "w": [[3, 4], [5, 6]]}
result = mnd.io.scoring(payload)

scoring.mnd must declare in::x and in::w: a payload key with no matching in:: is a 400. mnd.load(path) is the real API and mnd.io.<name> is sugar over it.

A response computed here is byte-identical to what maned-serve answers over HTTP for the same script and body — that is a CI fact, not a promise: tests/test_rest_parity.py launches maned-serve, POSTs the same bytes, and compares.

Installing

A wheel bundles libmaned_c in manedpy/_lib/. In a source checkout that directory is empty, so point $MANEDPY_LIB at a libmaned_c from a maned-capi-* tarball:

export MANEDPY_LIB=/path/to/maned-capi-*/lib/libmaned_c.dylib

The library is loaded by absolute path with ctypes.CDLL — no @rpath, no RPATH, no LD_LIBRARY_PATH. On load, manedpy checks that mnd_abi_version() falls in the range it accepts and asserts its mnd_response layout against the maned_c_abi.json shipped beside the library, which is what catches a stale or wrong-architecture $MANEDPY_LIB.

The API

Python Route
s.run(payload) / s(payload) POST /run.json → Result
s.frame(payload) POST /frame → Result
s.frame_csv(payload) POST /frame.csv → bytes
s.run_files(**named_bytes) POST /run multipart → {name: bytes} — the only way to get real PNG bytes back
s.health() GET /health → dict
s.inputs / s.outputs / s.routes cached from /health
s.request(method, target, content_type, body) the raw escape hatch: status, bytes, notes, nothing raised

Result is a dict subclass, so result["outputs"]["a"] and json.dumps(result) both work, plus .outputs, .profiles, .frames, .notes, .raw and .status.

Errors are a hierarchy under ManedError, all carrying .status, .body and .script: 400/413/431 → ManedInputError (also a ValueError), 404/405 → ManedRouteError, 500 → ManedRuntimeError (also a RuntimeError), 501 → ManedUnsupportedError, a load failure → ManedLoadError, and status 0 → ManedInternalError, which means an exception escaped the engine rather than any HTTP condition.

Scripts are cached on (realpath, mtime, size, flags), so editing a .mnd and re-running in the same REPL picks the change up. mnd.load(..., reload=True) and mnd.clear_cache() override that.

Threading

A Script takes a lock per call by default, which makes the routed case correct by construction. Non-routed scripts are provably safe to call concurrently on one handle, so mnd.load(path, concurrent=True) drops the lock — and is refused at load time if the script routes to a device.

Licensing — read this before packaging

The Python source in this repo is Apache-2.0. A built wheel is mixed-licence: it bundles libmaned_c, a proprietary-but-redistributable binary covered by section 3 of the maned LICENSE (shipped beside it as LICENSE-libmaned_c). pyproject.toml must use license-files listing both — never a bare Apache SPDX expression, which would misdescribe the wheel.

Known limits (by design, v1)

  • Calls cannot be interrupted. ctypes.CDLL releases the GIL, which is the point — but it also means a KeyboardInterrupt is not delivered until the native call returns. Ctrl-C in a REPL and "interrupt kernel" in Jupyter do nothing until then. Use multiprocessing with spawn for work long enough to want to cancel.
  • Relative data paths in .mnd files resolve against the process CWD, not the script's directory. maned-serve behaves the same way; load errors say so. Prefer absolute paths in scripts.
  • Windows is a non-goal. The serve and net layers are POSIX throughout.
  • set_kernel_threads is process-global; it changes timing, not values.
  • requests_served is not exposed: in-process it counts calls on one handle, which looks like a server metric and is not one.

Tests

python3 -m venv .venv && .venv/bin/pip install pytest
MANEDPY_LIB=/path/to/capi/lib/libmaned_c.dylib .venv/bin/python -m pytest

The suite walks the conformance corpus shipped in the capi tarball (<case>.mnd + .request.json + .expect.json, compared byte-for-byte), runs the REST-parity gate against a maned-serve subprocess ($MANED_SERVE, or a sibling binary in the workspace), and diffs _ffi.SIGNATURES against maned_c.h so the ctypes table cannot drift from the header.

Metadata

Release files for manedpy 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for manedpy 0.4.0
File Size Uploaded Provenance Actions
manedpy-0.4.0.tar.gz 35.2 kB Without provenance Details for manedpy-0.4.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for manedpy 0.4.0
File Interpreter ABI Platform Actions
manedpy-0.4.0-py3-none-manylinux_2_35_x86_64.whl Python 3 none Linux glibc 2.35+ x86-64 Details for manedpy-0.4.0-py3-none-manylinux_2_35_x86_64.whl
manedpy-0.4.0-py3-none-manylinux_2_35_aarch64.whl Python 3 none Linux glibc 2.35+ ARM64 Details for manedpy-0.4.0-py3-none-manylinux_2_35_aarch64.whl
manedpy-0.4.0-py3-none-macosx_11_0_universal2.whl Python 3 none macOS 11.0+ universal2 (ARM64, x86-64) Details for manedpy-0.4.0-py3-none-macosx_11_0_universal2.whl

Total release size: 8.9 MB

Release files / manedpy-0.4.0.tar.gz

Download URL manedpy-0.4.0.tar.gz
Size 35.2 kB
Tags Source
SHA-256 checksum
How to use checksums
157254950b01b48bbd5880ba2c2bee98d6a91134b0e476bc02a9b090f9bab4de
BLAKE2b-256 checksum
How to use checksums
1fc01214cf41c900c9d0a635fd5b8ee9a418eb3bd70d8676e3a1bc815702862c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / manedpy-0.4.0-py3-none-manylinux_2_35_x86_64.whl

Download URL manedpy-0.4.0-py3-none-manylinux_2_35_x86_64.whl
Size 3.5 MB
Tags Linux glibc 2.35+ x86-64 Python 3
SHA-256 checksum
How to use checksums
aeb8081430e5aea1cb1e43893917ed8ee9b12ef9d70f186be7a705e199deb7fb
BLAKE2b-256 checksum
How to use checksums
b24aedf450018a42cd043dfb15b33880946a95c406d45c0d27c24ef3ea3ea694
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / manedpy-0.4.0-py3-none-manylinux_2_35_aarch64.whl

Download URL manedpy-0.4.0-py3-none-manylinux_2_35_aarch64.whl
Size 3.4 MB
Tags Linux glibc 2.35+ ARM64 Python 3
SHA-256 checksum
How to use checksums
ac6485d20a70d6741047b4ec8ae5c92971c825dbca53c8fec444c3c70769ffd9
BLAKE2b-256 checksum
How to use checksums
9ce8da5d0a00b5720bdaca98618850282d9cd953b0f743863c5e49686f45f8fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / manedpy-0.4.0-py3-none-macosx_11_0_universal2.whl

Download URL manedpy-0.4.0-py3-none-macosx_11_0_universal2.whl
Size 2.0 MB
Tags Python 3 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
ef2b45cd9a3262c62d73d20f9797c4e822f9261f12290ad4bce6307e85726bc0
BLAKE2b-256 checksum
How to use checksums
6dd32fb6cb67a9e5a619d80d8278cfd25fd20bececcbb39679da10f497f01b7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for manedpy 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page