Skip to main content

A minimalistic [PyDub](http://pydub.com) clone.

Project description

snips-skill

Helpers to keep Snips skills in Python3 free of boilerplate code.

Contents

  • MqttClient: A thin wrapper around paho-mqtt
  • CommandLineClient skeleton MQTT command line client with connection settings.
  • SnipsClient: Reads connection parameters from /etc/snips/toml
  • Snips-specific decorators for callbacks, see below.
  • MultiRoomConfig: Utilities for multi-room setups.
  • Skill: Base class for Snips actions.
  • @intent decorator, see below.

Plain MQTT clients

Plain MQTT is supported via the MqttClient and CommandLineClient classes and the @topic decorator.

A CommandLineClient provides argument parsing for connection parameters and includes standard logging. For message handling, define a function or method as above, and decorate it with @topic. This registers the method (or function) as a callback for the given MQTT topic.

Usage example

from snips_skill import CommandLineClient, topic

class Logger( CommandLineClient):
    'Log all incoming MQTT messages'
    
    @topic( '#')
    def print_msg( self, userdata, msg):
        self.log.info( "%s: %s", msg.topic, msg.payload[:64])

if __name__ == '__main__':
    Logger().run()

Snips session event decorators

The Skill class provides automatic connection configuration via /etc/snips/toml. Also, the following Snips-specific decorators for session events are provided:

  • on_intent: Handle intents,
  • on_intent_not_recognized: Handle unknown intents,
  • on_start_session: Called before session start,
  • on_continue_session: Called for subsequent session prompts,
  • on_session_started: Called at session start,
  • on_end_session: Called before session end,
  • on_session_ended: Called at session end.

All decorators can be used either on standalone callback functions, or on methods of the various client classes (including Skill).

Methods should expect the parameters self, userdata, msg, and standalone functions should expect client, userdata, msg.

Multiple decorators on the same method are possible, but if they have inconsistent qos values, the results will be unpredictable. Also note that multiple decorators will produce repetitive log lines with DEBUG level. Set log_level=None on all but one decorator to fix it.

The @intent decorator

@intent-decorated callbacks receive msg.paylod as an IntentPayload object, a parsed version of the JSON intent data. Slot values are converted to appropriate Python types.

The next step in the Snips session depends on the outcome of the decorated function or method:

  • If the function returns a string or raises a SnipsError, the session ends with a message,
  • If it returns en empty string, the session is ended silently.
  • If it raises a SnipsClarificationError, the session is continued with a question. This can be used to narrow down parameters or to implement question-and-answer sequences.

To require a minimum level of confidence for an intent, put @min_confidence below @intent.

To ensure that certain slots are present in the intent, put @require_slot with a slot name below @intent.

The @intent decorator should not be used in combination with any on_* decorators.

Usage example

from snips_skill import intent, Skill

class HelloSkill( Skill):
    'Snips skill to say hello'
    
    @intent( 'example:hello')
    def say_hello( self, userdata, msg):
        return 'Hello, there'
        
if __name__ == '__main__':
    HelloSkill().run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snips-skill-0.1.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

snips_skill-0.1.0-py2.py3-none-any.whl (22.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file snips-skill-0.1.0.tar.gz.

File metadata

  • Download URL: snips-skill-0.1.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for snips-skill-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5c6a8f3dfb67a20cf32c67b0aae98e08a38af55baa1940e6b23719dfe415ed6f
MD5 8531ea1bd442ff865bb97ac00af4f60a
BLAKE2b-256 668ca838a51323c5bf35991cc9852c262387ef1f4c0668953e6a0a83ad82c41d

See more details on using hashes here.

File details

Details for the file snips_skill-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: snips_skill-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for snips_skill-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ca84d3de27846a636450ce96a9443c007590caedf7762bb9d1fcc78f4afa1384
MD5 fa139dd912ff76e72b7c4f99ab3d575c
BLAKE2b-256 9bbf99d3778c0d9eaf76213a132b9b9a9d9dc0e4566c33194d18638d267c230f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page