A tool that converts objects into hashes that can be reproduced quickly.
Project description
English description follows Japanese.
obj-hash Documentation (English)
Overview
obj-hash is a Python library that generates fast, deterministic hash values from JSON-serializable objects.
Unlike Python’s built-in hash() function, which produces different values on each interpreter run, obj-hash always returns the same hash for the same logical object structure.
Key Features
- Deterministic hashing for JSON-serializable objects
- Order-independent hashing for dictionaries and similar structures
- Uses BLAKE3, which is faster than SHA-256
- Default output length is 16 bytes (same number of combinations as UUID)
How It Works (Conceptually)
The input object is interpreted by its logical structure and values, not by incidental factors such as:
- Dictionary key insertion order
- Runtime-specific hash seeds
Objects that are logically equivalent (for example, dictionaries with the same keys and values but different orderings) produce the same hash value.
Usage Example
import obj_hash
h = obj_hash("hogehoge")
print(h)
# -> 66787eb34e4b87df2788806ba4750390
print(obj_hash({"23": "hoge", "list": []}))
# -> 1e3145f8a5679e6a00a802f88b7b5ba8
print(obj_hash({"23": "hoge", "list": []}, length=100))
# -> 1e3145f... (100 characters)
print(
obj_hash({"23": "hoge", "list": []})
== obj_hash({"list": [], "23": "hoge"})
)
# -> True
Parameters
-
object
- Any JSON-serializable Python object
-
length (optional)
- Length of the hexadecimal hash string
- Default: 16 bytes (32 hex characters)
obj-hash ドキュメント(日本語)
概要
obj-hash は、JSON化可能なオブジェクトを高速かつ決定的にハッシュ化する Python ライブラリです。
Python 標準の hash() は実行ごとに値が変わりますが、obj-hash は常に同じ論理構造に対して同じハッシュ値を返します。
特徴
- JSON化可能なオブジェクトを決定的にハッシュ化
- 辞書のキー順序に依存しない
- SHA-256 より高速な BLAKE3 を内部で使用
- デフォルトの出力長は 16バイト(UUIDと同等の組み合わせ数)
論理的な動作について
このライブラリは、オブジェクトを 見た目ではなく意味的な構造 として扱います。
そのため、以下のような要素はハッシュ値に影響しません。
- 辞書のキー追加順序
- 実行環境や起動回ごとの差異
同じ内容を表すオブジェクトであれば、構造が同一と判断され、必ず同じハッシュ値が生成されます。
使い方
import obj_hash
h = obj_hash("hogehoge")
print(h)
# -> 66787eb34e4b87df2788806ba4750390
print(obj_hash({"23": "hoge", "list": []}))
# -> 1e3145f8a5679e6a00a802f88b7b5ba8
print(obj_hash({"23": "hoge", "list": []}, length=100))
# -> 1e3145f...(100桁)
print(
obj_hash({"23": "hoge", "list": []})
== obj_hash({"list": [], "23": "hoge"})
)
# -> True
引数
-
object
- JSON化可能な任意の Python オブジェクト
-
length(省略可)
- 16進文字列としての出力長
- デフォルトは 16バイト(32文字)
Project details
Release history Release notifications | RSS feed
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 obj_hash-0.0.0.tar.gz.
File metadata
- Download URL: obj_hash-0.0.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ca5c7ee5fb912f3929b3c430492980836541c7fcade98a1d8acd6a19be78d37
|
|
| MD5 |
b12f5f219297ed06056501ab16655db5
|
|
| BLAKE2b-256 |
b046a2d7ffc62941363d504a291ea281268174b5e9cfc12b8b4dae110b432073
|
File details
Details for the file obj_hash-0.0.0-py3-none-any.whl.
File metadata
- Download URL: obj_hash-0.0.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
665ff4aeea3eeecf11056962f634415d4e4ff038b7a7e0d3e911cc7b4980a015
|
|
| MD5 |
7e369c91e729e9dd12fcfcc3e46e9570
|
|
| BLAKE2b-256 |
613cd9f3e0a2c544449de8194a3dc8bd8a298bc079fd5d17e45494febb4e56fa
|