Skip to main content

Vahid Unique ID Generator

Project description

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 = "1A2b3C4d5"
vuid = VUID.from_code(existing_code)

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

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 = "")

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

VUID.from_code(code: str)

  • Parameters:
    • code: An existing VUID code.
  • Returns: A VUID object.

Properties

  • code: Returns the VUID as a string.
  • 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.

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

vuid-0.1.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

vuid-0.1.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file vuid-0.1.2.tar.gz.

File metadata

  • Download URL: vuid-0.1.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for vuid-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9bcf8218eb94770799c1d39422b70f7c33aa9e05aa753e1abd59ac8c06020487
MD5 c3a8817771e40412073824716869ec39
BLAKE2b-256 858a672a604fd2a7266009f263c049fd5183e85ce307f1ad4110a225f3e324f8

See more details on using hashes here.

File details

Details for the file vuid-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: vuid-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for vuid-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2f89bbb70ba3e9b284721a10a2d0f74b5271886b1699f3c8bfbd4c36daa15ea3
MD5 92bf53b0f052d09f2b324a9074e5a375
BLAKE2b-256 88080420c4c3dc26a6e23e2e9dbf883a1b479c9325bdb84eb513613e17b08d63

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