nemony package

Submodules

nemony.cli module

Command line interface for nemony.

nemony.cli.main() None[source]

nemony.nemony module

Encoding Python objects as mnemonic adjective-noun pairs.

Currently supports strings, iterables, floats and ints.

nemony.nemony.encode(x: str | int | float | Iterable, sep: str = '_', n: int = 8, wordlist: Sequence[Sequence[str], Sequence[str]] | None = None) str[source]

Encode an object as an adjective-noun pair.

Works for strings, integers, floats, and iterables containing those types.

Parameters:
  • x (str | int | float | Iterable) – Python object to encode.

  • sep (str) – Separator between adjective and noun.

  • n (int, optional) – Number of digits to take from hexadecimal of SHA-256 hash. Default: 8.

  • wordlist (tuple, optional) – 2-tuple containing adjective list and noun list. Default: use builtin word list.

Returns:

Adjective and noun separated by sep.

Return type:

str

Examples

>>> encode('hello')
'decorous_block'
>>> encode('world')
'late_kevin'
>>> encode('world', sep='-')
'late-kevin'
>>> encode('world', sep='-', n=5)
'peppy-gabriel'
>>> encode(5.)
'live_drum'
>>> encode(['hello', 'world']) == encode(('hello', 'world'))
True
nemony.nemony.hash(x, *args, **kwargs) str[source]
nemony.nemony.hash(x: str, n: int | None = None) str
nemony.nemony.hash(x: int, n: int | None = None) str
nemony.nemony.hash(x: float, n: int | None = None) str
nemony.nemony.hash(x: Iterable, n: int | None = None, listsep: str = '\n') str

Hash an object using SHA-256 and take the first n hexadecimal digits.

Parameters:
  • x (str | int | float | Iterable) – Object to hash.

  • n (int, optional) – Truncate to first n digits. Default: use all 64 digits.

  • listsep (str, optional) – Character to use to separate entries of iterable. Default: newline.

Returns:

Hexadecimal representation of hashed string.

Return type:

str

Raises:

TypeError – If the object is not supported.

Examples

>>> hash('world')
'486ea46224d1bb4fb680f34f7c9ad96a8f24ec88be73ea8e5a6c65260e9cb8a7'
>>> hash('world', n=8)
'486ea462'
>>> hash(5., n=8)
'a19a1584'
>>> hash(['hello', 'world']) == hash(('hello', 'world'))
True

Module contents