Skip to main content

Minimal 14-character URL-safe unique ID generator based on millisecond timestamp and cryptographically secure random bits.

Project description

LazyId

npm version PyPI version Packagist version License

Minimal 14-character URL-safe unique ID generator based on millisecond timestamp and cryptographically secure random bits.

Overview

LazyId is a lightweight, cross-platform library for generating and parsing 14-character, URL-safe unique identifiers. Each ID encodes a 42-bit timestamp (milliseconds since Unix epoch, UTC) and a 42-bit cryptographically secure random value, using a custom Base64 alphabet (ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_).

No external dependencies. Consistent output across JavaScript, Python, and PHP.

Features

  • Compact: Generates 14-character IDs using a URL-safe Base64 alphabet.
  • Timestamp-Based: Embeds a 42-bit timestamp (milliseconds since 1970-01-01 UTC).
  • Cryptographic Random: 42 bits of secure random data.
  • Cross-Platform: Identical output in JavaScript, Python, and PHP.
  • Reversible: Extract the original timestamp from any ID.
  • No Dependencies: Uses only standard libraries.
  • Practically Collision-Free: Safe for massive scale.

Installation

JavaScript (Node.js or Browser)

Install via npm:

npm install lazyid

Python

Install via PyPI:

pip install lazyid

PHP

Install via Composer:

composer require niefdev/lazyid

Usage

JavaScript

const lazyid = require("lazyid");

let id = lazyid();
let data = lazyid(id);

// e.g.

// {
//  timestamp: '2025-07-17 23:06:41.645',
//  random_bit: '001010110011110011010000100101101100010111'
// }

Python

from lazyid import lazyid

id = lazyid()
data = lazyid('ZgZJT4smNKOm1p')

# e.g.

# {'timestamp': '2025-07-17 23:08:47.916', 'random_bit': '100110001101001010001110100110110101101001'}

PHP

<?php
require 'vendor/autoload.php';

use function LazyID\lazyid;

$id = lazyid();
$data = lazyid($id);

// e.g.

// array(2) {
//  ["timestamp"]=>
//  string(23) "2025-07-17 16:10:28.542"
//  ["random_bit"]=>
//  string(42) "110011101110110100111100101100110000000100"
// }

API Reference

lazyid([id: string])

  • Generate: Call with no arguments to create a new LazyId string.
  • Parse: Call with an ID string to extract { timestamp, random_bit }.

Returns:

  • JavaScript: string (generate) or { timestamp: string, random_bit: string } (parse)
  • Python: str (generate) or { 'timestamp': str, 'random_bit': str } (parse)
  • PHP: string (generate) or [ 'timestamp' => string, 'random_bit' => string ] (parse)

Throws: Error if the input string is invalid.

Structure of LazyId

  • Total Bits: 84 bits
  • Timestamp: 42 bits (milliseconds since 1970-01-01 UTC), reversible without loss.
  • Random Data: 42 bits (cryptographically secure)
  • Encoding: Custom Base64 (A-Z, a-z, 0-9, -, _)
  • Length: 14 characters (84 bits encoded)

Notes

  • Timezone: All timestamps are UTC+0. Use toISOString() in JS, datetime.utcfromtimestamp() in Python, and ISO8601 in PHP.
  • Random Quality: Uses cryptographic random generation (crypto.randomBytes, os.urandom, random_bytes) with no fallback.
  • Interoperability: IDs generated in one language can be parsed in another.

Collision Resistance

Combines 42-bit time + 42-bit cryptographic randomness. Practically impossible to collide, even across distributed systems. Safe for use as database keys, slugs, file names, or event IDs.

Contributing

Contributions welcome! Please submit issues or pull requests to the GitHub repository.

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/your-feature).
  3. Commit changes (git commit -m 'Add your feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. Open a pull request.

Issues

Report bugs or request features at https://github.com/niefdev/lazyid/issues.

License

MIT © niefdev

Author

Developed by niefdev

Version

Current version: 1.0.0

Repository

Source code: https://github.com/niefdev/lazyid

Homepage

Learn more: https://github.com/niefdev/lazyid#readme

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

lazyid-1.0.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

lazyid-1.0.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file lazyid-1.0.0.tar.gz.

File metadata

  • Download URL: lazyid-1.0.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for lazyid-1.0.0.tar.gz
Algorithm Hash digest
SHA256 98eb8d1a7b9b496a5c328ef735c3b9ca3dbb770775b4ab7d8b13811a571fdc6b
MD5 94b88fc059b6518bfc64246f53ff8db4
BLAKE2b-256 9a9826d0815383eb1d5a97bc2e4979c8e632afb932bbb3db49202438f4646ee3

See more details on using hashes here.

File details

Details for the file lazyid-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: lazyid-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for lazyid-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39ae5d04e3b7c882ee304cc32d6af8d1391bbd4d5814ced9a8d181d1d06b776e
MD5 f7c4ab51974c1a702d22ea8fa7381cb5
BLAKE2b-256 5fa5b219f71420c1a52a0c45cbb4b901a76b48e2eb3a0808d8405552327e212c

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