phrasebook

API Documentation

phrasebook

Note

Most of the functions and objects defined in the phrasebook.phrasebook module are actually available in the top-level (phrasebook) namespace.

Store phrases (SQL, messages, what-have-you) alongside your modules.

phrasebook.phrasebook.PHRASES_SUFFIX = '.phr'

the standard suffix for phrasebook directories

class phrasebook.phrasebook.Phrasebook(path: str = None, suffixes: Iterable[str] = None)[source]

Bases: object

A phrasebook is an indexed collection of string templates.

__init__(path: str = None, suffixes: Iterable[str] = None)[source]
Parameters:
  • path – the path to the phrases directory, or a file that has an accompanying phrasebook directory
  • suffixes – the suffixes of phrase files
get(phrase: str, default: str = None) → string.Template[source]

Get a phrase template.

Parameters:
  • phrase – the name of the phrase template
  • default – a default template or string
Returns:

the template (or the default), or None if no template is defined

See also

gets()

gets(phrase: str, default: str = None) → str[source]

Get a phrase template string.

Parameters:
  • phrase – the name of the phrase template
  • default – a default template or string
Returns:

the template (or the default), or None if no template is defined

items() → ItemsView[str, string.Template][source]

Get the key-value pairs.

load() → phrasebook.phrasebook.Phrasebook[source]

Load the phrases.

Returns:this instance
path

Get the path to the phrases directory.

substitute(phrase: str, default: str = None, safe: bool = True, **kwargs) → str[source]

Perform substitutions on a phrase template and return the result.

Parameters:
  • phrase – the phrase
  • default – a default template
  • safeTrue (the default) to leave the original placeholder in the template in place if no matching keyword is found
  • kwargs – the substitution arguments
Returns:

the substitution result

suffixes

Get the recognized suffixes for phrase files.

phrasebook.sql

SQL phrases (y’know… like queries and query fragments and such…)

class phrasebook.sql.SqlPhrasebook(path: str = None, suffixes: Iterable[str] = ('.sql', ))[source]

Bases: phrasebook.phrasebook.Phrasebook

A SQL phrasebook is an indexed collection of string templates that is particular to SQL phrases.

__init__(path: str = None, suffixes: Iterable[str] = ('.sql', ))[source]
Parameters:
  • path – the path to the phrases directory, or a file that has an accompanying phrasebook directory
  • suffixes – the suffixes of phrase files