API Reference
uuid

def uuid(obj: Memo, /) -> str

Obtains unique object ID (UUID) of a memo instance.

Returns a stable handle that allows the object to be reliably fetched with dbzero.fetch() across sessions. The UUID is a base-32 encoded string, making it URL and API-friendly. A common pattern is to retrieve an object's UUID, store it externally (e.g., in a URL query parameter), and then use it later to fetch the full object from dbzero.

The UUID is tied to the object's identity, not its state; it remains constant even if the object's attributes change. While the UUIDs are unique, they are not cryptographically secure. They can potentially be guessed but do not leak any information about the object they identify.

dbzero.uuid() also works correctly on an expired dbzero.weak_proxy, returning the UUID of the original, now-deleted object.

Parameters

  • obj Memo
    A memo instance or weak proxy to get the UUID of.

Returns

The UUID as a base-32 encoded string.


Examples

Basic usage

# Create an object and get its UUID
user = User(name="Alex")
user_uuid = db0.uuid(user)
# -> e.g., 'C5I6A8K8N1Q2T4V7Z9X4Y6P3'
 
# The UUID can be serialized, for example, in JSON
import json
payload = json.dumps({"id": user_uuid})
 
# ... later, in a different part of the application ...
 
# Use the UUID to fetch the object
data = json.loads(payload)
retrieved_user = db0.fetch(data["id"])
 
assert user == retrieved_user

Getting own UUID during initialization

You can't call dbzero.uuid(self) directly inside a class's __init__ method, as the object isn't fully managed by dbzero yet. To get an object's own UUID during creation, you must obtain "materialized" instance from self with dbzero.materialized():

@db0.memo
class MyObject:
    def __init__(self):
        # Can't use db0.uuid(self) directly in __init__
        self.my_uuid = db0.uuid(db0.materialized(self))