An adjective-noun-number identifier generator.
Project description
Generate "unique" identifiers of the form adjective-noun-number.
Usage
pip install uidgen
Then in python:
>>> import uidgen
>>> uidgen.generate()
spotless-leave-6
>>> uidgen.generate()
wet-diamond-0
>>> uidgen.generate()
dull-court-2
Or via CLI:
$ python -m uidgen
wild-sport-8
How "unique" are these IDs?
The total number of possible identifiers is:
>>> from uidgen.data import adjectives, nouns
>>> len(adjectives) * len(nouns) * 10
19996990
That's roughly 20 million. The uidgen.generate() function samples an ID uniformly from these possibilities. So, if you call uidgen.generate() a total of N times, the probability that all N ID are unique is:
>>> import math
>>> total = len(adjectives) * len(nouns) * 10
>>> for N in [10, 100, 1000, 10000, 100000]:
>>> print(N, math.prod(total-i for i in range(N)) / total**N)
10 0.9999977496634996
100 0.9997524929700011
1000 0.9753302225997922
10000 0.08204043013318953
100000 1.696918121141932e-109
The takeaway: If you're generating under 200 IDs, its very unlikely you'll see a collision. Beyond 200 IDs, you're really risking a collision.
So what's the use of this package? Other ID specifications such as uuid4 have much stronger probabilistic guarantees. However, imagine naming a training run of a deep learning model d986a320-46e1-477e-8b0c-0f53352a8025. It doesn't exactly roll off the tongue when you're in a meeting discussing the takeways of the technique used in run d986a320-46e1-477e-8b0c-0f53352a8025 vs run f1b4666f-ab0d-409c-a54f-271ac4e33578. You really want something that's easy to say, is memorable, and is unique, which uidgen provides. This is the same technique that wandb.ai uses to name training runs by default.
You should NOT use this library if:
- You're application cannot handle name collisions (i.e. the application doesn't detect collisions to regenerate an ID).
- You need to generate a lot of IDs (more than 10000), in which case, even if you regenerate on a collision, you'll be waiting a while until you get a unique ID.
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 uidgen-1.0.2.tar.gz.
File metadata
- Download URL: uidgen-1.0.2.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8ffd65aa4ca9189b7fe1bb12bc34abd230ba398f9ee337b1a7ed63582fc6d0a
|
|
| MD5 |
90c56fcb0408c84bebf3885141d12f93
|
|
| BLAKE2b-256 |
b6904cbaff7ed1c883997f8e4d5f91691b5aa57586c23983aea430d728661b03
|
File details
Details for the file uidgen-1.0.2-py3-none-any.whl.
File metadata
- Download URL: uidgen-1.0.2-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc7c311ff3ba36c8f413147120f0bff49b4eac1b186a06e9e6ed99f342bb3ae5
|
|
| MD5 |
5ecdb7bce85a5d09a7dae9151dac77ba
|
|
| BLAKE2b-256 |
3e262017cc2619465851ae3c6d9b323795ff72852b55a1b89b9a41e522780652
|