File size: 283 Bytes
c4757db
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
from __future__ import annotations

import hashlib
import json
from typing import Any


def stable_hash(obj: Any) -> str:
    canonical = json.dumps(obj, ensure_ascii=False, separators=(",", ":"), sort_keys=True)
    return hashlib.sha256(canonical.encode("utf-8")).hexdigest()[:16]