This is a thin adapter library which implements a subset of rpds-py using pyrsistent. The provided functionality is sufficient to run the jsonschema test cases successfully.
In 2023, the jsonschema devs replaced the pure-Python pyrsistent library dependency with a binary dependency called rpds-py. This replacement was done in order to improve performance (as CPython is quite slow). However, PyPy users may still prefer the pure-Python version both for speed reasons and also to avoid the hassle of building binary packages.
(The rpds-py
API also just feels better than the pyrsistent
one, in my humble opinion. If I wanted to build something with persistent data structures, I would probably either use this module or rpds-py
.)
use case 1: I can't use rpds-py for whatever reason, some other package requires it, and I need a drop-in replacement
Pip doesn't seem to have a way to override or substitute dependencies (at least without disabling dependency resolution entirely). Therefore, I suggest running something like this:
# install package "pyrsistent-as-rpds-py"
pip install --no-index --no-build-isolation .
# install fake "rpds" package to make pip happy
cd extra/fake_rpds
pip install --no-index --no-build-isolation .
Now you can install jsonschema
or other packages that depend on rpds-py
normally.
Just add pyrsistent-as-rpds-py
to your requirements.txt / pyproject.toml dependencies like you would any other dependency. Then you can write:
from pyrsistent_as_rpds.auto import List
lst = List(1, 2, 3)
print(lst.rest)
This will try to import the original rpds-py
module first. If it fails (because rpds-py
is not installed), then it use the pure Python version instead.
This library needs at least one of rpds-py
or pyrsistent
to be installed. If you are an end-user application packager / system integrator, you must choose to install either pyrsistent-as-rpds-py[pyrsistent]
or pyrsistent-as-rpds-py[rpds-py]
. This is unfortunately necessary because pip does not support alternative dependencies (e.g., require either X or Y to be installed).