Skip to main content

Compact human-readable almost unique identifiers for temporary objects in small non-synchronizing distributed systems.

Project description

UUID05 - compact human-readable almost unique identifiers for temporary objects in small non-synchronizing distributed systems.

Well, it's not really unique (that's why 0.5) and collisions are possible but probability is low and it's probably acceptable.

The library have zero dependencies and provides you with a class: UUID05 based on int with two additional methods:

  • make() - sort of constructor.
  • as_b64() -> str - alternative representation.

Examples below explain how it works:

TTL
(seconds)
Workers Worker ID Example value Max value int2b64(max_value)
(hour) 3600 2 1 9589 132400 AgUw
3600 4 2 29589 332400 BRJw
3600 10 4 49589 932400 Djow
3600 16 1 195893 15356400 6lHw
3600 32 11 1195893 31356400 Ad518A
3600 256 53 539589397 25535996400 BfIQYfA
(2 days) 172800 2 1 1449589 11555200 sFGA
172800 4 2 21449589 31555200 AeF-gA
172800 10 4 41449589 91555200 BXUFgA
172800 16 4 414495893 1517107200 Wm04AA
172800 32 14 1414495893 3117107200 uctIAA
172800 256 179 1791449589397 2551727827200 AlIe1KkA

Installing

pip install uuid05

Using

from uuid05 import UUID05

# May be parametrized by workers: int, ttl: int, precision: int
# defaults are: workers=10, ttl=2 days, precision=1
uid = UUID05.make()
suffix: str = uid.as_b64()
object_name: str = f'autotest_object_{suffix}'

It can be also used as an utility from command-line:

$ uuid05
61503153
$ uuid05 -w 2
1503125
$ uuid05 -t 3600 -w 2
27091
$ uuid05 -b -t 3600 -w 2
aZ8
$ uuid05 -b -w 2
FvN2
$ uuid05 -b
AxHktA
$ uuid05 -b -a '_-' -w 64
eB_5Yg
$ uuid05 --help

Where UUID05 is useful

In E2E/UI-testing. It's slow, and sometimes you need to check a data created by tests after run.

Or, more generally, in staging environments where you aren't sure that your testing system will delete data after runs, but tested system is aware of such a data and deletes it after some time. There's also be multiple testing systems instances running simultaneously, and you don't want them to affect each other.

You also may want identifiers to be more or less rememberable for at least 10-15 seconds while you switching tabs.

Oh, and you don't want to synchronize workers via network. Otherwise Redis, Memcached or another database with a single INCRementing counter would do the trick.

When UUID05 is useless

  • If your system isn't distributed. Local counter in memory or file will work better.
  • If your objects are persistent - you'd better use py-nanoid.
  • If you need to generate multiple UIDs for multiple object really quick:
    • generate one and reuse it, using a semantic or loop variable as a suffix;
    • pass precision argument to uuid05(). It scales automatically with worker count, but if there are less than 16 workers, default is 1 which means 1 uuid per 0.1 second, usually it's enough.
      • precision=3 argument will use milliseconds.
      • precision=6 for microseconds.
    • if precision=6 is not enough stop trying to make your identifier compact.
  • If you believe that semi-persistent data is a testing antipattern, and it should be cleared by testing system before or after each run.

Development

  • Tests are doctests and may be run by pytest.
  • Documentation - look at code, it's just two files.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uuid05-0.0.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

uuid05-0.0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file uuid05-0.0.2.tar.gz.

File metadata

  • Download URL: uuid05-0.0.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for uuid05-0.0.2.tar.gz
Algorithm Hash digest
SHA256 00620516eca4df952d198ddd5e8800588dd55b025a0c2d5bd83a1a7fadcd9535
MD5 2fb2916f3f10659dc5d28272897d8e3b
BLAKE2b-256 9e38e5bd92d219332935af0e5b5218b57300d8ba9e68cf740ef42448841e0093

See more details on using hashes here.

File details

Details for the file uuid05-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: uuid05-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for uuid05-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 71097638f4f26c224acda8b68003cd47cce00c7daa72391726b52713cff7be7f
MD5 a9148f00705ad4410e49323e35990156
BLAKE2b-256 5eb4a8342b91fbcb733247d3cbbe5157884bcab53df814e860ec24269a974e2c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page