Extensión de hashing SHA-256 acelerado con Rust y PyO3
Project description
devlacruz_hashlib
High-performance library for SHA-256 hash functions implemented in Rust with PyO3.
Features
- Ultra-fast computation of SHA-256 hashes
- GIL release during intensive operations
- Compatible with Python 3.7+
- Support for hashing integers, strings, and bytes
- Performance superior to pure Python implementations
Installation
pip install devlacruz_hashlib
```text
## Basic Usage
```python
import devlacruz_hashlib
# Hash of an integer (basic version)
hash1 = devlacruz_hashlib.hash_id_simple(12345)
print(f"Simple hash of integer: {hash1}")
# Hash of an integer (GIL-releasing version)
hash2 = devlacruz_hashlib.hash_id(12345)
print(f"Hash of integer: {hash2}")
# Hash of a string
hash3 = devlacruz_hashlib.hash_string("Hello world")
print(f"Hash of string: {hash3}")
# Hash of bytes
hash4 = devlacruz_hashlib.hash_bytes(b"binary data")
print(f"Hash of bytes: {hash4}")
```text
## Performance
This library provides a SHA-256 hash implementation significantly faster than pure Python solutions. Particularly useful for:
- Processing large volumes of data
- Computing hashes in intensive loops
- Applications where performance is critical
### Performance Comparison
```python
import time
import hashlib
import devlacruz_hashlib
# Test data
data = b"x" * 1000000 # ~1MB of data
# Time with Python's hashlib
start = time.time()
for _ in range(100):
hashlib.sha256(data).hexdigest()
py_time = time.time() - start
print(f"Python hashlib: {py_time:.3f} seconds")
# Time with devlacruz_hashlib
start = time.time()
for _ in range(100):
devlacruz_hashlib.hash_bytes(data)
rust_time = time.time() - start
print(f"devlacruz_hashlib: {rust_time:.3f} seconds")
print(f"Performance improvement: {py_time/rust_time:.1f}x faster")
```text
## Full API
### `hash_id_simple(x: int) → str`
Calculates the SHA-256 hash of an integer. This version does not release Python's GIL.
### `hash_id(x: int) → str`
Calculates the SHA-256 hash of an integer while releasing the GIL. Recommended for parallel processing.
### `hash_string(s: str) → str`
Calculates the SHA-256 hash of a text string. Releases the GIL during processing.
### `hash_bytes(data: bytes) → str`
Calculates the SHA-256 hash of a bytes object. Releases the GIL during processing.
## Technical Considerations
- The module releases the GIL (Global Interpreter Lock) during intensive hash operations, enabling true parallelism in multi-threaded applications.
- The Rust implementation provides memory and type safety without performance overhead.
- Compatible with all major platforms: Linux, Windows, and macOS.
## When to Use devlacruz_hashlib vs Standard hashlib
Use devlacruz_hashlib when:
- Maximum performance is needed for SHA-256 hash operations
- Working with large volumes of data
- Performing hash operations in critical loops
- Utilizing multi-threaded processing where releasing the GIL is advantageous
Use standard `hashlib` when:
- Other algorithms besides SHA-256 are needed
- Simplicity and maintainability are more important than performance
- Avoiding additional dependencies is preferred
## Contributions
Contributions are welcome. To contribute:
1. Fork the repository
2. Create a branch for your feature (`git checkout -b new-feature`)
3. Make your changes and commit (`git commit -am 'Add new feature'`)
4. Push your changes (`git push origin new-feature`)
5. Create a Pull Request
## License
MIT License - See the LICENSE file for more details.
## Author
Alejandro De La Cruz (devlacruz@axtosys.com)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file devlacruz_hashlib-0.1.1.tar.gz.
File metadata
- Download URL: devlacruz_hashlib-0.1.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1422ab6006385669fca7e556833cc2caad609ecdc4c1c287eaa0d4748164d542
|
|
| MD5 |
ac7ab7554da88ec98144e1191431df9c
|
|
| BLAKE2b-256 |
79fd6ba881c05228fa25a471f3c16617434c2fe52a1a9cad9b02a40251cf1525
|
File details
Details for the file devlacruz_hashlib-0.1.1-cp313-cp313-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: devlacruz_hashlib-0.1.1-cp313-cp313-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 235.5 kB
- Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e75978533eff28ca877f71c82b3b6f54741f324248f3f3f7bdb48af2cc82624
|
|
| MD5 |
40b6132d02e83d31f600caf5405e3f4d
|
|
| BLAKE2b-256 |
2e61743854a910863aaf98474dc1b9f1937b943e442269dedeb852e288e4bb0f
|