Skip to main content

Unique id from random chars and optional date-time.

Project description

uqid:

pip install uqid
from uqid import uqid, digits

print(uqid()) # e7ljCIs4grYZ9tOv6bpX3TQIA7FyA23umzGjDcIjHff2XwF2ziAw56B7S3EdOuCA
print(uqid(4, digits)) # 4982
  • Returns unique id from random chars.

  • Default is 64 chars 0-9a-zA-Z aka base62.

dtid:

pip install uqid
from uqid import dtid
print(dtid())

YYYYMMDDhhmmssmicrosrnd4
20161231235959123456uN1q
  • 24 bytes by default - as str(ObjectId()).

  • But human-friendly - unlike ObjectId.

  • Microsecond-precise UTC timestamp - unlike second-precise ObjectId().

  • May extract datetime_from_dtid().

  • May be used as a log timestamp as is.

  • Alphabetically ordered.

  • Safe chars 0-9a-zA-Z - unlike binary ObjectId() leading to “ValueError: Invalid UTF-8 sequence length” if added to JSON without str().

  • base62^4 is over 14M uniques per microsecond.

  • dtid(24) is 2x faster than uqid(24) but slower than str(ObjectId())

tests:

python2 uqid.py
python3 uqid.py

SAMPLES:
str(uuid4()): 3bb25137-2422-4d06-bd12-5a9de2ea2bf6
len(^): 36
len(v): 24
str(ObjectId()): 5acdcd1f9c591516ae800615
uqid(24): UFRFQVCtYu6rtQq8LD33XjI3
dtid(24): 20180411085351268116tHse
Iterations: 1000000

python2 SECONDS:
str(uuid4()) seconds: 11.825964
str(ObjectId()) seconds: 2.424702
uqid(24) seconds: 9.701306
dtid(24) seconds: 5.357983

python3 SECONDS:
str(uuid4()) seconds: 5.826098
str(ObjectId()) seconds: 3.192565
uqid(24) seconds: 17.769653
dtid(24) seconds: 9.588677

DUPLICATES:
str(uuid4()) duplicates: 0
str(ObjectId()) duplicates: 0
uqid(24) duplicates: 0
dtid(24) duplicates: 0

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

uqid-0.3.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

uqid-0.3.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

uqid-0.3.0-py2-none-any.whl (4.7 kB view details)

Uploaded Python 2

File details

Details for the file uqid-0.3.0.tar.gz.

File metadata

  • Download URL: uqid-0.3.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for uqid-0.3.0.tar.gz
Algorithm Hash digest
SHA256 edee2fc48c5feed999d95bc88755a57b9e94dd8405d23bc4a4afb87c58b18d78
MD5 80208188bc460e2a4fa4cce8c6c7df4f
BLAKE2b-256 31b18692e13be884be7d6dd9ea6478421ae53a8d9c43d696d3fa0df81f0c7346

See more details on using hashes here.

File details

Details for the file uqid-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: uqid-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for uqid-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc3adebc79462e4cea107b7e93ba00c59702ff25c587ecdf97dd26906578038c
MD5 59d3200bccd598a888fcde899c8eb3c5
BLAKE2b-256 5be5eb5c81e2266280593d8969ca1fa60b33b6f41ce638329bd8de4061857276

See more details on using hashes here.

File details

Details for the file uqid-0.3.0-py2-none-any.whl.

File metadata

  • Download URL: uqid-0.3.0-py2-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for uqid-0.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 61cfa4ed07b6166ae81b76937cdc302c4ee396f2bc80f98d50604392b9ce0f5c
MD5 e00850687e71c223bf148d48d2ebe037
BLAKE2b-256 ecfb0500e1c4a7266d52585646cc51ed9fbdd96d9f646e34f7ae42bfb0b91be5

See more details on using hashes here.

Supported by

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