Skip to main content

UUIDv7 generation for Python <3.11

Project description

uuid7gen

A lightweight and pure-Python implementation of UUIDv7 for Python versions < 3.11. Fully compatible with RFC 9562, including submillisecond precision.

Installation

pip install uuid7gen

Usage

Generate a single UUIDv7 (with optional submillisecond precision)

from uuid7gen import uuid7

id = uuid7()
print(id)

# Example output (ms precision):
# 018e6e7c-7b7c-7f7c-bf7c-7c7c7c7c7c7c

# Generate with submillisecond precision
timestamp_ms = 1620000000123.456  # float, ms since epoch
id_subms = uuid7(timestamp_ms=timestamp_ms)
print(id_subms)

# Example output (subms precision):
# 018e6e7c-7b7c-7f7c-bf7c-7c7c7c7c7c7d

Generate a batch of UUIDv7s (supports subms intervals)

from uuid7gen import batch_uuid7

ids = batch_uuid7(5, timestamp_start_ms=1620000000123.0, interval_ms=0.1)
for i, id in enumerate(ids):
    print(f"{i+1}: {id}")

# Example output:
# 1: 018e6e7c-7b7c-7f7c-bf7c-7c7c7c7c7c7c
# 2: 018e6e7c-7b7c-7f7c-bf7c-7c7c7c7c7c7d
# 3: 018e6e7c-7b7c-7f7c-bf7c-7c7c7c7c7c7e
# 4: 018e6e7c-7b7c-7f7c-bf7c-7c7c7c7c7c7f
# 5: 018e6e7c-7b7c-7f7c-bf7c-7c7c7c7c7c80

Visual representations of a UUIDv7

id = uuid7()
print("standard string:", id)
print("bytes:", id.bytes)
print("hex:", id.hex)
print("int:", id.int)
print("urn:", id.urn)

# Example output:
# standard string: 018e6e7c-7b7c-7f7c-bf7c-7c7c7c7c7c7c
# bytes: b'\x01\x8en|{|\x7f|\xbf|||||||'
# hex: 018e6e7c7b7c7f7cbf7c7c7c7c7c7c7c7c
# int: 212345678901234567890123456789012345
# urn: urn:uuid:018e6e7c-7b7c-7f7c-bf7c-7c7c7c7c7c7c

Features:

  • RFC 9562 compliant (including submillisecond encoding)
  • Python <3.11 compatible
  • Batch generation with subms intervals

For more details, see the documentation.

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

uuid7gen-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

uuid7gen-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file uuid7gen-0.1.0.tar.gz.

File metadata

  • Download URL: uuid7gen-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.3

File hashes

Hashes for uuid7gen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9ead289983f2c2181214c3530534acc13a0630884976885fd5db090883a738bb
MD5 eaad3062c6c2da07904848bf2cbca6ca
BLAKE2b-256 857365e3c024b0c278d9af90e4a14abd02bd7d1b95e27e7629231940aef67ebd

See more details on using hashes here.

File details

Details for the file uuid7gen-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: uuid7gen-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.3

File hashes

Hashes for uuid7gen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a17013fc65c08eb413b38d7aec44fb0f8ffb27d3281f46d4bd0933c0fdd03ce
MD5 01a37930a1a8d5e501fde7ce2cb73d93
BLAKE2b-256 9f153a0f75ab589f536fa62a5cf6567814360bf27cf2a5006edcf525ee8dd264

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