AST-based Python compatibility checker for the Monty interpreter
Project description
monty-compat
AST-based Python compatibility checker for the Monty sandbox.
Parses the Monty Rust source to extract every implemented builtin function, type constructor, exception type, and stdlib module, then checks arbitrary Python code for unsupported features — without executing it.
Installation
pip install monty-compat
Or for development (from checkout):
pip install -e .
Quick start
from monty_compat import monty_compat
# One-shot check — loads capabilities from cache (or builds on first run)
# By default uses the latest *released* version of Monty (only_released=True)
ok, reasons = monty_compat("x = [i * 2 for i in range(10)]")
# ok=True, reasons=[]
ok, reasons = monty_compat("import json; json.loads('{}')")
# ok=False, reasons=["module 'json' is not supported by Monty"]
# Include unreleased changes from the main branch
ok, reasons = monty_compat(code, only_released=False)
# Force rebuild (ignores cache)
ok, reasons = monty_compat(code, cache='regenerate')
# Skip cache entirely, read from local monty checkout
ok, reasons = monty_compat(code, cache='off', monty_root='/path/to/monty')
Cache
Capabilities are cached at ~/.monty_compat/monty_{key}_compat.json.
- Default TTL: 12 hours
- Cache key is
latest-releasewhenonly_released=True(default), ormainwhenonly_released=False - Passing an explicit
monty_rootfalls back to the installedpydantic-montyversion as the key cache='regenerate'forces a rebuild and overwrites the cachecache='off'skips all cache I/O
Lower-level API
from monty_compat import MontyCapabilities
# Build from the latest release tag on GitHub (default)
caps = MontyCapabilities.from_github()
# Build from the main branch (includes unreleased changes)
caps = MontyCapabilities.from_github(only_released=False)
# Build from a local monty repo checkout
caps = MontyCapabilities.from_local('/path/to/monty')
# Inspect capabilities
caps.builtin_functions # frozenset: abs, all, any, bin, chr, …
caps.type_constructors # frozenset: int, str, list, dict, …
caps.exception_types # frozenset: ValueError, TypeError, …
caps.modules # frozenset: sys, typing, asyncio, pathlib, os, re, …
caps.module_attributes # dict: {'asyncio': {'gather', 'run'}, …}
# Check code
ok, reasons = caps.check_code(some_code)
# Pretty-print
print(caps.summary())
What is checked
| Pattern | Example | Check |
|---|---|---|
import X |
import json |
Is json a supported module? |
from X import Y |
from asyncio import subprocess |
Is Y in X's known attributes? |
| Builtin calls | eval(...) |
Is the builtin implemented in Monty? |
Supported modules (as of 2026-03)
| Module | Available attributes |
|---|---|
re |
search, match, sub, findall, … |
asyncio |
gather, run |
os |
getenv, environ |
pathlib |
Path |
sys |
platform, version, version_info, stdout, stderr |
typing |
Any, Optional, Union, List, Dict, Callable, … |
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
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 monty_compat-0.4.1.tar.gz.
File metadata
- Download URL: monty_compat-0.4.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed236f203ba86802fec5e9a25f689ea722343b80fb59749931c0e12dab8eb830
|
|
| MD5 |
5b04e317990092ea5b161b94ac78f979
|
|
| BLAKE2b-256 |
5a656a4dcf723829711c2594167b87f435d309a628655a5e88288c096e3d2f29
|
File details
Details for the file monty_compat-0.4.1-py3-none-any.whl.
File metadata
- Download URL: monty_compat-0.4.1-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9c4b0998834073284538332df4bdee89a2e024a11240a18936cf31857852346
|
|
| MD5 |
1b59c2beea1ad22352b9ab52b553da0e
|
|
| BLAKE2b-256 |
dab7a56456231998e481aa0f22c77fa40af92f93c4b3d694be2cbcc7f62c66a4
|