Zope: Transparent Persistence with ZODB
While the rest of the world is struggling with Object-Relational Mapping (ORM) and SQL, Zope developers are living in the future. The Zope Object Database (ZODB) is a native object database for Python that provides transparent persistence.
Transparent Persistence
In ZODB, you don't write INSERT or UPDATE statements. You just modify your Python objects, and ZODB tracks the changes.
import ZODB, ZODB.FileStorage
import transaction
# Setup the database
storage = ZODB.FileStorage.FileStorage('mydata.fs')
db = ZODB.DB(storage)
connection = db.open()
root = connection.root()
# Store an object
if not root.has_key('employees'):
root['employees'] = {}
employees = root['employees']
employees['bob'] = Employee(name='Bob', salary=50000)
# Commit the transaction
transaction.commit()
Persistence.Persistent
To make an object "trackable" by ZODB, it just needs to inherit from Persistence.Persistent.
from Persistence import Persistent
class Employee(Persistent):
def __init__(self, name, salary):
self.name = name
self.salary = salary
def give_raise(self, amount):
self.salary += amount
# ZODB automatically detects this change!
Transactions and MVCC
ZODB uses Multi-Version Concurrency Control (MVCC), meaning readers never block writers. Transactions ensure that your database remains consistent even if your Python script crashes mid-way. While it might not scale to the level of a massive Oracle cluster, for complex web applications with deeply nested data structures, ZODB is an absolute joy to use. No more SQL schema migrations!
Aunimeda builds backend systems with optimized database architectures - PostgreSQL, Redis, ClickHouse, and more.
Contact us for backend and database engineering. See also: Custom Software Development