Skip to main content

Python library that provides an implementation of the ULID Specification

Project description

py-ulid - A ULID Implementation in Python

ulid logo

The py-ulid library is a minimal and self-contained implementation of the ULID (Universally Unique Lexicographically Sortable Identifier) specification in Python. For more information, please refer to the official specification.

Installation

You can install the py-ulid library from PyPi

pip install py-ulid

The py-ulid library can be used in any version of python >= 3.5 and does not require any additional packages or modules.

How to use

THe py-ulid library can be integrated into any of your existing python programs to provide generate, encode and decode ULIDs.

An example of a simple use case is shown below

from ulid import ULID

def main():

  # Create an ULID object
  ulid = ULID()

  # Generate a ULID
  value = ulid.generate()

  print(value)

if __name__ == '__main__':
  main()

Running that sample program would yield an output as follows

$ python sample_ulid.py

01BX5ZZKBKACTAV9WEVGEMMVRZ

Properties of an ULID

The proposed ULID spechas the following properties that give it an advantage over UUIDs

  • 128-bit compatibility with UUID
  • 1.21e+24 unique ULIDs per millisecond
  • Lexicographically sortable!
  • Canonically encoded as a 26 character string, as opposed to the 36 character UUID
  • Uses Crockford's base32 for better efficiency and readability (5 bits per character)
  • Case insensitive
  • No special characters (URL safe)
  • Monotonic sort order (correctly detects and handles the same millisecond)

Prior Art

Partly inspired by:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-ulid-1.0.1.tar.gz (3.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page