Interfaces for the unique id utility.

Note that most of these interfaces present identical method signatures to those of their zope.intid counterparts. This includes everything that comprises the IIntIds interface.

Note that the contracts for these APIs differs, primarily in not requiring IKeyReference support (however, the provided lifecycle event subscribers in zc.intid.subscribers do require this support).

The IIntIdsSubclass and event interfaces are new.

exception zc.intid.interfaces.IntIdMismatchError[source]

Bases: zope.intid.interfaces.IntIdMissingError

Raised from getId if the id of an object doesn’t match what’s recorded in the utility.

exception zc.intid.interfaces.IntIdInUseError[source]

Bases: ValueError

Raised by the utility when register tries to reuse an intid.

interface zc.intid.interfaces.IIntIdsQuery[source]

Finding IDs by object and objects by ID.


Return an object by its unique id

Raises:zope.intid.interfaces.ObjectMissingError – if there is no object with that id.

Get a unique id of an object.

queryObject(uid, default=None)

Return an object by its unique id

Return the default if the uid isn’t registered

queryId(ob, default=None)

Get a unique id of an object.

Return the default if the object isn’t registered


Return an iteration on the ids

interface zc.intid.interfaces.IIntIdsSet[source]

Establishing and destroying the connection between an object and an ID.


Register an object and returns a unique id generated for it.

If the object is already registered, its id is returned anyway.

If not already registered, the registration is made and an IIdAddedEvent is generated.


Remove the object from the indexes.

If the ob is not previously registered, this has no effect.

An IIdRemovedEvent is triggered for successful unregistrations.

interface zc.intid.interfaces.IIntIdsManage[source]

Some methods used by the view.


Return the number of objects indexed.


Return a list of (id, object) pairs.

interface zc.intid.interfaces.IIntIds[source]

Extends: zc.intid.interfaces.IIntIdsSet, zc.intid.interfaces.IIntIdsQuery, zc.intid.interfaces.IIntIdsManage

A utility that assigns unique ids to objects.

Allows to query object by id and id by object.

interface zc.intid.interfaces.IIntIdsSubclass[source]

Additional interface that subclasses can usefully use.


BTree family used for this id utility.

This will be either BTree.family32 or BTree.family64.

This may not be modified, but may be used to create additional structures of the same integer family as the refs structure.


BTree mapping from id to object.

Subclasses can use this to determine whether an id has already been assigned.

This should not be directly modified by subclasses.


Return a new iid that isn’t already used.

ob is the object the id is being generated for.

The default behavior is to generate arbitrary integers without reference to the objects they’re generated for.

This method may be overriden.

If this method returns an id that is already in use, register will raise an IntIdInUseError.

interface zc.intid.interfaces.IIdEvent[source]

Generic base interface for IntId-related events


The object related to this event


The int id utility generating the event.


The id that is being assigned or unassigned.

interface zc.intid.interfaces.IIdRemovedEvent[source]

Extends: zc.intid.interfaces.IIdEvent

A unique id will be removed.

The event is published before the unique id is removed from the utility so that the indexing objects can unindex the object.

interface zc.intid.interfaces.IIdAddedEvent[source]

Extends: zc.intid.interfaces.IIdEvent

A unique id has been added.

The event gets sent when an object is registered in a unique id utility.

interface zc.intid.interfaces.ISubscriberEvent[source]

An event fired by the subscribers in relation to another event.


The object related to this event


The ObjectEvent related to this event

interface zc.intid.interfaces.IAfterIdAddedEvent[source]

Extends: zc.intid.interfaces.ISubscriberEvent

Fired after all utilities have registered unique ids.

This event is guaranteed to be the last event fired by the subscribers that register ids. It will be fired exactly once, no matter how many utilities registered ids.

This has a similar purpose and structure to zope.intid.interfaces.IIntIdAddedEvent.


The dictionary that holds an (utility -> id) mapping of created ids

interface zc.intid.interfaces.IBeforeIdRemovedEvent[source]

Extends: zc.intid.interfaces.ISubscriberEvent

Fired before any utility removes an object’s unique ID.

This event is guaranteed to be the first event fired by the subscriber that removes IDs. It will only be fired if at least one utility will remove an ID.


Unique id utility.

This utility assigns unique integer ids to objects and allows lookups by object and by id.

This functionality can be used in cataloging.

class zc.intid.utility.IntIds(attribute, family=None)[source]

Bases: persistent.Persistent

This utility provides a two way mapping between objects and integer ids.

The objects are stored directly in the internal structures.


Generate an id which is not yet taken.

This tries to allocate sequential ids so they fall into the same BTree bucket, and randomizes if it stumbles upon a used one.