Skip to main content

A thread safe, monotonic, customizable, eazy to use SnowFlake ID generator

Project description

Snow Lance

Thread safe, monotonic, customizable, eazy to use SnowFlake ID generator.

Installation

pip install snowlance-0.1.0-py3-none-any.whl

Usage

You can initiate a SnowLance as follow:

lance = SnowLance() # all parameters have default values
print(lance.auto())

You may decide the number of bits for each part of the SnowFlake ID, system epoch, as well as timestamp resolution.

lance = SnowLance(
    timestamp_bit_width=42,
    instance_bit_width=10,
    seq_bit_width=12,
    epoch=datetime(2025, 1, 1),
    resolution="ms",
)

Since python does not have a limit on number of bits for intergers, neither does SnowLance. For the sake of compatibility with other non-python systems, you may want to keep the sum of the bits to be 64.

lance = SnowLance(
    timestamp_bit_width=100,
    instance_bit_width=14,
    seq_bit_width=14,
)

Timestamp resolution can be any of ["s", "ms", "us", "ns"]. But be aware, you can run out of time with SnowFlake ID. You can call 'time_left' method to see how much time left for you current epoch and resolution.

lance = SnowLance()
print(lance.time_left)
>>(141.39613429224536, 'years')

With a

Garantees (Expected behavior)

  • Thread safe
  • Monotonic
    • A Snowlance instance garantee to produce monotonically increasing IDs for single runs
    • No garantee for multiple Snowlance instance with same epoch and resolution

Run, build, and test

Install current source code

pip install -e .

Unit test

pip install -e .[test] && pytest

Build from source

rm -rf build/ dist/ *.egg-info/ && python -m build --wheel

You should be able to find the whl file in /dist directory

TODOs

There are a few things to consider

  • Current

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

snowlance-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file snowlance-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: snowlance-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for snowlance-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec889db18e7fa2b21879917883ed1d3426b2a961a492e71f491815c6cfa268f8
MD5 d616a071b17ae8ffc86e10a1cd7f2e18
BLAKE2b-256 967ad3747ca04f0507e1698afa4d97f8ec83f97124c79a627fdd0688587b3a49

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