betty.hashid module

Provides utilities to generate unique IDs through hashing.

This module MUST NOT be used for security purposes.

betty.hashid.hashid(key: bytes | str) str[source]

Create a hash ID for a key.

async betty.hashid.hashid_file_content(file_path: Path) str[source]

Create a hash ID for a file based on its contents.

This function relies on the file path and contents for uniqueness. File contents must be loaded into memory in their entirety, which is why betty.hashid.hashid_file_meta() may be more suitable for large files.

async betty.hashid.hashid_file_meta(file_path: Path) str[source]

Create a hash ID for a file based on its metadata.

This function relies on the file path, size, and last modified time for uniqueness. File contents are ignored. This may be suitable for large files whose exact contents may not be very relevant in the context the ID is used in.

betty.hashid.hashid_sequence(*keys: bytes | str) str[source]

Create a hash ID from a sequence of keys.