Registry / database / persistence

persistence

JSON →
library5.4pypypi✓ verified 84d ago

The `Persistence` package (version 5.4) provides a specific variant of the persistent base class, `Persistent`, implemented as an ExtensionClass. It is part of the Zope Foundation ecosystem and is primarily intended for use when ExtensionClass semantics are required. For general-purpose object persistence without these specific semantics, the `persistent.Persistent` class from the `persistent` distribution is typically recommended. The library is mature and receives occasional updates, with its most recent release in November 2025.

pip install Persistence
INSTALL
IMPORT
SIG · PERSISTENCE
P
persistence
databasepythonv5.4
Install
2.7s avg
Import
84ms
Disk
22MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.7s · import 0.084s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Persistent
from Persistence import Persistent
from persistent import Persistent
The `persistent` library provides a more general `Persistent` class. This `Persistence` library provides an ExtensionClass variant. Use the `persistent` library if ExtensionClass semantics are not needed.

Defines a basic persistent class using `Persistence.Persistent`. Note that for true persistence, this class needs to be instantiated and managed within a ZODB (Zope Object Database) context, which typically involves setting up a storage and connection.

from Persistence import Persistent class MyPersistentObject(Persistent): def __init__(self, value): self.value = value self.data = [] def add_data(self, item): self.data.append(item) # In a real ZODB application, this object would be managed by a Connection/Database. # Example: (requires ZODB setup, not runnable standalone for full persistence) # from ZODB import DB, FileStorage # import transaction # # storage = FileStorage.FileStorage('my_data.fs') # db = DB(storage) # conn = db.open() # root = conn.root() # # if 'my_obj' not in root: # root['my_obj'] = MyPersistentObject('initial_value') # transaction.commit() # # obj = root['my_obj'] # print(f'Initial value: {obj.value}, Data: {obj.data}') # obj.add_data('new_item') # obj.value = 'updated_value' # transaction.commit() # # print(f'Updated value: {obj.value}, Data: {obj.data}') # conn.close() # db.close()
Debug
Known issues
gotchaThe `Persistence` library provides a `Persistent` class that is an ExtensionClass. If you do not specifically require ExtensionClass semantics, it is recommended to use `persistent.Persistent` from the `persistent` distribution, which is the more common and general-purpose persistence base class.
fix
Evaluate your project's needs. If ExtensionClass is not a strict requirement, consider `pip install persistent` and `from persistent import Persistent` instead.
affects: All versions
breakingThis standalone `Persistence` release (and its related `persistent` package) is not recommended or supported with ZODB versions older than 3.11. ZODB 3.10 and earlier versions bundled their own internal version of the `persistent` package, which can lead to conflicts.
fix
Ensure your ZODB installation is version 3.11 or newer if you intend to use it with this standalone `Persistence` library. If using an older ZODB, rely on its bundled persistence mechanisms.
affects: < 5.0 (for standalone use with ZODB < 3.11)
breakingVersion 5.0 of `Persistence` (and the closely related `persistent` library) dropped support for older Python versions, specifically Python 2.7, 3.5, and 3.6.
fix
Upgrade your Python environment to 3.10 or newer (Persistence 5.4 requires >=3.10) to use `Persistence` version 5.0 or later.
affects: < 5.0
deprecatedThe function `persistent.cPersistence.simple_new` was removed in version 6.1 of the `persistent` library. While this is specifically for `persistent`, users migrating or confusing the two packages might encounter this if they relied on this function with older `persistent` versions.
fix
Avoid using `persistent.cPersistence.simple_new`. If migrating from older code, review its usage and replace it with appropriate object instantiation patterns.
affects: persistent >= 6.1
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'Persistence'
The `Persistence` package is not installed in the current Python environment, or the environment is not active.
fix
Ensure the package is installed: `pip install Persistence`. If using a virtual environment, ensure it is activated.
AttributeError: 'MyObject' object has no attribute '_p_oid'
This error typically occurs when an object intended to be persistent (inheriting from `Persistence.Persistent`) is instantiated or used outside of a properly initialized ZODB connection, or its persistence state is not correctly managed.
fix
Ensure objects inheriting from `Persistence.Persistent` are instantiated and operated upon within the context of an active ZODB database connection and managed by a ZODB Storage/Connection.
TypeError: object of type 'Persistence.Persistent' is not JSON serializable
Instances of `Persistence.Persistent` (or any custom class inheriting from it) are not natively JSON serializable. Attempting to directly serialize these objects using `json.dumps()` will fail.
fix
Implement custom JSON serialization for your persistent objects. This usually involves defining a `__json__` method or providing a custom `json.JSONEncoder` that knows how to convert your persistent object into a JSON-serializable dictionary or other basic types.
Upgrade
Version history
5.4latest on PyPI · released Nov 16, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
persistence — pip install persistence · libregistry