Skip to main content

Unique id from random chars and optional date-time.

Project description


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.


pip install uqid
from uqid import dtid

  • 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 2x slower than str(ObjectId()).



Length: 24
uqid(24): SdGksfuUJAmDGz7suDzgJYr4
dtid(24): 20160923092803852711Pqci
str(ObjectId()): 57e4f5a39c5915591b593563
Iterations: 1000000
uqid(24) seconds: 11.457604
dtid(24) seconds: 5.997643
str(ObjectId()) seconds: 2.715093
uqid(24) duplicates: 0
dtid(24) duplicates: 0
str(ObjectId()) 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.2.0.tar.gz (2.2 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page