Skip to main content



ulid


What is this?

This is a port of the original JavaScript ULID implementation to Python.

A ULID is a universally unique lexicographically sortable identifier. It is

  • 128-bit compatible 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)

In general the structure of a ULID is as follows:

   01AN4Z07BY      79KA1307SR9X4MV3
  |----------|    |----------------|
   Timestamp          Randomness
     48bits             80bits

For more information have a look at the original specification.

Installation

  $ pip install python-ulid

Basic Usage

Create a new ULID on from the current timestamp

  >>> from ulid import ULID
  >>> ulid = ULID()

Encode in different formats

  >>> str(ulid)
  '01BTGNYV6HRNK8K8VKZASZCFPE'
  >>> ulid.hex
  '015ea15f6cd1c56689a373fab3f63ece'
  >>> int(ulid)
  1820576928786795198723644692628913870
  >>> ulid.bytes
  b'\x01^\xa1_l\xd1\xc5f\x89\xa3s\xfa\xb3\xf6>\xce'

Access timestamp attribute

  >>> ulid.timestamp
  1505945939.153
  >>> ulid.milliseconds
  1505945939153
  >>> ulid.datetime
  datetime.datetime(2017, 9, 20, 22, 18, 59, 153000, tzinfo=datetime.timezone.utc)

Convert to UUID

  >>> ulid.to_uuid()
  UUID('015ea15f-6cd1-c566-89a3-73fab3f63ece')

Other implementations

Changelog

Version 1.0.0

  • Dropped support for Python 2. Only Python 3.6+ is supported.
  • Added type annotations
  • Added the named constructors ULID.from_datetime, ULID.from_timestamp and from_hex.
  • The named constructor ULID.new has been removed. Use one of the specifc named constructors instead. For a new ULID created from the current timestamp use the standard constructor.
  # old
  ulid = ULID.new()
  ulid = ULID.new(time.time())
  ulid = ULID.new(datetime.now())

  # new
  ulid = ULID()
  ulid = ULID.from_timestamp(time.time())
  ulid = ULID.from_datetime(datetime.now())
  • The ULID.str and ULID.int methods have been removed in favour of the more Pythonic special dunder-methods. Use str(ulid) and int(ulid) instead.
  • Added the property ULID.hex that returns a hex representation of the ULID.
  >>> ULID().hex
  '0171caa5459a8631a6894d072c8550a8'
  • Equality checks and ordering now also work with str-instances.
  • The package now has no external dependencies.
  • The test-coverage has been raised to 100%.

Release files for python-ulid 1.0.2

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

Source distribution (sdist)

Source distribution for python-ulid 1.0.2
File Size Uploaded
python-ulid-1.0.2.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-ulid 1.0.2
File Interpreter ABI Platform
python_ulid-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / python-ulid-1.0.2.tar.gz

Download URL python-ulid-1.0.2.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f3772388eeb9a90b0004c706ac965d92210fb0b59ce413dae17e1f1a93bdcf14
BLAKE2b-256 checksum
How to use checksums
6c7a87d9e9016c78fcec2caef78ed7823de166e888c05b1df6f88b7df591e8f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.0

Release files / python_ulid-1.0.2-py3-none-any.whl

Download URL python_ulid-1.0.2-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7ec6449227d7f700b5636254fb05fbf35d5c1a456acda00c712cefb9258e65c
BLAKE2b-256 checksum
How to use checksums
aa4af0d8c5b53bb3afad54279cde738564c1fe79a80e7dd01e33ace179b4aaae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.0

Release history Release notifications | RSS feed

4.0.1

2 release files

4.0.0

2 release files

3.2.1

2 release files

3.2.0

1 release file

3.1.0

2 release files

3.0.0

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

1.1.0

2 release files

1.0.3

2 release files

This release

1.0.2 This release

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.0.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