Skip to content

Hash

HashExtract

Bases: ExtractionMethod

Hashes input string.

Method name: hash

Example configuration

.. code-block:: yaml

- method: hash
  inputs:
    hash_str: $model
    output_key: hashed_terms
Source code in extraction_methods/plugins/hash.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class HashExtract(ExtractionMethod):
    """
    Hashes input string.

    **Method name:** ``hash``

    Example configuration:
        .. code-block:: yaml

            - method: hash
              inputs:
                hash_str: $model
                output_key: hashed_terms
    """

    input_class = HashInput

    @update_input
    def run(self, body: dict[str, Any]) -> dict[str, Any]:

        body[self.input.output_key] = hashlib.md5(
            self.input.input_term.encode("utf-8"), usedforsecurity=False
        ).hexdigest()

        return body

HashInput

Bases: Input

Model for Hash Input.

Parameters:

Name Type Description Default
hash_str str

string to be hashed.

required
output_key str

key to output to.

required
Source code in extraction_methods/plugins/hash.py
25
26
27
28
29
30
31
32
33
34
35
class HashInput(Input):
    """
    Model for Hash Input.
    """

    hash_str: str = Field(
        description="string to be hashed.",
    )
    output_key: str = Field(
        description="key to output to.",
    )