betty.hashid module - Betty 0.4.0a3 documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# 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

  Create a hash ID for a key.

  Parameters:

    key (`bytes` | `str`)

  Return type:

    `str`

async betty.hashid.hashid_file_content(file_path: pathlib.Path) → str

  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.

  Parameters:

    file_path (`pathlib.Path`)

  Return type:

    `str`

async betty.hashid.hashid_file_meta(file_path: pathlib.Path) → str

  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.

  Parameters:

    file_path (`pathlib.Path`)

  Return type:

    `str`

betty.hashid.hashid_sequence(*keys: bytes | str) → str

  Create a hash ID from a sequence of keys.

  Parameters:

    keys (`bytes` | `str`)

  Return type:

    `str`