Skip to main content

A Sonyflake implementation optimized for extreme usages.

Project description

A SonyFlake ID generator tailored for high-volume ID generation.

Installation

pip install sonyflake-turbo

Usage

Easy mode:

from sonyflake_turbo import SonyFlake

sf = SonyFlake(0x1337, 0xCAFE)

for _, id_ in zip(range(10), sf):
    print(f"{id_:016x}")

Turbo mode:

from datetime import datetime, timezone
from random import sample
from timeit import timeit

from sonyflake_turbo import SONYFLAKE_MACHINE_ID_MAX, SonyFlake

epoch = datetime(2025, 6, 5, tzinfo=timezone.utc)

for count in [32, 16, 8, 4, 2, 1]:
    machine_ids = sample(range(SONYFLAKE_MACHINE_ID_MAX + 1), count)
    sf = SonyFlake(*machine_ids, start_time=int(epoch.timestamp()))
    t = timeit(lambda: [next(sf) for _ in range(1000)], number=1000)
    print(f"Speed: 1M ids / {t:.2f}sec with {count} machine IDs")

Important Notes

SonyFlake algorithm produces IDs at rate 256 IDs per 10msec per 1 Machine ID. One obvious way to increase the throughput is to use multiple generators with different Machine IDs. This library provides a way to do exactly that by passing multiple Machine IDs to the constructor of the SonyFlake class. Generated IDs are non-repeating and are always increasing. But be careful! You should be conscious about assigning Machine IDs to different processes and/or machines to avoid collisions. This library does not come with any Machine ID management features, so it’s up to you to figure this out.

This library has limited free-threaded mode support. It won’t crash, but you won’t get much performance gain from multithreaded usage. Consider creating generators per thread instead of sharing them across multiple threads.

Development

Install:

python3 -m venv env
. env/bin/activate
pip install -e .[test]

Run tests:

py.test

Building wheels:

pip install cibuildwheel
cibuildwheel

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

sonyflake_turbo-0.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distributions

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

sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_x86_64.whl (9.0 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_i686.whl (9.8 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_aarch64.whl (9.7 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.7 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (9.6 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.3 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

sonyflake_turbo-0.1.0-cp38-abi3-macosx_11_0_arm64.whl (7.6 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file sonyflake_turbo-0.1.0.tar.gz.

File metadata

  • Download URL: sonyflake_turbo-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sonyflake_turbo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9a782c56076937ad52d02215570f26cac4a1bf761fce783e01318f19a5251bb9
MD5 6a68c3a263a71f37e2af6f2832685476
BLAKE2b-256 4c3b7ff263f528024b1611b11be07d7c62433cbfeaf0289f724a6800739ad0a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-0.1.0.tar.gz:

Publisher: publish.yml on ZipFile/python-sonyflake-turbo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 71d3eeee7aff2ff5fdb25df2f510a919cc0f021b0ac60505cebcad18d6a9e17b
MD5 093a8e0d67b3bc3b06c71f427600d272
BLAKE2b-256 ea604c6c60eff6875dceb0283168d98979e70af4e97c70adbf4c5e253b41aeb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_x86_64.whl:

Publisher: publish.yml on ZipFile/python-sonyflake-turbo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 46c57e5518264a044593d165b05c6207b44f4fab620945b265efa1703c3e2d00
MD5 9c29302b9bea144376b3c0e526e467b3
BLAKE2b-256 eb03eaa2c09bd1d33b7885fa7f63202c15cd1ca3cd3a187a845d08fe58095789

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_i686.whl:

Publisher: publish.yml on ZipFile/python-sonyflake-turbo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 baad91df46297aadd089137fd4401d805166cde305cb3b3ecee70b158d5e9f92
MD5 b2c9e2cc6d8b4c3881891dd9cca7d06c
BLAKE2b-256 22affa9cbf2a8959989d38a765fac91fe6e53a138056d4ef0a4274058e6f8cad

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-0.1.0-cp38-abi3-musllinux_1_2_aarch64.whl:

Publisher: publish.yml on ZipFile/python-sonyflake-turbo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4d9de1874d089a512d545ad6e1fda2c68254c5791a3681065b58a2b2798588c8
MD5 8ec4f0ce68544f00b43efc04d3833838
BLAKE2b-256 7609a60782c6edb0e4fcec53862d265e3274620bd9d1c660526106c8ba8533a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on ZipFile/python-sonyflake-turbo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f0b16588d6a6a56fac12f15e428af411034fa32945a9eab31e60362875da0e34
MD5 5943b489529fef645a1c4a18bd0081dd
BLAKE2b-256 8a78ffcb057e616064d5c5ff32666ec33576c7294f9c9e48a5f46998a97499b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: publish.yml on ZipFile/python-sonyflake-turbo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d6330ebb338c2b1172f702e0cf432b1afde529b7462b018c3271570dcb27eb8d
MD5 a68dd393a7a147473884bbeed1d275a2
BLAKE2b-256 52bf40670985538c28762fef842a48a525e16fff8f1081cc88b347ee1d78d4ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on ZipFile/python-sonyflake-turbo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sonyflake_turbo-0.1.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6801c523b4d70b7b0b075912f8605bd98ae34bb4f8ed7469e24b500a96154fb9
MD5 bbf3589df860f4ac25ce726e595f8d33
BLAKE2b-256 0d17a83f6e62ed73cde3990106ed43f140f5e0855ecb1ce0fcc990411a0e54cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-0.1.0-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on ZipFile/python-sonyflake-turbo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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