Mycroft AI
  • Documentation
  • About Mycroft AI
    • Why use Mycroft AI?
    • Glossary of terms
    • Contributing
    • FAQ
  • Using Mycroft AI
    • Get Mycroft
      • Mark II
        • Mark II Dev Kit
      • Mark 1
      • Picroft
      • Linux
      • Mac OS and Windows with VirtualBox
      • Docker
      • Android
    • Pairing Your Device
    • Basic Commands
    • Installing New Skills
    • Customizations
      • Configuration Manager
      • mycroft.conf
      • Languages
        • Français (French)
        • Deutsch (German)
      • Using a Custom Wake Word
      • Speech-To-Text
      • Text-To-Speech
    • Troubleshooting
      • General Troubleshooting
      • Audio Troubleshooting
      • Wake Word Troubleshooting
      • Log Files
      • Support Skill
      • Getting more support
  • Skill Development
    • Voice User Interface Design Guidelines
      • What can a Skill do?
      • Design Process
      • Voice Assistant Personas
      • Interactions
        • Intents
        • Statements and Prompts
        • Confirmations
      • Conversations
      • Error Handling
      • Example Interaction Script
      • Prototyping
      • Design to Development
    • Development Setup
      • Python Resources
      • Your First Skill
    • Skill Structure
      • Lifecycle Methods
      • Logging
      • Skill Settings
      • Dependencies
        • Manifest.yml
        • Requirements files
      • Filesystem access
      • Skill API
    • Integration Tests
      • Test Steps
      • Scenario Outlines
      • Test Runner
      • Reviewing the Report
      • Adding Custom Steps
      • Old Test System
    • User interaction
      • Intents
        • Padatious Intents
        • Adapt Intents
      • Statements
      • Prompts
      • Parsing Utterances
      • Confirmations
      • Conversational Context
      • Converse
    • Displaying information
      • GUI Framework
      • Show Simple Content
      • Mycroft-GUI on a PC
      • Mark 1 Display
    • Advanced Skill Types
      • Fallback Skill
      • Common Play Framework
      • Common Query Framework
      • Common IoT Framework
    • Mycroft Skills Manager
      • Troubleshooting
    • Marketplace Submission
      • Skills Acceptance Process
        • Information Review Template
        • Code Review Template
        • Functional Review Template
        • Combined Template
      • Skill README.md
    • FAQ
  • Mycroft Technologies
    • Technology Overview
    • Roadmap
    • Mycroft Core
      • MessageBus
      • Message Types
      • Services
        • Enclosure
        • Voice Service
        • Audio Service
        • Skills Service
      • Plugins
        • Audioservice Plugins
        • STT Plugins
        • TTS Plugins
        • Wake Word Plugins
      • Testing
      • Legacy Repo
    • Adapt
      • Adapt Examples
      • Adapt Tutorial
    • Lingua Franca
    • Mimic TTS
      • Mimic 3
      • Mimic 2
      • Mimic 1
      • Mimic Recording Studio
    • Mycroft GUI
      • Remote STT and TTS
    • Mycroft Skills Kit
    • Mycroft Skills Manager
    • Padatious
    • Precise
    • Platforms
Powered by GitBook
On this page
  • Making a method available through the Skill API
  • Limitations
  • Example
  • Using another Skill's API
  • Getting information on a Skill's exported API

Was this helpful?

  1. Skill Development
  2. Skill Structure

Skill API

The Skill API offers a simple and convenient way to use other Skill's methods and export your own to help other Skill creators.

The Skill API uses the Mycroft Message Bus to communicate between Skills and wraps the interaction in simple Python objects making them easy to use.

Making a method available through the Skill API

A method can be tagged with the skill_api_method decorator. This will handle all the basics of making the method available to other Skills over the Message Bus.

    @skill_api_method
    def my_exported_method(self, my_arg, my_other_arg):
    """My skill api method documentation
    """

The decorator will generate everything needed for accessing the method over the Message Bus and extract the associated docstring.

Limitations

The Skill API works over the Message Bus. This requires that the return values are json serializable. All common Python builtin types (such as List, String, None, etc.) work well, however custom classes are not currently supported.

Example

from mycroft.skills import MycroftSkill, skill_api_method

class RobberSkill(MycroftSkill):
    @skill_api_method
    def robber_lang(self, sentence):
        """Encode a sentence to "Rövarspråket".

        Each consonant gets converted to consonant + "o" + consonant,
        vowels are left as is.

        Returns: (str) sentence in the robber language.
        """
        wovels = "aeiouyåäö"
        tokens = []
        for char in sentence.lower() and char.isalpha():
            if char not in wovels:
                tokens.append(char + 'o' + char)
            else:
                tokens.append(char)
        return ' '.join(tokens)


def create_skill():
    return RobberSkill()

Using another Skill's API

If you want to make use of exported functionality from another Skill, you must fetch that Skill's SkillApi. This will give you a small class with the target Skill's exported methods. These methods are nothing special and can be called like any other class's methods.

To access the robber_lang() method we created above, we could write:

from mycroft.skills.api import SkillApi

class NewRobberSkill(MycroftSkill):
    def initialize(self):
        self.robber = SkillApi.get('robber-skill.forslund')
        self.speak(self.robber.robber_lang('hello world'))


def create_skill():
    return NewRobberSkill()

When the NewRobberSkill is initialized, it will assign the API from the Skill robber-skill.forslund to self.robber. We then run the exported method robber_lang() passing the argument 'hello world'.

Our NewRobberSkill will therefore speak something like "hoh e lol lol o wow o ror lol dod".

Getting information on a Skill's exported API

The Mycroft CLI has an :api command for exploring Skill APIs.

:api robber-lang.forslund

will show any exported method from the robber-lang.forslund Skill. Each exported method's docstring will automatically be extracted and presented, providing information on how each method is intended to be used.

PreviousFilesystem accessNextIntegration Tests

Last updated 4 years ago

Was this helpful?