Skip to main content

Python bindings for GxHash

Project description

gxhash-py

GitHub PyPi PyPI - Downloads python codecov main.yml

Shows a bar chart with benchmark results.

128-bit hash throughput (MiB/s)

Python bindings for GxHash, a blazingly fast and robust non-cryptographic hashing algorithm.

Highlights

  • Fastest non-cryptographic hash algorithm of its class.
  • Pure Rust backend with zero additional Python runtime overhead.
  • Zero-copy data access across the FFI boundary via the buffer protocol.
  • Support for async hashing with multithreaded parallelism for non-blocking applications.
  • Passes all SMHasher tests and produces high-quality, hardware-accelerated 32/64/128-bit hashes.
  • Guaranteed stable hashes across all supported platforms.
  • Provides a performant, drop-in replacement for the built-in hashlib module.
  • SIMD-accelerated hexdigest encoding with SSSE3/NEON intrinsics.
  • Fully-typed, clean API with uncompromising strict-mode conformance across all major type checkers.
  • Zero-dependency installations on all platforms supported by maturin and puccinialin.

Installation

gxhash is available on PyPI and can be installed via pip.

pip install gxhash

For the best throughput, you can allow gxhash to use wider registers by installing with the MATURIN_PEP517_ARGS environment variable.

[!WARNING]
This is only possible on systems that support VAES and AVX2 instruction sets. Running on unsupported hardware will result in an illegal instruction error at runtime.

MATURIN_PEP517_ARGS="--features hybrid" pip install gxhash

By default, gxhash attempts to detect and use your system's vectorisation features. You can manually control this by setting the specific RUSTFLAGS for your machine. For x64 systems, the minimum required features are aes and ssse3.

RUSTFLAGS="-C target-feature=+aes,+ssse3" pip install gxhash

For ARM64 systems, the minimum required features are aes and neon.

RUSTFLAGS="-C target-feature=+aes,+neon" pip install gxhash

Supported Platforms

gxhash is well supported across a wide range of platforms, thanks in part to maturin, and more specifically puccinialin. Therefore, gxhash supports all platforms that maturin and puccinialin support. gxhash is also actively tested on the following platforms:

  • Ubuntu 24.04 x64
  • Ubuntu 24.04 ARM64
  • macOS 15 x64
  • macOS 15 ARM64
  • Windows Server 2025 x64
  • Windows 11 ARM64

Usage

Hashing bytes.

from gxhash import GxHash32

def main() -> None:
    gxhash = GxHash32(seed=0)
    result = gxhash.hash(b"Hello, world!")

if __name__ == "__main__":
    main()

Hashing bytes asynchronously.

from asyncio import run
from gxhash import GxHash128

async def main() -> None:
    gxhash = GxHash128(seed=0)
    result = await gxhash.hash_async(b"Hello, world!")

if __name__ == "__main__":
    run(main())

As a drop-in replacement for hashlib.

[!WARNING]
GxHash is not an incremental hasher, and all inputs provided to the update method will be accumulated internally. This can lead to an unexpected increase in memory usage if you are expecting streaming behaviour. Also note that hash computation in gxhash.hashlib functions are deferred and only computed when digest or hexdigest is called.

from gxhash.hashlib import gxhash128

def main() -> None:
    hasher = gxhash128(data=b"Hello, world!", seed=0)
    result = hasher.hexdigest()

if __name__ == "__main__":
    main()

Contribute

Read the CONTRIBUTING.md docs for development setup and guidelines.

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

gxhash-0.4.1.tar.gz (19.9 kB view details)

Uploaded Source

File details

Details for the file gxhash-0.4.1.tar.gz.

File metadata

  • Download URL: gxhash-0.4.1.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gxhash-0.4.1.tar.gz
Algorithm Hash digest
SHA256 7d14b35d5180ce0466c67eb869674d4d7150ad2b557d64c3e885b8cd022a9e63
MD5 2588cc2143952891f5e5851b8a2af680
BLAKE2b-256 bf91776b465da6563d8f510950399fb66a389530d4bb617f827357a75aa820a3

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