Package: uuid05
UUID05- compact human-readable almost unique identifiers for temporary objects
in small non-synchronizing distributed systems. Inspired by nanoid and mktemp utility.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 (well, you need python3 and pip) and provides you withUUID05class
based onintwith two additional methods:make()- sort of constructor.as_b64() -> str- alternative compact representation.Examplesbelow explain how it works:TTL(seconds)WorkersWorker IDExample valueMax value.as_b64(max_value)(hour) 3600219589132400AgUw36004229589332400BRJw360010449589932400Djow3600161195893153564006lHw36003211119589331356400Ad518A36002565353958939725535996400BfIQYfA(2 days) 17280021144958911555200sFGA172800422144958931555200AeF-gA1728001044144958991555200BXUFgA1728001644144958931517107200Wm04AA172800321414144958933117107200uctIAA17280025617917914495893972551727827200AlIe1KkAInstallingpip3installuuid05Usingfromuuid05importUUID05# basic usageuid=UUID05.make()suffix:str=uid.as_b64()object_name:str=f'autotest_object_{suffix}'# .make() may be parametrized by workers: int, ttl: int, precision: int# defaults are: workers=10, ttl=2 days, precision=1uid:int=UUID05.make(workers=16,ttl=86400,precision=6)# 1419554951415uid.as_b64()# 'AUqEXzNy'# you may also want to just shorten your existing integer identifiers.suffix:str=UUID05(123123123123).as_b64()assertsuffix=='HKq1w7M'# How to get maximum UUID value/length with given params?max_value=UUID05.max_value(machines=16,ttl=86400,precision=6)# 1586399913600len(str(max_value))==13len(max_value.as_b64())==8# AXFczaaAlen(f'autotest_object_{max_value.as_b64()}')==23# autotest_object_AXFczaaAIt can be also used as an utility from command-line:$uuid0561503153$uuid05-w21503125$uuid05-t3600-w227091$uuid05-b-t3600-w2aZ8
$uuid05-b-w2FvN2
$uuid05-b
AxHktA
$uuid05-b-a'_-'-w64eB_5Yg
$uuid05--helpWhere UUID05 is usefulIn E2E/UI-testing. It's slow, and sometimes you need to check a data created by testsafterrun.Or, more generally, in staging environments where you aren't sure that yourtestingsystem
will delete data after runs, but thetestedsystem 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 youdon'twant to synchronize workers via network.
Otherwise Redis, Memcached or another database with a single INCRementing counter would do the trick.When UUID05 is uselessIf your system isn't distributed, local counter in memory or file will work better.If your objects are persistent, you'd better usepy-nanoid.If you need to generate multiple UIDs for multiple object reallyquick:generate one and reuse it, using a semantic or loop variable as a suffix;well, there's a simple collision preventing mechanism, allowingsmall"bursts" of loops;If you seek for performance, disable it (uuid05.disable_cache = True) to win ~32% time.passprecisionargument touuid05(). 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=3argument will use milliseconds.precision=6for microseconds.ifprecision=6is 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 the testing system before or after each run.BenchmarksFunctionCPU Frequency (GHz)Collision prevening mechanism enabledMean time, nsUUID05.make()3.8GHzTrue868UUID05.make()3.8GHzFalse1300uuid.uuid4()3.8GHzn/a1500UUID05.make()4.7GHzTrue779UUID05.make()4.7GHzFalse1070UUID05(1333).as_b64()3.8GHzn/a596str(uuid.UUID)3.8GHzn/a570DevelopmentTests are doctests and may be run bypytest.Benchmarks - use%timeitinipythonDocumentation - look at code, it's just two files.Build -python3 -m build --sdist --wheel.Releasetwine check dist/uuid05-<version>* && twine upload dist/uuid05-<version>*.Design -UUID05class doesn't try to copyuuidmodule methods, properties and behavior. Speed also isn't a goal.