Skip to main content

plone.uuid

This is a minimal package that can be used to obtain a universally unique identifier (UUID) for an object.

The default implementation uses the Python standard library uuid module to generate an RFC 4122-compliant UUID, using the uuid4() function. It will assign a UUID upon object creation (by subscribing to IObjectCreatedEvent from zope.lifecycleevent) and store it in an attribute on the object.

Why use an attribute and not annotations? The most common form of annotation is the one provided by IAttributeAnnotations. This stores annotations in a BTree in an attribute called __annotations__, which means that annotation values do not end up in the same ZODB persistent object as the parent. This is good for “large” values, but not very good for small ones that are frequently required, as it requires a separate ZODB object load.

Simple usage

To automatically assign a UUID to your objects using the default implementation outlined above, you should:

  • Make sure they implement plone.uuid.interfaces.IAttributeUUID. You can do this in code, via the implements() directive, or in ZCML, with a statement like:

    <class class="my.package.MyClass">
        <implements interface="plone.uuid.interfaces.IAttributeUUID" />
    </class>
  • Make sure that an IObjectCreatedEvent is fired for this object when it is first created.

Once the event handler has triggered, you can obtain a UUID by adapting the object to the IUUID interface:

from plone.uuid.interfaces import IUUID
uuid = IUUID(context)

The uuid variable will now be a (byte) string containing a UUID. If the UUID has not yet been assigned, adaptation will fail with a TypeError.

If you would rather get None instead of a TypeError, you can do:

uuid = IUUID(context, None)

UUID view

If you require a UUID in a page template or remotely, you can use the @@uuid view, which is registered for all objects that provide the IUUIDAware marker interface (which is a super-interface of the IAttributeUUID marker seen above).

For example:

<div tal:attributes="id string:uuid-${context/@@uuid}">
    ...
</div>

The view simply returns the UUID string as looked up by the IUUID adapter.

Customising behaviour

There are two primary customisation points for this package:

  • You can change the default UUID generating algorithm by overriding the unnamed utility providing the IUUIDGenerator interface. The default implementation simply calls uuid.uuid4() and casts the result to a str.

  • You can change the UUID storage by providing a custom IUUID adapter implementation. If you do this, you must also provide a mechanism for assigning UUIDs upon object creation, usually via an event handler. To obtain a UUID, use the IUUIDGenerator interface:

    from zope.component import getUtility
    from plone.uuid.interfaces import IUUIDGenerator
    
    generator = getUtility(IUUIDGenerator)
    uuid = generator()

    You should also make sure that instances with a UUID provide a sub-interface of plone.uuid.interfaces.IUUIDAware.

Changelog

3.0.0 (2026-05-18)

Internal:

  • Update configuration files. [plone devs]

3.0.0a1 (2025-11-19)

Breaking changes:

  • Replace pkg_resources namespace with PEP 420 native namespace. Support only Plone 6.2 and Python 3.10+. (#3928)

2.0.2 (2025-09-10)

Internal:

  • Move distribution to src layout [gforcada] (#4217)

2.0.1 (2024-01-22)

Internal:

  • Update configuration files. [plone devs] (237ff4c8, 6e36bcc4)

2.0.0 (2023-04-26)

Breaking changes:

  • Drop python 2.7 support. [gforcada] (#1)

Internal:

  • Update configuration files. [plone devs] (2ed8f544)

1.0.6 (2020-04-22)

Bug fixes:

  • Minor packaging updates. (#1)

1.0.5 (2018-01-18)

Bug fixes:

  • Fix package dependencies. [gforcada]

  • Fix documentation and uuid generator class name to reflect the fact that we use the uuid4 implementation instead of uuid1. [thet]

1.0.4 (2016-06-02)

Bug fixes:

  • Update setup.py url to point to github. [esteele]

  • Fixed issues preventing tests passing on Python 3 [datakurre]

1.0.3 (2012-05-31)

  • Use zope.browserpage. [hannosch]

  • Defensive UUID assignment in addAttributeUUID() handler: keep existing UUID value if handler called more than once, except in case of object copy event, where original and destination should have distinct UUID. [seanupton]

1.0.2 - 2011-10-18

  • Generate UUID without dashes. [elro]

1.0.1 - 2011-05-20

1.0 - 2011-05-13

  • Release 1.0 Final [esteele]

  • Add MANIFEST.in. [WouterVH]

1.0b2 - 2011-01-03

  • Add MutableUUID component [toutpt]

1.0b1 - 2010-11-27

  • Initial release

Release files for plone.uuid 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plone.uuid 3.0.0
File Size Uploaded
plone_uuid-3.0.0.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for plone.uuid 3.0.0
File Interpreter ABI Platform
plone_uuid-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / plone_uuid-3.0.0.tar.gz

Download URL plone_uuid-3.0.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fb64e08a08ffce78011a46c80d8e442c1c8047f62ad51392394e943726db477e
BLAKE2b-256 checksum
How to use checksums
37dedc33484ee86f254c52c66fa3047699dbd9194da1651d01a206f54593627c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / plone_uuid-3.0.0-py3-none-any.whl

Download URL plone_uuid-3.0.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da5a05db10ce645bea952bb92e9a51c74ec91749692b0c71b35fc568b4a62c7a
BLAKE2b-256 checksum
How to use checksums
43c434ca960715df4d75cd92979bb6dff602f25bdc0bcb057c6584f988bc6c03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page