Random prefixed ids
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zuid-0.1.1.tar.gz.
File metadata
- Download URL: zuid-0.1.1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.6.8 Linux/4.15.0-69-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
150f72b2e2a882f4ee1aeef921856dec506dd87eebea9afb31d6b87295f0f694
|
|
| MD5 |
c66f76935944be5133a438d66552dec5
|
|
| BLAKE2b-256 |
60f9b6e0592719110599925b3416188e0ee40da688005877aaeb3db8f9193d9c
|
File details
Details for the file zuid-0.1.1-py3-none-any.whl.
File metadata
- Download URL: zuid-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.6.8 Linux/4.15.0-69-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d8c86d73806fa8927a31843073dbec0c09f8f25822f5f4480ea492c80f463b0
|
|
| MD5 |
c992ab63e7588616a48a4ac6a5a0cc0c
|
|
| BLAKE2b-256 |
4210888b45bdd7438dbb1fae59a55c30eed7042a6f811071fc8535256c16c454
|