ULID implementation for Python

Overview



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%.
Deep Difference and search of any Python object/data.

DeepDiff v 5.6.0 DeepDiff Overview DeepDiff: Deep Difference of dictionaries, iterables, strings and other objects. It will recursively look for all t

Sep Dehpour 1.6k Jan 08, 2023
Python program to do with percentages and chances, random generation.

Chances and Percentages Python program to do with percentages and chances, random generation. What is this? This small program will generate a list wi

n0 3 Jul 15, 2021
A pythonic dependency injection library.

Pinject Pinject is a dependency injection library for python. The primary goal of Pinject is to help you assemble objects into graphs in an easy, main

Google 1.3k Dec 30, 2022
python-codicefiscale: a tiny library for encode/decode Italian fiscal code - codifica/decodifica del Codice Fiscale.

python-codicefiscale python-codicefiscale is a tiny library for encode/decode Italian fiscal code - codifica/decodifica del Codice Fiscale. Features T

Fabio Caccamo 53 Dec 14, 2022
A hashtag from string extract python module

A hashtag from string extract python module

Fayas Noushad 3 Aug 10, 2022
Script to rename and resize folders of images

script to rename and resize folders of images

Tega Brain 2 Oct 29, 2021
Handy Tool to check the availability of onion site and to extract the title of submitted onion links.

This tool helps is to quickly investigate a huge set of onion sites based by checking its availability which helps to filter out the inactive sites and collect the site title that might helps us to c

Balaji 13 Nov 25, 2022
Michael Vinyard's utilities

Install vintools To download this package from pypi: pip install vintools Install the development package To download and install the developmen

Michael Vinyard 2 May 22, 2022
A simple tool to move and rename Nvidia Share recordings to a more sensible format.

A simple tool to move and rename Nvidia Share recordings to a more sensible format.

Jasper Rebane 8 Dec 23, 2022
Two fast AUC calculation implementations for python

fastauc Two fast AUC calculation implementations for python: python-based is approximately 5X faster than the default sklearn.metrics.roc_auc_score()

Vsevolod Kompantsev 26 Dec 11, 2022
DiddiParser 2: The DiddiScript parser.

DiddiParser 2 The DiddiScript parser, written in Python. Installation DiddiParser2 can be installed via pip: pip install diddiparser2 Usage DiddiPars

Diego Ramirez 3 Dec 28, 2022
Python USD rate in RUB parser

Python EUR and USD rate parser. Python USD and EUR rate in RUB parser. Parsing i

Andrew 2 Feb 17, 2022
A thing to simplify listening for PG notifications with asyncpg

asyncpg-listen This library simplifies usage of listen/notify with asyncpg: Handles loss of a connection Simplifies notifications processing from mult

ANNA 18 Dec 23, 2022
NetConfParser is a tool that helps you analyze the rpcs coming and going from a netconf client to a server

NetConfParser is a tool that helps you analyze the rpcs coming and going from a netconf client to a server

Aero 1 Mar 31, 2022
A collection of resources/tools and analyses for the angr binary analysis framework.

Awesome angr A collection of resources/tools and analyses for the angr binary analysis framework. This page does not only collect links and external r

105 Jan 02, 2023
Blender 2.93 addon for loading Quake II MD2 files

io_mesh_md2 is a Blender 2.93 addon for importing Quake II MD2 files.

Joshua Skelton 11 Aug 31, 2022
Color box that provides various colors‘ rgb decimal code.

colorbox Color box that provides various colors‘ rgb decimal code

1 Dec 07, 2021
Implicit hierarchical a posteriori error estimates in FEniCSx

FEniCSx Error Estimation (FEniCSx-EE) Description FEniCSx-EE is an open source library showing how various error estimation strategies can be implemen

Jack S. Hale 1 Dec 08, 2021
Pampy: The Pattern Matching for Python you always dreamed of.

Pampy: Pattern Matching for Python Pampy is pretty small (150 lines), reasonably fast, and often makes your code more readable and hence easier to rea

Claudio Santini 3.5k Jan 06, 2023
A simple Python app that generates semi-random chord progressions.

chords-generator A simple Python app that generates semi-random chord progressions.

53 Sep 07, 2022