Skip to content

4.0.0

Choose a tag to compare

@mdomke mdomke released this 20 Jul 15:21
4.0.0
aa8b06b

⚠️ Breaking changes

  • ValueProvider and the ULID.provider class attribute have been removed. ULID generation is now handled by the new ULIDGenerator together with pluggable monotonicity policies. Code that replaced ULID.provider or subclassed ValueProvider must migrate to a custom ULIDGenerator assigned to ulid.default_generator.
  • The internal validate_type decorator was removed. The ULID.from_* constructors still raise TypeError for arguments of the wrong type, so runtime behaviour is unchanged.

Added

  • A public ULIDGenerator class that encapsulates ULID generation and can be configured with a custom clock, randomness source, and monotonicity policy.
  • Pluggable monotonicity policies — StrictMonotonicPolicy (the default), LaxMonotonicPolicy, and PureRandomPolicy — together with the MonotonicityPolicy protocol and the BaseMonotonicPolicy base class for implementing custom policies.
  • A module-level ulid.default_generator that can be reassigned to route ULID() and the ULID.from_* constructors through a custom ULIDGenerator.

Migration

import ulid
from ulid import ULIDGenerator, LaxMonotonicPolicy

# Before (removed):
#     ULID.provider = MyValueProvider()
# After:
ulid.default_generator = ULIDGenerator(policy=LaxMonotonicPolicy())

alternatively you can just create a generator object with the custom policy and create your ULID values with it

from ulid import ULIDGenerator, LaxMonotonicPolicy


generator = ULIDGenerator(policy=LaxMonotonicPolicy())
generator.generate()

Full changelog: 3.2.1...4.0.0