Registry / database / snowflake-id

snowflake-id

JSON →
library1.0.2pypypi✓ verified 84d ago

A Python library for generating Snowflake-like unique IDs, inspired by Twitter's Snowflake ID. Version 1.0.2 supports Python 3.8+ and provides a simple interface for distributed unique ID generation with configurable epoch, worker ID, and sequence. The library is stable but not frequently updated.

pip install snowflake-id
INSTALL
IMPORT
SIG · SNOWFLAKE-ID
S
snowflake-id
databasepythonv1.0.2
Install
1.6s avg
Import
41ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.044s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.038s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SnowflakeGenerator
from snowflake import SnowflakeGenerator
The module name is 'snowflake', not 'snowflake_id' or 'snowflake_id_generator'.

Create a generator with a worker ID (0-1023) and generate IDs by calling next().

from snowflake import SnowflakeGenerator gen = SnowflakeGenerator(42) # instance (worker ID) snowflake_id = next(gen) print(snowflake_id)
Debug
Known issues
gotchaThe SnowflakeGenerator is an iterator; you must call next() or iterate over it. Many users mistakenly call gen.generate() or gen.get_id() which don't exist.
fix
Use next(gen) or for id in gen: ...
affects: all
gotchaThe worker ID range is 0-1023 (10 bits). Using a value outside this range may cause unexpected behavior or errors. The library does not validate strictly.
fix
Ensure worker ID is an integer between 0 and 1023.
affects: all
gotchaSnowflake IDs are not guaranteed to be strictly increasing across multiple processes with different worker IDs if system clocks are not synchronized. This is by design but can cause confusion.
fix
Use NTP or similar time synchronization across workers.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'SnowflakeGenerator' from 'snowflake_id'
Incorrect import path. The package name on PyPI is 'snowflake-id', but the import module is 'snowflake'.
fix
Run: pip install snowflake-id, then import: from snowflake import SnowflakeGenerator
AttributeError: 'SnowflakeGenerator' object has no attribute 'generate'
Trying to call a method like gen.generate() instead of using the iterator protocol.
fix
Use next(gen) to get the next ID.
Upgrade
Version history
1.0.2latest on PyPI · released Apr 17, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Meta
2
Resources
snowflake-id — pip install snowflake-id · libregistry