1 About Addons
Kodi Add-ons are extensions that can be run from inside the Kodi GUI. They are usually written by third party developers and published to our official repository. Add-ons can also be published in other repositories or as stand alone zip files anywhere on the internet. Examples of Add-ons include video website streams, scrapers, skins and scripts.
Kodi Add-ons are typically written in python.
Add-ons should work with the latest Krypton Release. Each time a new version of Kodi is released we add new features which may lead to a break compatibility. It is up to the author to update their add-on to remain compatible.
2 Addon system using python
Kodi includes a built-in Python interpreter that allows users to develop add-ons (scripts and plugins) that interface easily and cleanly with the Kodi dashboard. These add-ons can extend the functionality of Kodi without requiring extensive programming experience or ability. While you may not feel comfortable browsing the Kodi source code and submitting patches (or even bug reports), you can learn how to write a script or plugin with just a few hours’ practice, using the information available in these pages.
This page is intended as an introduction to Kodi Python for new developers, and a quick reference for more experienced programmers. If you’re not interested in programming, you might want to visit this page for information about installing and using Python add-ons as an end user. If you’re already familiar with Kodi Python, you can probably skip on down to the environment details or the resource links below for quick reference material.
The very latest Kodi python API documentation “PyDocs” with classes and functions is automatically generated from XBMC’s source code and can be found here (not all functions are available in previous versions): https://codedocs.xyz/xbmc/xbmc/group__python.html (for Kodi 17.x Krypton and onwards)
4 Python plugins versus scripts
Please do not confuse “Plugins” and “Scripts”. It is very important to understand the difference between them before you start coding your addon. Unlike Scripts (which can basically perform any action), Plugins do not really provide new functionality to Kodi, instead what they do is provide a directory listing (for instance, like your movie library) to Kodi. This listing can contain folders as well as files. When a user clicks on a folder, kodi will run the plugin again to retrieve another listing. If a file is clicked, kodi will either play the file directly or call the addon to retrieve a playable url.
Another difference is that scripts can create their own gui (skin) while plugins can’t. Plugin listings are presented in the current skin.
Do not try to mix and match script and plugin functionality as that will only give you weird error messages.
5 Script development
If you’re new to Python programming (or just new to Kodi Python), the easiest way to get started is with a script. The traditional Hello World program, written as an Kodi Python script, would look like this:
That’s the same code you would enter at the Python command line, because Kodi runs a full-featured, standard Python interpreter (for more information concerning the current version number and included modules see the environment details below). If you’re already familiar with Python programming, the only new challenge is learning the custom modules that allow you to gather information from Kodi and manipulate the Graphical User Interface (GUI).
There are some excellent tutorials available to introduce you to Kodi scripting (and Python in general). See the HOW-TO included in the Kodi Online Manual, or visit Alexpoet’s Kodi Scripting site for a popular beginner’s tutorial (PDF).
6 Plugin development
While scripts offer you flexibility and full control over the Kodi GUI, plugins allow you to quickly and consistently present information to the user through the standard Kodi menu structure.
When a user launches a plugin, the plugin generates a list of menu items and hands them to Kodi to draw on the screen (regardless of screen resolution, skin, or any other user setting). While plugin developers lose some amount of control over the presentation, they no longer have to make up their own UIs, or worry about creating a usable look and feel across multiple displays.
Plugins are most commonly used to scrape websites for links to streaming videos, displaying the video list in Kodi just like it would movie files on the local hard drive.
7 Resource links
While the three custom libraries give you control over the Kodi GUI, you’ll eventually want to be able to interact with other parts of the system. Much of Kodi’s functionality is exposed to Python, one way or another. These are some of the systems you can use to make your Python add-ons more useful.
7.1 Must read
A must read for developers is style guide for writing python. This contains the do’s and dont’s when starting to write code.
7.2 List of built-in functions
You can call any of the Kodi Built-in Commands using the function xbmc.executebuiltin().
7.3 Kodi databases (media metadata libraries)
Kodi uses Music and Video Libraries, stored in a SQL (SQLite) database, to store massive amounts of additional meta data concerning local media files (assuming the user has enabled the libraries and chosen the right Content and scraper for each of his sources). Although there’s no direct access from Python to the Kodi Database, you can gain access to the databases from Python through the JSON RPC. Read more about that here.
See Databases for database layout
Kodi uses InfoLabels to display media file information (such as Artist and Album for a song, or Title and Cast list for a movie or TV show). This information shows up in the browsing menu (when using Library Mode), as well as in the Now Playing details when the media player is active.
You can get the currently-playing InfoLabel using the getInfoLabel function in xbmc. You can also set the InfoLabel information for any menu items you create in a plugin, making a much more versatile user experience.
- See: InfoLabels
7.5 Other python pages
There are several other pages in the Kodi Online Manual dedicated to Python development. You can find a comprehensive list by clicking “Python” in the Categories list at the bottom of any Python page. Definitely check out following pages with tons of great sample code.
Need to clean this up:
General Python Info:
A few useful libs for scraping websites:
- http://pypi.python.org/pypi/simplejson/ (included in py2.6 + )
- http://effbot.org/zone/pythondoc-elementtree-ElementTree.htm (included in py2.6 + )
8 Environment details
Kodi comes with Python 2.7
9 Migration to Python 3
10 Out of Date
- With the release of Eden 11.0, some functions are out of date. Please view http://kodi.wiki/view/Eden_API_changes for the latest on incorporating Python scripts.
- With the release of Frodo 12.0, some functions are out of date. Please view http://kodi.wiki/view/Frodo_API_changes for the latest on incorporating Python scripts.
- With the release of Gotham 13.0, some functions are out of date. Please view http://kodi.wiki/view/Gotham_API_changes for the latest on incorporating Python scripts.
- With the release of Helix 14.0, some functions are out of date. Please view http://kodi.wiki/view/Helix_API_changes for the latest on incorporating Python scripts.
- With the release of Isengard 15.0, some functions are out of date. Please view http://kodi.wiki/view/Isengard_API_changes for the latest on incorporating Python scripts.
- With the release of Jarvis 16.0, some functions are out of date. Please view http://kodi.wiki/view/Jarvis_API_changes for the latest on incorporating Python scripts.
11 See also
Learn Modules and Packages in Python programming
Hello World Android app built with Android Studio