Minimal 14-character URL-safe unique ID generator based on millisecond timestamp and cryptographically secure random bits.
Project description
LazyId
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.
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature). - Commit changes (
git commit -m 'Add your feature'). - Push to the branch (
git push origin feature/your-feature). - 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98eb8d1a7b9b496a5c328ef735c3b9ca3dbb770775b4ab7d8b13811a571fdc6b
|
|
| MD5 |
94b88fc059b6518bfc64246f53ff8db4
|
|
| BLAKE2b-256 |
9a9826d0815383eb1d5a97bc2e4979c8e632afb932bbb3db49202438f4646ee3
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39ae5d04e3b7c882ee304cc32d6af8d1391bbd4d5814ced9a8d181d1d06b776e
|
|
| MD5 |
f7c4ab51974c1a702d22ea8fa7381cb5
|
|
| BLAKE2b-256 |
5fa5b219f71420c1a52a0c45cbb4b901a76b48e2eb3a0808d8405552327e212c
|