Migration from pygraph (v1.0.x)
If your project was using pygraph (v1.0.0 or v1.0.1), this guide explains the transition to pysafe-pickle in v1.1.0.
Why the Rename?
The package name on PyPI has always been pysafe-pickle (pip install pysafe-pickle). In v1.0.x, it was imported as import pygraph.
To eliminate confusion between the PyPI distribution name and Python code, the canonical import is now:
python
import pysafe_pickle as pspThe Zero-Breakage Bridge in v1.1.0
v1.1.0 was designed as a strictly backward-compatible minor release:
- Existing Code Continues to Run:
import pygraphworks with 100% identical behavior.from pygraph.migrations import migrateworks without errors.from pygraph.exceptions import PyGraphErrorworks without errors.
- Gentle Warning:
- Importing
pygraphemits aFutureWarning(stacklevel=2) indicating thatpygraphwill be removed inpysafe-pickle2.0.0. The shim stays available throughout v1.x. pygraphis a thin alias:pygraph.dumps is pysafe_pickle.dumps, andpygraph.migrations,pygraph.exceptions, andpygraph.picklerresolve to the same modules as theirpysafe_picklecounterparts.- To silence the warning while you migrate, update the import rather than filtering it.
- Importing
- Dual Binary Compatibility:
- Data files created with
v1.0.xstart with thePYGRmagic header. - The decoder accepts both the legacy
PYGRand the currentPSPKheader, with no warning when reading old data. - New payloads are always written with the
PSPKheader. - You can load old files without doing any data conversion!
- Data files created with
- Dual Attribute Support:
- Dataclasses with
__pygraph_version__are versioned just like those with__pysafe_pickle_version__(the new name takes precedence if both exist). See Schema Evolution for how migrations behave.
- Dataclasses with
How to Update Your Code
Updating takes less than a minute. Search and replace:
python
# Before (v1.0.x)
import pygraph
obj = {"name": "Alice"}
data = pygraph.dumps(obj)
restored = pygraph.loads(data)
@pygraph.migrate(from_version=1, to_version=2, type_name="User")
def migrate_user(state):
...python
# After (v1.1.0+)
import pysafe_pickle as psp
obj = {"name": "Alice"}
data = psp.dumps(obj)
restored = psp.loads(data)
@psp.migrate(from_version=1, to_version=2, type_name="User")
def migrate_user(state):
...Behavior Notes for Upgrading
- Anything loaded from old
PYGRfiles is rebuilt exactly like new data: as a generated class named after the original dataclass, or as your own class if you pass it withclasses=(v1.4.0+). Schema versions stored by v1.0.x (__pygraph_version__) drive migrations the same way. - Since v1.3.0, additional types are supported (arbitrary-size
int,bytearray,complex, lone-surrogate strings), and v1.4.0 addsdatetimetypes,Decimal,UUID, enums, namedtuples,collectionstypes and more. Older versions cannot read payloads that use these new types, but they can read payloads that do not. - Since v1.4.0 the library raises
UnsafeTypeError,DecodeError,HMACErrorandSchemaVersionError.from pygraph.exceptions import ...andpygraph.HMACErroretc. resolve to the same classes. They subclassTypeError/ValueError, so existing handlers keep working. hmac_keysigning and verification work since v1.4.0 (they raisedNotImplementedErrorbefore).