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.
1
@skill_api_method
2
def my_exported_method(self, my_arg, my_other_arg):
3
"""My skill api method documentation
4
"""
Copied!
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

1
from mycroft.skills import MycroftSkill, skill_api_method
2
3
class RobberSkill(MycroftSkill):
4
@skill_api_method
5
def robber_lang(self, sentence):
6
"""Encode a sentence to "Rövarspråket".
7
8
Each consonant gets converted to consonant + "o" + consonant,
9
vowels are left as is.
10
11
Returns: (str) sentence in the robber language.
12
"""
13
wovels = "aeiouyåäö"
14
tokens = []
15
for char in sentence.lower() and char.isalpha():
16
if char not in wovels:
17
tokens.append(char + 'o' + char)
18
else:
19
tokens.append(char)
20
return ' '.join(tokens)
21
22
23
def create_skill():
24
return RobberSkill()
Copied!

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:
1
from mycroft.skills.api import SkillApi
2
3
class NewRobberSkill(MycroftSkill):
4
def initialize(self):
5
self.robber = SkillApi.get('robber-skill.forslund')
6
self.speak(self.robber.robber_lang('hello world'))
7
8
9
def create_skill():
10
return NewRobberSkill()
Copied!
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.
1
:api robber-lang.forslund
Copied!
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.
Last modified 7mo ago