Skip to main content

zuid

Generates URL-safe random ids with a prefix and optional timestamp.

Installing

pip install zuid

Usage

The ZUID class works as a callable id factory for a given prefix:

>>> from zuid import ZUID
>>> generator = ZUID(prefix='user_')
>>> generator()
'user_03QewpfEIpPWUICXdgtvdR'
>>> generator()
'user_1LJSXMoyH6p7VsiL8wwIm1'

The factory generates ids that are 22 chars long by default, which in base 62 corresponds to 131 random bits. For comparison, a v4 UUID has 122 random bits. It can be changed with the length parameter:

>>> generator = ZUID(prefix='user_', length=27)
>>> generator()
'user_X5fSIStIKpYWcg07nqEfPbMvmME'

With the timestamped parameter, the factory uses the current nanoseconds since epoch as the first 8 bytes, preserving the order when sorting by id.

>>> generator = ZUID(prefix='user_', timestamped=True)
>>> generator()
'user_1qzuvBwgHdQVO2gA4GelYX'
>>> generator()
'user_1qzuvCscVyClzGaqakgvsl'
>>> generator()
'user_1qzuvDb0TuCuIJJON103Of'
>>> generator()
'user_1qzuvES4mTQ7fWykywvjNb

Metadata

Release files for zuid 0.1.1

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

Source distribution (sdist)

Source distribution for zuid 0.1.1
File Size Uploaded
zuid-0.1.1.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zuid 0.1.1
File Interpreter ABI Platform
zuid-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / zuid-0.1.1.tar.gz

Download URL zuid-0.1.1.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
150f72b2e2a882f4ee1aeef921856dec506dd87eebea9afb31d6b87295f0f694
BLAKE2b-256 checksum
How to use checksums
60f9b6e0592719110599925b3416188e0ee40da688005877aaeb3db8f9193d9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.17 CPython/3.6.8 Linux/4.15.0-69-generic

Release files / zuid-0.1.1-py3-none-any.whl

Download URL zuid-0.1.1-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d8c86d73806fa8927a31843073dbec0c09f8f25822f5f4480ea492c80f463b0
BLAKE2b-256 checksum
How to use checksums
4210888b45bdd7438dbb1fae59a55c30eed7042a6f811071fc8535256c16c454
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.17 CPython/3.6.8 Linux/4.15.0-69-generic

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

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