Handling

The handling domain enables skills to register their data such as meta, handlers and translations.

This is where you, as a developer, will spend most of your time, see Writing skills for more info.

Basically, you will just declare a python module and use pytlas decorators to register some specific components on the running environment.

Handlers store

Handlers are register on an instance of an HandlersStore, mostly using the intent decorator.

class pytlas.handling.HandlersStore(data: dict = None)

Holds skill handlers.

get(intent_name: str) → Callable

Try to retrieve the handler associated with a particular intent.

Parameters:intent_name (str) – Intent to search
Returns:Handler if found, None otherwise
Return type:callable
register(intent_name: str, func: Callable, package: str = None) → None

Register an intent handler.

Parameters:
  • intent_name (str) – Name of the intent to handle
  • func (callable) – Handler to be called when the intent is triggered
  • package (str) – Optional package name (usually __package__), if not given pytlas will try to determine it based on the call stack

Metas store

Skill meta are registered on a MetasStore, mostly using the meta decorator.

class pytlas.handling.MetasStore(translations_store: pytlas.handling.localization.TranslationsStore = None, data: dict = None)

Hold skill metadatas.

all(lang: str) → List[pytlas.handling.skill.Meta]

Retrieve all registered meta in the given language.

Parameters:lang (str) – Language to use
Returns:Registered Meta
Return type:list of Meta
get(package: str, lang: str) → pytlas.handling.skill.Meta

Retrieve a meta for the given package.

Parameters:
  • package (str) – Package name to retrieve
  • lang (str) – Lang for which you want to retrieve the skill Meta
Returns:

Meta instance or None if not found

Return type:

Meta

register(func: Callable, package: str = None) → None

Register skill package metadata

Parameters:
  • func (func) – Function which will be called with a function to translate strings using the package translations at runtime
  • package (str) – Optional package name (usually __package__), if not given pytlas will try to determine it based on the call stack

Translations store

Translations are registered on a TranslationsStore instance, mostly using the translations decorator.

class pytlas.handling.TranslationsStore(data: dict = None)

Translations store which holds all translations used by skills.

all(lang: str) → Dict[str, Dict[str, str]]

Retrieve all translations for all packages in the given language.

Parameters:lang (str) – Language for which we want translations
Returns:Dictionary of package => translations dict in the given language
Return type:dict
get(package: str, lang: str) → Dict[str, str]

Retrieve all translations for a particular package.

Parameters:
  • package (str) – Name of the package
  • lang (str) – Language to retrieve
Returns:

Translations dictionary

Return type:

dict

register(lang: str, func: Callable, package: str = None) → None

Register translations into the store.

Parameters:
  • lang (str) – Language being loaded
  • func (func) – Function to call to load a dictionary of translations
  • package (str) – Optional package name (usually __package__), if not given pytlas will try to determine it based on the call stack