ulid/ulid

Object representation of a ULID.

class ulid.ulid.Timestamp(buffer: Union[bytes, bytearray, memoryview])

Represents the timestamp portion of a ULID.

  • Unix time (time since epoch) in milliseconds.

  • First 48 bits of ULID when in binary format.

  • First 10 characters of ULID when in string format.

property str

Computes the string value of the timestamp from the underlying memoryview in Base32 encoding.

Returns

Timestamp in Base32 string form.

Return type

str

Raises

ValueError – if underlying memoryview cannot be encoded

property timestamp

Computes the Unix time (seconds since epoch) from its memoryview.

Returns

Timestamp in Unix time (seconds since epoch) form.

Return type

float

property datetime

Creates a datetime instance (assumes UTC) from the Unix time value of the timestamp with millisecond precision.

Returns

Timestamp in datetime form.

Return type

datetime

property bin

Computes the binary string value of the underlying memoryview.

Returns

Memory in binary string form

Return type

str

property bytes

Computes the bytes value of the underlying memoryview.

Returns

Memory in bytes form

Return type

bytes

property float

Computes the float value of the underlying memoryview in big-endian byte order.

Returns

Bytes in float form.

Return type

float

property hex

Computes the hexadecimal string value of the underlying memoryview.

Returns

Memory in hexadecimal string form

Return type

str

property int

Computes the integer value of the underlying memoryview in big-endian byte order.

Returns

Bytes in integer form.

Return type

int

property oct

Computes the octal string value of the underlying memoryview.

Returns

Memory in octal string form

Return type

str

class ulid.ulid.Randomness(buffer: Union[bytes, bytearray, memoryview])

Represents the randomness portion of a ULID.

  • Cryptographically secure random values.

  • Last 80 bits of ULID when in binary format.

  • Last 16 characters of ULID when in string format.

property str

Computes the string value of the randomness from the underlying memoryview in Base32 encoding.

Returns

Timestamp in Base32 string form.

Return type

str

Raises

ValueError – if underlying memoryview cannot be encoded

property bin

Computes the binary string value of the underlying memoryview.

Returns

Memory in binary string form

Return type

str

property bytes

Computes the bytes value of the underlying memoryview.

Returns

Memory in bytes form

Return type

bytes

property float

Computes the float value of the underlying memoryview in big-endian byte order.

Returns

Bytes in float form.

Return type

float

property hex

Computes the hexadecimal string value of the underlying memoryview.

Returns

Memory in hexadecimal string form

Return type

str

property int

Computes the integer value of the underlying memoryview in big-endian byte order.

Returns

Bytes in integer form.

Return type

int

property oct

Computes the octal string value of the underlying memoryview.

Returns

Memory in octal string form

Return type

str

class ulid.ulid.ULID(buffer: Union[bytes, bytearray, memoryview])

Represents a ULID.

  • 128 bits in binary format.

  • 26 characters in string format.

  • 16 octets.

  • Network byte order, big-endian, most significant bit first.

property str

Computes the string value of the ULID from its memoryview in Base32 encoding.

Returns

ULID in Base32 string form.

Return type

str

Raises

ValueError – if underlying memoryview cannot be encoded

timestamp()ulid.ulid.Timestamp

Creates a Timestamp instance that maps to the first 48 bits of this ULID.

Returns

Timestamp from first 48 bits.

Return type

Timestamp

randomness()ulid.ulid.Randomness

Creates a Randomness instance that maps to the last 80 bits of this ULID.

Returns

Timestamp from first 48 bits.

Return type

Timestamp

property uuid

Creates a UUID instance of the ULID from its bytes representation.

Returns

UUIDv4 from the ULID bytes

Return type

UUID

property bin

Computes the binary string value of the underlying memoryview.

Returns

Memory in binary string form

Return type

str

property bytes

Computes the bytes value of the underlying memoryview.

Returns

Memory in bytes form

Return type

bytes

property float

Computes the float value of the underlying memoryview in big-endian byte order.

Returns

Bytes in float form.

Return type

float

property hex

Computes the hexadecimal string value of the underlying memoryview.

Returns

Memory in hexadecimal string form

Return type

str

property int

Computes the integer value of the underlying memoryview in big-endian byte order.

Returns

Bytes in integer form.

Return type

int

property oct

Computes the octal string value of the underlying memoryview.

Returns

Memory in octal string form

Return type

str