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, start_time=1749081600)

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, MachineIDLCG, SonyFlake

get_machine_id = MachineIDLCG(int(datetime.now(tz=timezone.utc).timestamp()))
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")

Async:

from anyio import sleep  # AsyncSonyFlake supports both asyncio and trio
from sonyflake_turbo import AsyncSonyFlake, SonyFlake

sf = SonyFlake(0x1337, 0xCAFE, start_time=1749081600)
asf = AsyncSonyFlake(sf, sleep)

print(await asf)
print(await asf(5))

async for id_ in asf:
    print(id_)
    break

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.

This library also contains pure-Python implementation as a fallback in case of C extension unavailability (e.g. with PyPy or when installed with --no-binary flag).

Development

Install:

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

Run tests:

py.test

Building wheels:

pip install cibuildwheel
cibuildwheel

Building py3-none-any wheel (without C extension):

SONYFLAKE_TURBO_BUILD=0 python -m build --wheel

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-1.0.0.tar.gz (16.1 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-1.0.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

sonyflake_turbo-1.0.0-cp314-cp314t-win_amd64.whl (18.9 kB view details)

Uploaded CPython 3.14tWindows x86-64

sonyflake_turbo-1.0.0-cp314-cp314t-win32.whl (18.6 kB view details)

Uploaded CPython 3.14tWindows x86

sonyflake_turbo-1.0.0-cp314-cp314t-musllinux_1_2_x86_64.whl (18.9 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

sonyflake_turbo-1.0.0-cp314-cp314t-musllinux_1_2_aarch64.whl (19.8 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ ARM64

sonyflake_turbo-1.0.0-cp314-cp314t-manylinux_2_28_x86_64.whl (18.6 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ x86-64

sonyflake_turbo-1.0.0-cp314-cp314t-manylinux_2_28_aarch64.whl (20.0 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ ARM64

sonyflake_turbo-1.0.0-cp314-cp314t-macosx_11_0_arm64.whl (16.8 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

sonyflake_turbo-1.0.0-cp310-abi3-win_amd64.whl (18.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

sonyflake_turbo-1.0.0-cp310-abi3-win32.whl (17.8 kB view details)

Uploaded CPython 3.10+Windows x86

sonyflake_turbo-1.0.0-cp310-abi3-musllinux_1_2_x86_64.whl (18.4 kB view details)

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

sonyflake_turbo-1.0.0-cp310-abi3-musllinux_1_2_aarch64.whl (19.3 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

sonyflake_turbo-1.0.0-cp310-abi3-manylinux_2_28_x86_64.whl (17.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

sonyflake_turbo-1.0.0-cp310-abi3-manylinux_2_28_aarch64.whl (19.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

sonyflake_turbo-1.0.0-cp310-abi3-macosx_11_0_arm64.whl (16.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for sonyflake_turbo-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e0dd7e2b115032408658ddaefc2870f301b45eeb3619042f32d035025ae257bc
MD5 2f928744f2ab50aa67b281f9677378af
BLAKE2b-256 d976cb2405ab956c54049b430f2e2ad77e1c35e8abacb5f68237422dbcaa3d65

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.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-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a686bf2dc8f1cabaf0eb1b97c0bcdc3696705d9a6b2287fd0a9108df3893b930
MD5 154ba2a6a420688d144c3053bba01224
BLAKE2b-256 72ae1eec8ff78328bb9907fda048a883a41312bf5d17cbcabe291365ce4c0e69

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-py3-none-any.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-1.0.0-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 a3ec907b494029e6de037a3df53382d96739baaf0a110f847c2a1f4ba306ca0b
MD5 3e6e6629f326622d3e7250ddcd1e06d8
BLAKE2b-256 f4b2139c0eb8dbf24faea8dcc571d012be18bca7782e7bc98d353da1384660ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp314-cp314t-win_amd64.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-1.0.0-cp314-cp314t-win32.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 193908248a40d4df0fc201c22d915b7e04e43097670fa9839a737cfd3ed09dcb
MD5 5ad0906914c0ec13bbc02d7524c054b2
BLAKE2b-256 5274e760b2ea9dff62149d6b4aeea26132c1851858c1291f2a1ee853d059b83f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp314-cp314t-win32.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-1.0.0-cp314-cp314t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2fd87226696b97b6fde50606f5a4de647adf1f8f2b9d312b5886046114a99951
MD5 8bf52f622e09f8054bceb24d57f7626d
BLAKE2b-256 445a07dc73cc9b246648e48c76823b2f2b076e4bdeaac291c5f4bf0f69bcda8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp314-cp314t-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-1.0.0-cp314-cp314t-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp314-cp314t-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 085be3f7901d0131a6e849a20c3c27439e983c1fe74410ac52553b92547c338f
MD5 d9715ead766d2879a8424de5bf8e0f47
BLAKE2b-256 a2003777dc41a42deb25ca2637f4be3d3776dbc3bb4993e23b2c623d4dc88499

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp314-cp314t-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-1.0.0-cp314-cp314t-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp314-cp314t-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1daf8f91796dd945113305341f3ea147f215dc3fec33c810e6e3bc8b02c9413d
MD5 dec955f5e26d86c4085400cc790af827
BLAKE2b-256 cb656480cff4acf6c08a2a9036e064775bd2258f8958bde9db8c0554165a0bb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp314-cp314t-manylinux_2_28_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-1.0.0-cp314-cp314t-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp314-cp314t-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cd497df4cb907e98d2393a397df066dd885d32f95325ba60897d6be93c1e4e63
MD5 03279ea84221c5a1dfb07f1d0589934f
BLAKE2b-256 ef870320047db8a60fb565d2b6eabf2ec41d29415ac16fc47c62c366c3296205

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp314-cp314t-manylinux_2_28_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-1.0.0-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 981fba0eadac0a4f1c12d322918380391406def12983eb2a9b0092d644562200
MD5 95205363f2eadb4506c532bccb842f4a
BLAKE2b-256 acd3f83e23053fdd96e79166cedae74a179ef98fd20a14bb416a016207a6f126

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp314-cp314t-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.

File details

Details for the file sonyflake_turbo-1.0.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 82d157332c23e841eae579559b2e4426c69fbe1a66b2cabe33a3d4e8e6b21375
MD5 bc6e67930b141416d944b50813b01f20
BLAKE2b-256 1fd42320c8a474b86df22debd15f213bb3105afa83c9684ac3ed3716558c37ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp310-abi3-win_amd64.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-1.0.0-cp310-abi3-win32.whl.

File metadata

  • Download URL: sonyflake_turbo-1.0.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sonyflake_turbo-1.0.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 5110792efc1a0f0b4c8a791777d0a65694431e6ac401ef191b401da596fcd185
MD5 f36656417b4bf2206e1eab59b6392b59
BLAKE2b-256 7e712d1429a9becd9c7201233f18be2119e6799a627981bb1f24f3c2ee4ea247

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp310-abi3-win32.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-1.0.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 35433b346e8d46b87ede525ec0c77b83c868c3d6f800cca0273d4a05b5e3f271
MD5 2d5c66b944ed61bb88af9b05f1cebe98
BLAKE2b-256 38fd556eefddcbbd742d4b195b5ac4518658cf6fdaaa7c3277c73c2ecaf1b3e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp310-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-1.0.0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 5958ede025828bb42bc0f2c8c83d595f368f187ada07b03281fb070f1f1e778d
MD5 93707365ede1999c0f4ce98138062143
BLAKE2b-256 dc6e4648287518988aadd8fbf4ef25ca5e00eafb38414b1cdd03b3d6b76bbd66

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp310-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-1.0.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d1bf1d116f5f3755d517a8779f717e9e2faf5b01fe36cc67a5835caa87c6f13d
MD5 8b297da0cdd618b41358e568c53700e8
BLAKE2b-256 ea16e3e5ee7b01ced441676fb25510afc58b7c1b199073ba22ac26c10b6bf076

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp310-abi3-manylinux_2_28_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-1.0.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a24599f1d7d842fbf4aadd9f70d55d34870d6afc697f3b7e0e048e8a361d8070
MD5 34c4631f1260d8e20091d054c8d30f0b
BLAKE2b-256 7633c83d01fd890ebf02abfa40acf4233b021738bec6ceba02afcc952d96aac8

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp310-abi3-manylinux_2_28_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-1.0.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sonyflake_turbo-1.0.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d162ca8ddd5ee1cd7d0d07967470fadd38118c23c5b6ec615bd695c3a0f471e9
MD5 b39c64a9138ccfeb08fe81d2e5ee7b1f
BLAKE2b-256 8b52d6a7997340445956fdb7af979cd33481db8b9103c5ef7d1245e3a21291ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonyflake_turbo-1.0.0-cp310-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