Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
19f9449
Add numpy ndarray support
trevorprater Mar 26, 2026
529777b
Add comprehensive numpy parity test and fix 4 bugs
trevorprater Mar 26, 2026
d6df35e
Add resource limit checks and accept plain lists in elementwise numpy…
trevorprater Mar 26, 2026
09e8527
Fix ndarray bitwise invert and np.where shape validation (Codex review)
trevorprater Mar 26, 2026
836898d
Production-readiness fixes for numpy ndarray support
trevorprater Mar 27, 2026
bc54d08
feat(numpy): implement ~40 new NumPy operations for 100% LLM-common c…
trevorprater Mar 27, 2026
f636b99
fix(numpy): address review findings — input validation, docs, comments
trevorprater Mar 27, 2026
41d1e02
feat(numpy): add 100+ functions for comprehensive NumPy parity
trevorprater Mar 27, 2026
896fdbc
feat(numpy): Phase 2 — bitwise ops, setitem, iter, contains, in-place…
trevorprater Mar 27, 2026
6f2124b
feat(numpy): Phase 9 — ndarray methods (item, cumprod, squeeze, take,…
trevorprater Mar 27, 2026
825198c
feat(numpy): fix sort in-place, slice setitem with array RHS, add 200…
trevorprater Mar 27, 2026
f77cba6
feat(numpy): add //=, %=, **= in-place ops, .flat attr, .repeat()/.no…
trevorprater Mar 27, 2026
c73b459
Merge remote-tracking branch 'origin/main' into feat/numpy-only
trevorprater May 7, 2026
1252f29
Fix codespell hits in numpy CI
trevorprater May 7, 2026
72eab08
Add audited NumPy alias coverage
trevorprater May 7, 2026
b53922b
Match CI Python formatting
trevorprater May 7, 2026
60569d5
Add NumPy real-only introspection helpers
trevorprater May 7, 2026
b0bb902
Apply Python stub formatting
trevorprater May 7, 2026
9fef048
Stabilize NumPy memory limit assertion
trevorprater May 7, 2026
d80ee10
Add low-risk NumPy math ufuncs
trevorprater May 7, 2026
0ac04b2
Add NumPy shape index helpers
trevorprater May 7, 2026
0839d16
Add NumPy bitwise helpers
trevorprater May 7, 2026
26c6dff
Add NumPy window helpers
trevorprater May 7, 2026
a794e8f
Add NumPy integer representation helpers
trevorprater May 7, 2026
835f616
Add NumPy finite conversion helpers
trevorprater May 7, 2026
93fbc83
Add NumPy manipulation wrappers
trevorprater May 7, 2026
0bbdc11
Add NumPy linear numeric wrappers
trevorprater May 7, 2026
f1bc40a
Add NumPy unique result helpers
trevorprater May 7, 2026
a252e2e
Add NumPy dtype aliases
trevorprater May 7, 2026
4357006
Add NumPy index helpers
trevorprater May 7, 2026
f85a284
Add NumPy phase helpers
trevorprater May 7, 2026
eff2325
Add NumPy sorting helpers
trevorprater May 7, 2026
078cec7
Add NumPy statistical helpers
trevorprater May 7, 2026
7f00957
Add NumPy stack split helpers
trevorprater May 7, 2026
512ee26
Add NumPy in-place update helpers
trevorprater May 7, 2026
40bdca5
Add NumPy dtype metadata helpers
trevorprater May 7, 2026
4357128
Add NumPy runtime config helpers
trevorprater May 7, 2026
6d30026
Add NumPy display helpers
trevorprater May 7, 2026
c148711
Add NumPy no-host runtime helpers
trevorprater May 7, 2026
9b09327
Add NumPy selection helpers
trevorprater May 7, 2026
3c744cd
Add NumPy histogram helpers
trevorprater May 7, 2026
2007214
Add NumPy multidimensional histograms
trevorprater May 7, 2026
000604a
Add NumPy polynomial helpers
trevorprater May 7, 2026
bddbc7d
Add NumPy dtype category predicates
trevorprater May 7, 2026
c155bbf
Add NumPy polynomial division helpers
trevorprater May 7, 2026
3797946
Add NumPy iterator index helpers
trevorprater May 7, 2026
6b06a18
Add NumPy dtype info helpers
trevorprater May 7, 2026
13ba23c
Add NumPy callable array constructors
trevorprater May 7, 2026
9fc607c
Add NumPy scalar metadata exports
trevorprater May 7, 2026
71a6c82
Add NumPy fromstring text parser
trevorprater May 7, 2026
66e1466
Optimize parser filename interning
trevorprater May 7, 2026
649cb7d
Implement NumPy broadcasting support
trevorprater May 7, 2026
1481608
Implement NumPy dtype and float formatting helpers
trevorprater May 7, 2026
9c9f3fe
Merge remote-tracking branch 'origin/main' into feat/numpy-only
trevorprater May 7, 2026
0575c7b
Implement NumPy tensor contraction helpers
trevorprater May 8, 2026
1f7d54d
Implement NumPy block assembly
trevorprater May 8, 2026
5b155a9
Complete NumPy core runtime coverage
trevorprater May 8, 2026
7c0d15e
Keep flatiter off the Value hot path
trevorprater May 8, 2026
331da18
Document built-in NumPy support
trevorprater May 8, 2026
31be82e
Address NumPy review feedback
trevorprater May 8, 2026
cd7bcb7
Implement NumPy compatibility markers
trevorprater May 8, 2026
3e7447b
Fix NumPy ndarray type display
trevorprater May 8, 2026
ec5da8b
Implement NumPy metadata dtype markers
trevorprater May 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ What Monty **can** do:
- Completely block access to the host environment: filesystem, env variables and network access are all implemented via external function calls the developer can control
- Call functions on the host - only functions you give it access to
- Run typechecking - monty supports full modern python type hints and comes with [ty](https://docs.astral.sh/ty/) included in a single binary to run typechecking
- Run many `import numpy as np` numeric array workloads with built-in NumPy support for arrays, dtypes, broadcasting, ufunc-style math, reductions, indexing, shape manipulation and common numeric helpers
- Be snapshotted to bytes at external function calls, meaning you can store the interpreter state in a file or database, and resume later
- Startup extremely fast (<1μs to go from code to execution result), and has runtime performance that is similar to CPython (generally between 5x faster and 5x slower)
- Be called from Rust, Python, or Javascript - because Monty has no dependencies on cpython, you can use it anywhere you can run Rust
Expand All @@ -41,7 +42,7 @@ What Monty **can** do:
What Monty **cannot** do:

- Use the rest of the standard library
- Use third party libraries (like Pydantic), support for external python library is not a goal
- Load arbitrary third party libraries (like Pydantic). NumPy support is built into Monty; it is not general package import support
- define classes (support should come soon)
- use match statements (again, support should come soon)

Expand All @@ -66,6 +67,30 @@ In very simple terms, the idea of all the above is that LLMs can work faster, ch

Monty can be called from Python, JavaScript/TypeScript or Rust.

### Built-in NumPy support

Monty includes a built-in `numpy` module for safe numeric array workloads. This is implemented inside the sandbox, so user code can write ordinary `import numpy as np` snippets without loading CPython's C-backed NumPy package or gaining host access.

```python
import pydantic_monty

code = """
import numpy as np

scores = np.array([[1, 2, 3], [4, 5, 6]])
weights = np.array([10, 20, 30])
weighted = scores * weights

(weighted.tolist(), weighted.sum(), scores.mean(), str(scores.astype('float').dtype))
"""

m = pydantic_monty.Monty(code)
print(m.run())
#> ([[10, 40, 90], [40, 100, 180]], 460, 3.5, 'float64')
```

The supported NumPy surface is the pure, sandbox-safe numeric core: `ndarray`, supported numeric dtypes, broadcasting, ufunc-style math and predicates, reductions, indexing, shape helpers, sorting/selection helpers, formatting helpers, and common construction/manipulation routines. Monty intentionally does not expose host-boundary or external-memory APIs such as file loaders/savers, `memmap`, DLPack, `ctypeslib`, or include-path discovery, and it does not aim to implement full submodule families such as `linalg`, `fft`, `random`, `ma`, `testing`, or `typing`.

### Python

To install:
Expand Down
23 changes: 17 additions & 6 deletions crates/monty-datatest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ struct TestConfig {
/// When true, wrap code in async context for CPython execution.
/// Used for tests with top-level await which Monty supports but CPython doesn't.
async_mode: bool,
/// When true, skip running this test on CPython.
/// Used for tests that require modules not available in the CPython test harness.
skip_cpython: bool,
/// When true, create a temporary directory with a known structure and mount it.
/// For Monty: mounted at `/mnt` with `OverlayMemory` mode.
/// For CPython: passed as real path. `root` variable injected into both.
Expand Down Expand Up @@ -172,14 +175,18 @@ fn parse_fixture(content: &str) -> (String, Expectation, TestConfig) {
.map(|line| line.trim_start_matches('#').trim())
.collect::<Vec<_>>();

let mount_fs = comment_lines.iter().any(|line| line.starts_with("mount-fs"));
let has_marker = |marker| {
comment_lines
.iter()
.any(|line| line.split_whitespace().next() == Some(marker))
};
let mount_fs = has_marker("mount-fs");
let mut config = TestConfig {
iter_mode: comment_lines.iter().any(|line| line.starts_with("call-external")) || mount_fs,
async_mode: comment_lines.iter().any(|line| line.starts_with("run-async")),
iter_mode: has_marker("call-external") || mount_fs,
async_mode: has_marker("run-async"),
skip_cpython: has_marker("skip-cpython"),
mount_fs,
skip_cpython_windows: comment_lines
.iter()
.any(|line| line.starts_with("skip-cpython-windows")),
skip_cpython_windows: has_marker("skip-cpython-windows"),
..Default::default()
};
// Check for "xfail=" directive
Expand Down Expand Up @@ -2372,6 +2379,10 @@ fn run_test_cases_cpython(path: &Path) -> Result<(), Box<dyn Error>> {
.display()
.to_string();

if config.skip_cpython {
return Ok(());
}

// Skip CPython tests that rely on POSIX path semantics when running on Windows
if cfg!(windows) && config.skip_cpython_windows {
return Ok(());
Expand Down
20 changes: 20 additions & 0 deletions crates/monty-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ const m = new Monty('x + y', { inputs: ['x', 'y'] })
const result = m.run({ inputs: { x: 10, y: 20 } }) // returns 30
```

## Built-in NumPy Support

Monty includes a built-in `numpy` module for pure numeric array workloads inside the sandbox. User code can import NumPy-style APIs without loading CPython's C-backed NumPy package or exposing host files, external memory, network access, or other host-boundary features.

```ts
const m = new Monty(`
import numpy as np

scores = np.array([[1, 2, 3], [4, 5, 6]])
weights = np.array([10, 20, 30])
weighted = scores * weights

weighted.tolist()
`)

const result = m.run() // returns [[10, 40, 90], [40, 100, 180]]
```

Supported NumPy behavior focuses on Monty's sandbox-safe numeric core: `ndarray`, supported numeric dtypes, broadcasting, ufunc-style math and predicates, reductions, indexing, shape helpers, sorting/selection helpers, formatting helpers, and common construction/manipulation routines. Host-boundary APIs, external-memory APIs, object/string/complex/datetime arrays, and full submodule families such as `linalg`, `fft`, `random`, `ma`, `testing`, and `typing` are intentionally outside this built-in subset.

## External Functions

For synchronous external functions, pass them directly to `run()`:
Expand Down
24 changes: 24 additions & 0 deletions crates/monty-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ print(m.run(inputs={'x': 10, 'y': 5}))
#> 50
```

### Built-in NumPy Support

Monty includes a built-in `numpy` module for pure numeric array workloads inside the sandbox. This lets user code import NumPy-style APIs without loading CPython's C-backed NumPy package or exposing host files, external memory, network access, or other host-boundary features.

```python
import pydantic_monty

code = """
import numpy as np

scores = np.array([[1, 2, 3], [4, 5, 6]])
weights = np.array([10, 20, 30])
weighted = scores * weights

(weighted.tolist(), weighted.sum(), scores.mean(), str(scores.astype('float').dtype))
"""

m = pydantic_monty.Monty(code)
print(m.run())
#> ([[10, 40, 90], [40, 100, 180]], 460, 3.5, 'float64')
```

Supported NumPy behavior focuses on Monty's sandbox-safe numeric core: `ndarray`, supported numeric dtypes, broadcasting, ufunc-style math and predicates, reductions, indexing, shape helpers, sorting/selection helpers, formatting helpers, and common construction/manipulation routines. Host-boundary APIs, external-memory APIs, object/string/complex/datetime arrays, and full submodule families such as `linalg`, `fft`, `random`, `ma`, `testing`, and `typing` are intentionally outside this built-in subset.

### Resource Limits

```python
Expand Down
Loading
Loading