Functions
hash_str
Hash string content using specified algorithm.
hash_str
def hash_str(content: str, truncate: int | None = None, algorithm: str = 'sha256') -> str
Hash string content using specified algorithm.
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
content |
str |
— | String content to hash |
truncate |
int | None |
None |
Truncate result to N characters (None = full hash) |
algorithm |
str |
'sha256' |
Hash algorithm ('sha256', 'md5') |
Returns
Hex digest of hash, optionally truncatedstr
—
hash_bytes
Hash bytes content using specified algorithm.
hash_bytes
def hash_bytes(content: bytes, truncate: int | None = None, algorithm: str = 'sha256') -> str
Hash bytes content using specified algorithm.
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
content |
bytes |
— | Bytes content to hash |
truncate |
int | None |
None |
Truncate result to N characters (None = full hash) |
algorithm |
str |
'sha256' |
Hash algorithm ('sha256', 'md5') |
Returns
Hex digest of hash, optionally truncatedstr
—
hash_dict
Hash dictionary deterministically (sorted keys, string serialization).
hash_dict
def hash_dict(data: dict[str, Any], truncate: int | None = 16, algorithm: str = 'sha256') -> str
Hash dictionary deterministically (sorted keys, string serialization).
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
data |
dict[str, Any] |
— | Dictionary to hash |
truncate |
int | None |
16 |
Truncate result to N characters (default: 16) |
algorithm |
str |
'sha256' |
Hash algorithm ('sha256', 'md5') |
Returns
Hex digest of hashstr
—
hash_file
Hash file content by streaming (memory-efficient for large files).
hash_file
def hash_file(path: Path, truncate: int | None = None, algorithm: str = 'sha256', chunk_size: int = 8192) -> str
Hash file content by streaming (memory-efficient for large files).
Parameters 4
| Name | Type | Default | Description |
|---|---|---|---|
path |
Path |
— | Path to file |
truncate |
int | None |
None |
Truncate result to N characters (None = full hash) |
algorithm |
str |
'sha256' |
Hash algorithm ('sha256', 'md5') |
chunk_size |
int |
8192 |
Read buffer size in bytes |
Returns
Hex digest of file content hashstr
—
hash_file_with_stat
Hash file for fingerprinting (includes mtime for fast invalidation).
Combines file content hash wi…
hash_file_with_stat
def hash_file_with_stat(path: Path, truncate: int | None = 8, algorithm: str = 'sha256') -> str
Hash file for fingerprinting (includes mtime for fast invalidation).
Combines file content hash with modification time for efficient cache invalidation without re-hashing unchanged files.
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
path |
Path |
— | Path to file |
truncate |
int | None |
8 |
Truncate result to N characters (default: 8 for URLs) |
algorithm |
str |
'sha256' |
Hash algorithm |
Returns
Fingerprint string suitable for URLsstr
—