# hashing

URL: /patitas/api/utils/hashing/
Section: utils
Description: 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'

---

> For a complete page index, fetch /patitas/llms.txt.

Open LLM text
(/patitas/api/utils/hashing/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Futils%2Fhashing%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Futils%2Fhashing%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Futils%2Fhashing%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Futils%2Fhashing%2Findex.txt)

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'
```

3Functions

## 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`

`subtree_hash`

2

`str`

▼

Deterministic structural hash for a Patitas AST node/subtree.

Uses dataclass f…

`def subtree_hash(node: Any, *, truncate: int = 16) -> str`

Deterministic structural hash for a Patitas AST node/subtree.

Uses dataclass field traversal to remain stable across process runs.

##### Parameters

Name
Type
Description

`node`
`Any`

`truncate`
`int`

Default:`16`

##### Returns

`str`
