Skip to main content

Generates sortable, date/time-containing, human friendly unique string IDs. The default length of generated IDs is 24 characters containing 118 bits total.

Features

  • Consists of only unambiguous lowercase letters and digits for human readability.

  • The first and last characters are letters chosen from among the most neat ones.

  • The generated IDs contain the date/time with a potential precision of 50ns encoded in the first 12 characters.

  • Extractable date/time.

  • The order of the strings is the same as the order of the date/time encoded in them.

  • The remaining characters contain highest possible secure random bits, generated from the following sources of entropy:

    • Current process ID

    • Hostname

    • Random bits of the highest possible secure source of randomness

    • Environment variable names and values

    • A counter that is randomly initialized when the module is imported and thead-safely incremented each time suid_gen is called

Installing

pip install suid

Every time the module is loaded it performs a time_ns precision test. If worse than 5 mks, a warning is logged. On the Windows platform it is recommended to install the win-precise-time package:

pip install win-precise-time

Usage

Generate a unique ID containing the current date/time:

>>> from suid import suid_gen
>>> suid_gen()
'by6wtze6jduq6ksj4tbsnjcx'

Generate a unique ID of the specified length:

>>> suid_gen(length=32)
'by6wtzvyyq380mc4fdyv9q1p1bbyr1vp'

Generate a unique ID containing a custom date/time:

>>> from datetime import datetime, timezone
>>> dt = datetime(year=2023, month=11, day=10, hour=14, minute=26, second=15, microsecond=1234, tzinfo=timezone.utc)
>>> suid_gen(at=dt)
'by640s7bh6vc9rk2s5ud6wvw'

Extract encoded date/time from ID:

>>> from suid import suid_to_datetime
>>> suid_to_datetime('by640s7bh6vc9rk2s5ud6wvw')
datetime.datetime(2023, 11, 10, 14, 26, 15, 1234, tzinfo=datetime.timezone.utc)

There is a helper function to get the current date/time, which can be more precise then the standard datetime.now(tz=timezone.utc):

>>> from suid import utcnow
>>> utcnow()
datetime.datetime(2023, 11, 26, 9, 0, 35, 886315, tzinfo=datetime.timezone.utc)

1.0.1 —

  • Fixed a bug with incorrect sort order.

1.0

  • Initial version.

Release files for suid 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for suid 1.0.1
File Size Uploaded
suid-1.0.1.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for suid 1.0.1
File Interpreter ABI Platform
suid-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / suid-1.0.1.tar.gz

Download URL suid-1.0.1.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5b47f03a89672e0103ebc818472dabef09364bb8897fe8e89de664958103e639
BLAKE2b-256 checksum
How to use checksums
36566270598105ad42f889e912c48d70c0be0a7a275341f609e342eb5404fa10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / suid-1.0.1-py3-none-any.whl

Download URL suid-1.0.1-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64624f801e7040578c6895767a2fc588a89a895647d299bc30cd1acc2008b522
BLAKE2b-256 checksum
How to use checksums
dd9928abb96934940810e705e57b322b27d56a6cdb66189f88023ff4d13bae29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page