Module

utils.hashing

Cryptographic hashing utilities for Patitas.

Provides standardized hashing for cache keys and content fingerprinting.

Example:

>>> from patitas.utils.hashing import hash_str
>>> hash_str("hello world")
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
>>> hash_str("hello world", truncate=16)
'b94d27b9934d3e08'

Functions

hash_str 3 str
Hash string content using specified algorithm.
def hash_str(content: str, truncate: int | None = None, algorithm: str = 'sha256') -> str
Parameters
Name Type Description
content str

String content to hash

truncate int | None

Truncate result to N characters (None = full hash)

Default:None
algorithm str

Hash algorithm ('sha256', 'md5')

Default:'sha256'
Returns
str
hash_bytes 3 str
Hash bytes content using specified algorithm.
def hash_bytes(content: bytes, truncate: int | None = None, algorithm: str = 'sha256') -> str
Parameters
Name Type Description
content bytes

Bytes content to hash

truncate int | None

Truncate result to N characters (None = full hash)

Default:None
algorithm str

Hash algorithm ('sha256', 'md5')

Default:'sha256'
Returns
str