Registry / serialization / siphash24

siphash24

JSON →
library1.8pypypi✓ verified 21d ago

The siphash24 library provides a C-based, streaming-capable implementation of SipHash-1-3 and SipHash-2-4 variants for Python. It offers an interface compatible with Python's standard `hashlib` module, enhancing it with an `intdigest()` method for integer hash values. The current version is 1.8, with releases occurring several times a year to support new Python versions and address minor updates.

pip install siphash24
INSTALL
IMPORT
SIG · SIPHASH24
S
siphash24
serializationpythonv1.8
Install
1.6s avg
Import
Disk
16MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.8 · 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
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

siphash24
import siphash24
Imports the module itself, which provides functions and hashlib-compatible classes.
siphash13
import siphash24
The siphash13 function is accessed via the top-level siphash24 module, e.g., siphash24.siphash13().

Demonstrates how to use both SipHash-2-4 (streaming) and SipHash-1-3 (one-shot) variants. It highlights the `hashlib`-compatible interface methods (`update`, `digest`, `hexdigest`) and the library's extended `intdigest` method. Keys are managed via environment variables for security best practice.

import siphash24 import os # SipHash-2-4 example (recommended variant) key = os.environ.get('SIPHASH_KEY_24', 'a' * 16).encode('utf-8') # 16-byte key message = b'hello world' h = siphash24.siphash24(key=key) h.update(message) hash_digest = h.digest() hash_int = h.intdigest() hash_hex = h.hexdigest() print(f"SipHash-2-4 digest: {hash_digest.hex()}") print(f"SipHash-2-4 int digest: {hash_int}") print(f"SipHash-2-4 hex digest: {hash_hex}") # SipHash-1-3 example key_13 = os.environ.get('SIPHASH_KEY_13', 'b' * 16).encode('utf-8') # 16-byte key m_13 = siphash24.siphash13(key=key_13, data=b'another message') print(f"SipHash-1-3 digest (one-shot): {m_13.digest().hex()}")
Debug
Known issues
gotchaThe `digest()` method returns a `bytes` object, while the `intdigest()` method returns a Python `int` object. Ensure you use the correct method based on your expected output type.
fix
Use `hash_obj.digest()` for `bytes` output or `hash_obj.intdigest()` for `int` output.
affects: All versions
breakingPrior to version 1.6, the `hexdigest()` method returned a `bytes` object. Starting with version 1.6, `hexdigest()` consistently returns a `str` object for consistency with `hashlib`.
fix
Update your code to expect a `str` return type from `hexdigest()`. If you need `bytes`, encode the string manually (e.g., `.encode('utf-8')`).
affects: <1.6
gotchaInstances of `siphash24` hash objects are not thread-safe. If a single hash object is modified concurrently by multiple threads, external synchronization primitives (e.g., `threading.Lock`) must be used to prevent race conditions.
fix
Use a separate hash object per thread or implement explicit locking mechanisms when sharing hash objects across threads.
affects: All versions
gotchaThe SipHash algorithm requires a 16-byte key. While `siphash24` will zero-pad shorter keys, it is best practice to always provide a 16-byte `bytes-like` object for the key to ensure predictable and secure hashing behavior.
fix
Always provide a 16-byte key as a `bytes-like` object. For example, `b'your_16_byte_key'`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'siphash24'
The `siphash24` package has not been installed in the current Python environment.
fix
Run `pip install siphash24` in your terminal to install the library.
TypeError: a bytes-like object is required, not 'str'
The `update()` method (and other data input methods) of `siphash24` expects a bytes-like object, but a string was provided.
fix
Encode the string to bytes before passing it to `update()`, for example, `data.encode('utf-8')`.
ValueError: Key must be 16 bytes long
The key provided to `siphash24.new()` must be exactly 16 bytes long as required by the SipHash algorithm.
fix
Ensure the key is exactly 16 bytes long. You can generate a secure random key using `os.urandom(16)` or pad/truncate an existing key.
ModuleNotFoundError: No module named 'siphash'
The module name `siphash24` was misspelled as `siphash` in the import statement.
fix
Correct the import statement to `import siphash24` or `from siphash24 import new`.
Upgrade
Version history
1.8latest on PyPI · released Sep 2, 2025
Audit
Dependencies
pythonrequiredRuntime environment
Agent activity
9 hits · last 30 days
node
6
Resources
siphash24 — pip install siphash24 · libregistry