Hashing¶
Functions for generating hashes.
b64_decoded_str ¶
b64_decoded_str(encoded_str)
Decodes an encoded base64 string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_str
|
str
|
A string that has been previously encoded with base64 |
required |
Returns:
| Type | Description |
|---|---|
str
|
a decoded base 64 string |
Source code in src/aibs_informatics_core/utils/hashing.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
b64_encoded_str ¶
b64_encoded_str(decoded_str)
Encodes a string with base 64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decoded_str
|
str
|
Any string |
required |
Returns:
| Type | Description |
|---|---|
str
|
an encoded base 64 string |
Source code in src/aibs_informatics_core/utils/hashing.py
80 81 82 83 84 85 86 87 88 89 | |
generate_file_hash ¶
generate_file_hash(
filename, bufsize=128 * 1024, hash_type="sha256"
)
Generate a hash for a file
https://stackoverflow.com/a/70215084/4544508
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
filepath to hash |
required |
bufsize
|
int
|
buffer size. Defaults to 128*1024. |
128 * 1024
|
hash_type
|
Literal['md5', 'sha256']
|
type of hash to generate. Defaults to "sha256". |
'sha256'
|
Returns:
| Type | Description |
|---|---|
str
|
hash value of file |
Source code in src/aibs_informatics_core/utils/hashing.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
generate_path_hash ¶
generate_path_hash(
path, includes=None, excludes=None, hash_type="sha256"
)
Generate a hash based on files found under a given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
path to compute a hash |
required |
includes
|
List[str]
|
list of regex patterns to include. Defaults to None. |
None
|
excludes
|
List[str]
|
list of regex patterns to exclude. Defaults to None. |
None
|
hash_type
|
Literal['md5', 'sha256']
|
type of hash to generate. Defaults to "sha256". |
'sha256'
|
Returns:
| Type | Description |
|---|---|
str
|
hash value |
Source code in src/aibs_informatics_core/utils/hashing.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
sha256_hexdigest ¶
sha256_hexdigest(content=None)
Create a SHA 256 Hex Digest string from optional content.
If content is not provided, a unique Hex Digest is generated from UUID
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
JSON
|
Input to base hexdigest off of. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
a SHA 256 hex digest string. |
Source code in src/aibs_informatics_core/utils/hashing.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
urlsafe_b64_decoded_str ¶
urlsafe_b64_decoded_str(encoded_str)
Decodes an encoded base64 string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_str
|
str
|
A string that has been previously encoded with base64 |
required |
Returns:
| Type | Description |
|---|---|
str
|
a decoded base 64 string |
Source code in src/aibs_informatics_core/utils/hashing.py
92 93 94 95 96 97 98 99 100 101 | |
urlsafe_b64_encoded_str ¶
urlsafe_b64_encoded_str(decoded_str)
Encodes a string with a URL SAFE version of base 64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decoded_str
|
str
|
Any string |
required |
Returns:
| Type | Description |
|---|---|
str
|
an encoded base 64 string |
Source code in src/aibs_informatics_core/utils/hashing.py
104 105 106 107 108 109 110 111 112 113 | |
uuid_str ¶
uuid_str(content=None)
Get a UUID String, with option for using a seed to ensure determinism.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
A seed to use for determining UUID. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
UUID appropriate string |
Source code in src/aibs_informatics_core/utils/hashing.py
30 31 32 33 34 35 36 37 38 39 40 41 | |