Skip to main content

VUID Package

Release Build status Commit activity License

The VUID is a Python package designed to generate vahid unique identifiers (VUIDs) based on a custom epoch time and a base-62 encoding scheme. The package provides a simple and efficient way to create unique IDs that can be used in various applications, such as database keys, distributed systems, or any scenario where uniqueness is critical.

Features

  • Custom Epoch Time: The package uses a custom epoch time (START_EPOC_TIME) to ensure uniqueness and avoid collisions with other timestamp-based ID systems.
  • Base-62 Encoding: Utilizes a base-62 encoding scheme (0-9, A-Z, a-z) to generate compact and human-readable IDs.
  • High Performance: Capable of generating over 800,000 unique IDs per second, making it suitable for high-throughput systems.
  • Timestamp Extraction: Allows extraction of the creation timestamp from a generated VUID.
  • Randomness: Adds a 4-character random suffix to each ID to further ensure uniqueness.

Installation

To install the package, use pip:

pip install vuid

Usage

Generating a VUID

To generate a unique VUID, simply create an instance of the VUID class with a timestamp:

from datetime import datetime
from vuid import VUID

# Generate a VUID using the current time
timestamp = datetime.now().timestamp()
vuid = VUID(timestamp)

print(vuid)  # Example output: "1A2b3C4d5"

Extracting the Creation Time

You can extract the creation time of a VUID using the created_time property:

creation_time = vuid.created_time
print(creation_time)  # Example output: "2025-01-04 12:04:08"

Creating a VUID from an Existing Code

If you already have a VUID code, you can create a VUID object from it:

existing_code = "CS21A2b3C4d5"
vuid = VUID.from_code(existing_code)

print(vuid.created_time)  # Output: "2025-07-22 05:24:09"
print(vuid.extra)  # Output: 1738
print(vuid.prefix)  # Output: "C"

Comparing VUIDs

The VUID class supports comparison operations, allowing you to compare two VUIDs:

vuid1 = VUID(datetime.now().timestamp())
vuid2 = VUID(datetime.now().timestamp())

print(vuid1 == vuid2)  # False
print(vuid1 < vuid2)  # True or False, depending on the timestamps

API Reference

VUID(timestamp: int, *, prefix: str = "", extra: int = None)

  • Parameters:
    • timestamp: A timestamp (in seconds) used to generate the VUID.
    • prefix: A string used to add as prefix in the VUID.
    • extra: An integer to save extra info in the VUID.
  • Returns: A VUID object.

VUID.from_code(code: str, *, extra_index: int | None = None)

  • Parameters:
    • code: An existing VUID code.
    • extra_index: if you have put extra you must the start index of the extra.
  • Returns: A VUID object.

Properties

  • code: Returns the code as a string.
  • extra: Returns the extra as an integer.
  • created_time: Returns the creation time of the VUID as a datetime object.

Methods

  • __str__(): Returns the VUID as a string.
  • __repr__(): Returns a formal representation of the VUID.
  • __eq__(other): Compares two VUIDs for equality.
  • __hash__(): Returns the hash of the VUID.
  • __lt__(other), __le__(other), __gt__(other), __ge__(other), __ne__(other): Comparison methods for VUIDs.

Performance

  • The package is optimized for high performance, capable of generating over 800,000 unique IDs per second.
  • Tested to generate 11,592,876 unique codes in 14.04 seconds.

Limitations

  • The current implementation supports IDs with a maximum length of 9 characters. If the timestamp exceeds the 5-character limit (after base-62 encoding), a warning will be logged.
  • The package is designed to work until January 15, 2054, after which the timestamp encoding will overflow.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the BEER-WARE License. See the LICENSE file for details.

Metadata

Release files for vuid 0.1.6

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

Source distribution (sdist)

Source distribution for vuid 0.1.6
File Size Uploaded Provenance Actions
vuid-0.1.6.tar.gz 6.0 kB Without provenance Details for vuid-0.1.6.tar.gz

Built distribution (wheel)

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

Total release size: 11.7 kB

Release files / vuid-0.1.6.tar.gz

Download URL vuid-0.1.6.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d0956ed3691c70bde170cf8d5d22782a658f951b66b9b7b0fd69e12666b8fa52
BLAKE2b-256 checksum
How to use checksums
c9bd36a96183aeb06b5fed940fff8232f2504e665289feee7995749e91304a92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.18

Release files / vuid-0.1.6-py3-none-any.whl

Download URL vuid-0.1.6-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2281d97b9368cd1d349f728ef8d026a0e1bf48d8b09463a421ca061a1107e13
BLAKE2b-256 checksum
How to use checksums
fad0ee52c3e80923ad1f157c7ee93024bfdfb8059b129ba248c7caa57f54e69a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.18

Security for vuid 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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