Skip to main content

GitHub license Lint Test Downloads codecov

Monty: Python Made Even Easier

Monty is the missing complement to Python. It implements supplementary utilities that are not part of the standard library: transparent support for compressed files, JSON/YAML/msgpack serialization of arbitrary objects, design patterns such as cached_class, deprecation helpers, and many more.

Python comes with "batteries included", but in building several large scientific frameworks (most notably pymatgen), we found ourselves repeatedly writing the same small utilities. Monty collects these into a single, well-tested, dependency-light library. Where the standard library has since caught up, Monty delegates to it.

Monty supports Python 3.11+.

Installation

pip install monty
# or
uv add monty

Optional extras pull in dependencies for specific features:

Extra Enables
json Serialization of numpy, pandas, pint, pydantic, torch and bson objects
serialization msgpack support in dumpfn/loadfn
multiprocessing imap_tqdm progress bars
dev IPython-based install_excepthook
optional All of the above
pip install "monty[optional]"

Highlights

Transparent compressed I/O. zopen opens plain, .gz, .bz2, .xz and .lzma files with one call; reverse_readline reads large files from the end.

from monty.io import reverse_readline, zopen

with zopen("OUTCAR.gz", mode="rt", encoding="utf-8") as f:
    for line in reverse_readline(f):
        if "TOTAL-FORCE" in line:
            break

Serialization of arbitrary objects. Subclass MSONable to get as_dict()/from_dict() and JSON round-tripping for free; dumpfn/loadfn pick the format (JSON, JSON lines, YAML, msgpack) and compression from the file extension.

from monty.json import MSONable
from monty.serialization import dumpfn, loadfn


class Calculation(MSONable):
    def __init__(self, name: str, energy: float):
        self.name = name
        self.energy = energy


dumpfn(Calculation("relax", -3.42), "calc.json.gz")
calc = loadfn("calc.json.gz")  # -> Calculation instance

Scratch directories. ScratchDir runs a block in a temporary directory and copies results back on exit.

from monty.tempfile import ScratchDir

with ScratchDir(".", copy_from_current_on_enter=True, copy_to_current_on_exit=True):
    ...  # run an expensive calculation

Development helpers. Mark deprecations with an optional removal deadline, and guard code paths on optional dependencies.

from monty.dev import deprecated, requires

try:
    import torch
except ImportError:
    torch = None


@deprecated(replacement="new_func", deadline=(2028, 1, 1))
def old_func(): ...


@requires(torch is not None, "torch is required for this function.")
def train(): ...

Other modules include monty.design_patterns (cached_class, singleton), monty.functools (lazy_property, return_if_raise, timeout), monty.shutil (compress_dir, decompress_dir, gzip_dir), monty.os.path (zpath, find_exts), monty.re (regrep) and monty.collections (frozendict, AttrDict, tree).

See the official docs for the full API.

Development

git clone https://github.com/materialyzeai/monty.git
cd monty
uv sync --all-extras
uv run pytest
uv run ruff check src && uv run ruff format src
uv run mypy -p monty

Metadata

Release files for monty 2026.10.21

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

Source distribution (sdist)

Source distribution for monty 2026.10.21
File Size Uploaded Provenance
monty-2026.10.21.tar.gz 257.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for monty 2026.10.21
File Interpreter ABI Platform
monty-2026.10.21-py3-none-any.whl Python 3 none any Details

Total release size: 321.2 kB

Release files / monty-2026.10.21.tar.gz

Download URL monty-2026.10.21.tar.gz
Size 257.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9580d17c63a45d02105d9f3ab19c463a08a768a844ef09a61e6fa92cad6eedd5
BLAKE2b-256 checksum
How to use checksums
2cf14de1afef798eb51c5de7e7628670de462e556f90e4339c16d29b2d1a3f48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / monty-2026.10.21-py3-none-any.whl

Download URL monty-2026.10.21-py3-none-any.whl
Size 63.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b83891666ea9eb0d81fa1ebde17bfbd12056018aac231a7d7dd372224170bb5
BLAKE2b-256 checksum
How to use checksums
5b8fe3666ee61653ad455b1416fbc3ba7ba66169329abaee6c283ffa751c9e5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for monty 2026.10.21

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.

Release history Release notifications | RSS feed

This release

2026.10.21 This release

2 release files No provenance

0.0.1

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