<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://kodi.wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fourpointsix</id>
	<title>Official Kodi Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://kodi.wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fourpointsix"/>
	<link rel="alternate" type="text/html" href="https://kodi.wiki/view/Special:Contributions/Fourpointsix"/>
	<updated>2026-06-15T09:34:58Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://kodi.wiki/index.php?title=General_information_about_migration_to_Python_3&amp;diff=253240</id>
		<title>General information about migration to Python 3</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=General_information_about_migration_to_Python_3&amp;diff=253240"/>
		<updated>2024-08-02T22:20:55Z</updated>

		<summary type="html">&lt;p&gt;Fourpointsix: Updated to reflect sunsetting of Python 2&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
Python 3 was first released in 2008, and the last release of Python 2.7 was in 2020. Thanks to a successful [[Archive:Google Summer of Code/2017|Google Summer of Code 2017 project]], Kodi 19.x (Matrix) became the first release to support Python 3.&lt;br /&gt;
&lt;br /&gt;
Since Python 3.x versions are not backward-compatible with Python 2.x, we decided to urge addon developers prior to the 19.x release to port their addons to Python 3 by making the addons compatible with both Python 2 and 3 and submitting them to the official repo. That way, when 19.x was to be released we wouldn&#039;t have a situation with no working addons. Looking back, the transition was rather successful.&lt;br /&gt;
&lt;br /&gt;
Over seven years have since passed and the last release supporting Python 2, 18.x (Leia), has aged out of support. As a result, Python 3 is the only supported addon environment.&lt;br /&gt;
&lt;br /&gt;
This article is for any addon developers who have not yet ported their old addons from Python 2.&lt;br /&gt;
&lt;br /&gt;
== The Process ==&lt;br /&gt;
* For Kodi 19.x (Matrix) and up, only addons that are compatible with Python 3 will be accepted to the official addon repository.&lt;br /&gt;
* There&#039;s a thread on the Kodi forum so that addon devs can get help with their migration process.&lt;br /&gt;
&lt;br /&gt;
== Python 2 And 3 Differences ==&lt;br /&gt;
Below is a brief overview of the main differences between Python 3 and 2.&lt;br /&gt;
&lt;br /&gt;
=== Unicode strings by default ===&lt;br /&gt;
:{{See also|Unicode Concerns}}&lt;br /&gt;
In Python 2, the built-in &#039;&#039;&#039;&amp;lt;tt&amp;gt;str&amp;lt;/tt&amp;gt;&#039;&#039;&#039; type holds the sequence of bytes so it can be used to store both binary data and textual data in ASCII or any of a long list of 8-bit fixed-length encodings. Python 2 also has the &#039;&#039;&#039;&amp;lt;tt&amp;gt;unicode&amp;lt;/tt&amp;gt;&#039;&#039;&#039; type that can store text in various writing systems. The fundamental atomic unit of a &amp;lt;tt&amp;gt;unicode&amp;lt;/tt&amp;gt; object is a Unicode codepoint (a writing system character). Both &amp;lt;tt&amp;gt;str&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;unicode&amp;lt;/tt&amp;gt; objects can be mixed and matched together (e.g. concatenated using the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; operator).&lt;br /&gt;
&lt;br /&gt;
In Python 3, the &#039;&#039;&#039;&amp;lt;tt&amp;gt;str&amp;lt;/tt&amp;gt;&#039;&#039;&#039; type holds Unicode characters, and for binary data a new &#039;&#039;&#039;&amp;lt;tt&amp;gt;bytes&amp;lt;/tt&amp;gt;&#039;&#039;&#039; type was added. This type was also added to Python 2.7 to simplify porting to Python 3, but in Python 2.7 &amp;lt;tt&amp;gt;bytes&amp;lt;/tt&amp;gt; is simply an alias for &amp;lt;tt&amp;gt;str&amp;lt;/tt&amp;gt;. The &amp;lt;tt&amp;gt;str&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;bytes&amp;lt;/tt&amp;gt; types are incompatible, and an attempt to use both together will result in a &amp;lt;tt&amp;gt;TypeError&amp;lt;/tt&amp;gt; exception. A &amp;lt;tt&amp;gt;bytes&amp;lt;/tt&amp;gt; object can be converted to a &amp;lt;tt&amp;gt;str&amp;lt;/tt&amp;gt; using the &amp;lt;code&amp;gt;.decode()&amp;lt;/code&amp;gt; method, and conversely a &amp;lt;tt&amp;gt;str&amp;lt;/tt&amp;gt; object is converted to &amp;lt;tt&amp;gt;bytes&amp;lt;/tt&amp;gt; using the &amp;lt;code&amp;gt;.encode()&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
=== Absolute Import ===&lt;br /&gt;
Python 3 uses so called “absolute import” and you can no longer import neighbor modules from inside a package using only a module name. You need to either to use either a fully qualified name or a “dotted” notation.&lt;br /&gt;
&lt;br /&gt;
Let’s assume that you have a &amp;lt;code&amp;gt;foo&amp;lt;/code&amp;gt; package that contains &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spam&amp;lt;/code&amp;gt; modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
foo/&lt;br /&gt;
  __init__.py&lt;br /&gt;
  bar.py&lt;br /&gt;
  spam.py    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And you need to import &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; module from &amp;lt;code&amp;gt;spam&amp;lt;/code&amp;gt;. In Python 2 you can do:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import bar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But in Python 3 you need to use either&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import foo.bar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from . import bar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Floating Point Division ===&lt;br /&gt;
In Python 2 applying division operator to int numbers produces int result. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 4 / 3&lt;br /&gt;
1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python 3 division operator always gives you a float result.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 4/3&lt;br /&gt;
1.3333333333333333&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get an int result you need to use integer division operator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 4 // 3&lt;br /&gt;
1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Print Function ===&lt;br /&gt;
In Python 3 print statement has been replaced with print() function. This is not very relevant to Kodi because using print in Python addons is discouraged and xbmc.log() function should be used to write messages to the Kodi log.&lt;br /&gt;
&lt;br /&gt;
=== Default Iterators ===&lt;br /&gt;
In Python 3 most function and methods that produce sequences return iterators instead of lists. For example, range() function and .items(), .keys(), .values() of dict type produce iterators instead of lists, and their Python 2 analogues — xrange() function and .iter* methods of dict type — have been removed.&lt;br /&gt;
&lt;br /&gt;
=== No long Integers ===&lt;br /&gt;
In Python 3 long integer type has been removed and int type can now hold a number of arbitrary length.&lt;br /&gt;
&lt;br /&gt;
Those are only some of the differences between Python 2 and 3. For a more complete list see [https://docs.python.org/3.6/whatsnew/3.0.html official Python documentation].&lt;br /&gt;
&lt;br /&gt;
== Some Useful Information ==&lt;br /&gt;
As it was said above, Python 3 includes a number of incompatible changes, so to avoid situation when after upgrading Kodi for Python 3 support most Python addons will be broken developers should start to port their addons to be compatible with both Python 2 and 3. This is not a trivial task but fortunately there are a number of tools and recommendations to simplify this process. Here I’ll give you some advice and information about tools that will simplify creating portable code that runs on both Python 2 and 3.&lt;br /&gt;
&lt;br /&gt;
=== Know Your Strings! ===&lt;br /&gt;
This is the most problematic part of porting Python 2 code to Python 3 so I put it first. One of the most notable differences between Python 2 and 3 is clear separation between “textual” and “binary” strings, that is, between textual data and their binary representation. This difference is often difficult to understand, especially for novice developers (not only in Python), and the fact that in Python 2 you can mix together str (binary data) and unicode (textual data) adds to that difficulty.&lt;br /&gt;
&lt;br /&gt;
There are many explanations in the Internet, but here are the most basic things about strings that you need to know:&lt;br /&gt;
&lt;br /&gt;
“Textual” or Unicode strings (unicode in Python 2 and str in Python 3) hold text as a sequence of characters. A minimal unit in such strings is a Unicode character — an abstract entity that represent an alphabet symbol, a punctuation sign or other symbol included in the Unicode character table. Of course, such symbols have concrete internal binary representation (a computer is a binary machine after all), but this representation is not relevant to us. All you need to know is that “textual” strings contain text units without being tied to concrete binary representation.&lt;br /&gt;
&lt;br /&gt;
Unlike Unicode strings, binary strings (str in Python 2 and bytes in both Python 2 and 3) hold binary data, and a minimal unit of such strings is a byte or 8 bits. Historically, in Python 2 such strings are used for textual data encoded in ASCII or other 1-byte fixed-length encoding (e.g. Windows 1251 for Cyrillic alphabets). However, this approach has its limitation, that is why unicode type was introduced in Python 2, and in Python 3 it was renamed to str and made a default container for textual data.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, Python 2 allows to mix and match Unicode and binary strings in the same context and this creates big problems when porting Python 2 code to Python 3. So in order to successfully port your code to Python 3 you need to carefully consider how textual data are processed in your addon. The following recommendations will help you avoid problems when writing Python 2/3 compatible code.&lt;br /&gt;
&lt;br /&gt;
=== Avoid using binary strings for text ===&lt;br /&gt;
Store all your text as Unicode strings. This means that all binary strings received from external sources (textual files, websites, various APIs) need to be decoded using appropriate encoding (UTF-8 in most cases). If you need to use strings literals (although using hardcoded strings for user-facing text in Kodi is strongly discouraged), they need to be defined as unicode strings as well. You can use either&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from __future__ import unicode_literals&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
at the beginning of your modules to enable unicode strings by default as in Python 3 or u-strings, e.g. &amp;lt;code&amp;gt;u&#039;foo&#039;&amp;lt;/code&amp;gt; (Python 3 understands them too) — it doesn&#039;t really matter as long as you are doing it consistently.&lt;br /&gt;
&lt;br /&gt;
=== Know the libraries you are using ===&lt;br /&gt;
Working with Python Standard Library and third-party libraries (including Kodi Python API) you should know that types their functions and methods expect and what types they return. For example, in popular requests library Response.text property returns a Unicode string and Response.content returns a binary string.&lt;br /&gt;
&lt;br /&gt;
If a function/method/property returns a binary string, you need to decode it to a Unicode string using .decode() method. Don’t use unicode class constructor because unicode type does not exist in Python 3.&lt;br /&gt;
&lt;br /&gt;
If you are reading textual files from disk, it is better to use io.open() instead of built-in open(). io.open() can decode file contents to Unicode using specified encoding and works identically both in Python 2 and 3. Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import io&lt;br /&gt;
&lt;br /&gt;
with io.open(&#039;foo.txt&#039;, &#039;r&#039;, encoding=&#039;utf-8&#039;) as fo:&lt;br /&gt;
   text = fo.read()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Potential pitfalls ===&lt;br /&gt;
When writing Python 3-compatible code or converting existing Python 2 codebase to compatible code you should pay attention to the following Python language constructions where TypeError exceptions may happen because of incompatible string types if you don’t get your strings in order:&lt;br /&gt;
&lt;br /&gt;
* String concatenations with + operator (&amp;lt;code&amp;gt;&#039;foo&#039; + &#039;bar&#039;&amp;lt;/code&amp;gt;).&lt;br /&gt;
* String formatting — both “old style” (&amp;lt;code&amp;gt;&#039;foo %s&#039; % &#039;bar&#039;&amp;lt;/code&amp;gt;) and “new style” (&amp;lt;code&amp;gt;&#039;foo {}&#039;.format(&#039;bar&#039;)&amp;lt;/code&amp;gt;).&lt;br /&gt;
* String joining (&amp;lt;code&amp;gt;&#039;, &#039;.join([&#039;foo&#039;, &#039;bar&#039;])&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In all those cases always make sure that you work with Unicode strings only.&lt;br /&gt;
Another source of subtle bugs is functions and methods that accept and return binary strings (str type) in Python 2  but Unicode strings in Python 3 (again, str type but with different properties). You can use the following utility functions to “normalize” strings that are provided to such functions/methods and received from them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
__all__ = [&#039;PY2&#039;, &#039;py2_encode&#039;, &#039;py2_decode&#039;]&lt;br /&gt;
&lt;br /&gt;
PY2 = sys.version_info[0] == 2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def py2_encode(s, encoding=&#039;utf-8&#039;):&lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
   Encode Python 2 ``unicode`` to ``str``&lt;br /&gt;
&lt;br /&gt;
   In Python 3 the string is not changed.   &lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
   if PY2 and isinstance(s, unicode):&lt;br /&gt;
       s = s.encode(encoding)&lt;br /&gt;
   return s&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def py2_decode(s, encoding=&#039;utf-8&#039;):&lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
   Decode Python 2 ``str`` to ``unicode``&lt;br /&gt;
&lt;br /&gt;
   In Python 3 the string is not changed.&lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
   if PY2 and isinstance(s, str):&lt;br /&gt;
       s = s.decode(encoding)&lt;br /&gt;
   return s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Those utility functions are included in Kodi Six library that is described in the following section.&lt;br /&gt;
&lt;br /&gt;
== Helper Libraries and Tools ==&lt;br /&gt;
=== 2to3 ===&lt;br /&gt;
[https://docs.python.org/2/library/2to3.html 2to3] script is created by Python developers to help converting existing Python 2 code to Python 3. On Windows it is included in Python distribution (Tools subfolder) but on other OSes you man need to install it separately. For example, on Ubuntu it is included in python-examples package. Note that this script is created for conversion from Python 2 to 3, not for writing portable code, so you need to treat its output with care.&lt;br /&gt;
&lt;br /&gt;
=== Modernize ===&lt;br /&gt;
https://python-modernize.readthedocs.io/en/latest/ Modernize] script works on top of 2to3 and is supposed to help you to convert your existing Python 2 code to Python 2/3-compatible. However, in my experiments it did not work reliably even in simple cases so I cannot recommend it for usage.&lt;br /&gt;
&lt;br /&gt;
=== Six ===&lt;br /&gt;
[https://pythonhosted.org/six/ Six] was the first library developed to simplify Python 2 to 3 migration. It provides a set of wrappers that hide differences between Python 2 and 3 behind its API. It is less intrusive than the following alternative because it does not monkey-patch built-in names, but in order to use Six library effectively you need to learn its API. Six can be used both for writing new Python 2/3-compatible addons and converting existing ones, but it requires good knowledge of Python 2/3 differences to pick necessary Six features that address specific differences.&lt;br /&gt;
&lt;br /&gt;
Six library is included in the Kodi addon repository as &#039;&#039;&#039;script.module.six&#039;&#039;&#039; addon.&lt;br /&gt;
&lt;br /&gt;
=== Future ===&lt;br /&gt;
[http://python-future.org/ Future] library, like Six, was created to simplify porting existing Python 2 code to 3. But it uses a different approach than Six. Future monkey-patches built-in Python objects to make Python 2 behave like Python 3. The advantage of such approach is that code written using Future is close to idiomatic Python 3 and requires little re-work if you decide to drop Python 2 support in the future. However, such approach may cause problems in some rare edge-cases.&lt;br /&gt;
&lt;br /&gt;
Future library also includes &amp;lt;code&amp;gt;futurize&amp;lt;/code&amp;gt; command-line utility for converting existing Python 2 code to 2/3-compatible and in my experiments this utility showed good results.&lt;br /&gt;
Future library (without additional utilities) is included in the Kodi addon repository as script.module.future addon.&lt;br /&gt;
&lt;br /&gt;
=== Kodi Six ===&lt;br /&gt;
[https://github.com/romanvm/kodi.six Kodi Six] library (available as &#039;&#039;&#039;script.module.kodi-six&#039;&#039;&#039; addon) is created to normalize string handling in Kodi Python API based on different Python versions by applying wrappers around Kodi API functions and classes. In Kodi API based on Python 2 Kodi Six wrappers have the following effects:&lt;br /&gt;
&lt;br /&gt;
* All functions and methods that expect string arguments can accept both UTF-8 encoded &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt; objects and &amp;lt;code&amp;gt;unicode&amp;lt;/code&amp;gt; objects.&lt;br /&gt;
* All functions and methods that return string data return &amp;lt;code&amp;gt;unicode&amp;lt;/code&amp;gt; objects.&lt;br /&gt;
&lt;br /&gt;
In Kodi API based on Python 3 the wrappers have no effect because Python 3-based API works only with &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt; (Unicode) objects. This eliminates the need for ad hoc encoding and decoding string when working with Kodi API. To use the wrappers you need to import Kodi API &amp;lt;code&amp;gt;xbmc*&amp;lt;/code&amp;gt; modules from Kodi Six instead of importing them directly:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from kodi_six import xbmc, xbmcaddon, xbmcgui, xbmcplugin, xbmcvfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PyCharm ===&lt;br /&gt;
PyCharm, except for being a really good Python IDE, also provides code compatibility inspection that helps you write Python 2/3-portable code. Open &#039;&#039;&#039;Settings&#039;&#039;&#039; (Alt+F7) &amp;gt; &#039;&#039;&#039;Editor&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Inspections&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Python&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Code compatibility inspections&#039;&#039;&#039; and check Python version that you want to support.&lt;br /&gt;
&lt;br /&gt;
PyCharm Community Edition is free and provides all features you need for creating Python addons for Kodi.&lt;br /&gt;
&lt;br /&gt;
== Writing Portable Code ==&lt;br /&gt;
Here I’ll give you some tips about how to write portable code:&lt;br /&gt;
&lt;br /&gt;
* Learn the differences between Python 2 and 3. You need to know at least the most important differences between the two major Python versions.&lt;br /&gt;
* Use version control system — git or mercurial — to track changes in your code. If you are porting existing code, do it in a separate branch.&lt;br /&gt;
* No matter if you are going to write a brand new addon or to port existing addon to Python 3, carefully choose your tools. It is totally possible to write portable code without any helper tools and libraries, but you need to know what you are doing. However, in most cases I’d recommend you to use Future library and its utilities. Carefully read Future documentation.&lt;br /&gt;
* Put the following line at the beginning of all your modules:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from __future__ import absolute_import, division, unicode_literals&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This will enable respective Python 3 features in your code. You don’t need to import print_function (another Python 3 feature) because in Kodi addons you should to use xbmc.log() to write messages to the Kodi log file.&lt;br /&gt;
&lt;br /&gt;
=== Writing New Addons ===&lt;br /&gt;
Check the [http://python-future.org/quickstart.html#if-you-are-writing-code-from-scratch Quick Start Guide] section of Future library documentation. You can also use Six library, but, as it was said previously, you need to learn its API to pick the necessary features to address specific Python version differences, while Future allows to write your code in (almost) idiomatic Python 3.&lt;br /&gt;
&lt;br /&gt;
A brief procedure for writing new Python 2/3-compatible addons with Future library:&lt;br /&gt;
&lt;br /&gt;
# Create a new virtual environment with Python 3 interpreter and activate it.&lt;br /&gt;
# Install Future library: &amp;lt;code&amp;gt;pip install future&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Point your IDE (Integrated Development Environment) to that environment. For example, in PyCharm: &#039;&#039;&#039;File&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Setting&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Project&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Project Interpreter&#039;&#039;&#039;.&lt;br /&gt;
# Put the following line at the beginning of your Python code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from __future__ import absolute_import, division, unicode_literals&lt;br /&gt;
from future import standard_library&lt;br /&gt;
from future.builtins import *&lt;br /&gt;
standard_library.install_aliases()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Write your addon using Python 3 syntax and standard library names. However, you may still need to use wrappers from Future library for some specific cases (e.g. iterators over &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt; elements). Read Future docs for more info.&lt;br /&gt;
&lt;br /&gt;
=== Porting Existing Addons ===&lt;br /&gt;
A brief procedure for porting existing code to Python 3-compatible with Future library:&lt;br /&gt;
# Install Future library into your working Python 2 virtual environment: &amp;lt;code&amp;gt;pip install future&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Run &amp;lt;code&amp;gt;futurize&amp;lt;/code&amp;gt; utility to convert all your scripts and modules to portable code.&lt;br /&gt;
&lt;br /&gt;
Test your new or converted addon in Kodi with Python 2 interpreter and fix all found issues. After that test the addon in Kodi with Python 3 interpreter and again fix all found issues.&lt;br /&gt;
You can use [https://github.com/romanvm/kodi.web-pdb Web-PDB] debugger for troubleshooting issues in your code. It is compatible with both Python 2 and 3.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* Python 2 and 3 differences: https://docs.python.org/3.6/whatsnew/3.0.html&lt;br /&gt;
* Future library documentation: http://python-future.org/&lt;br /&gt;
* Six library documentation: https://pythonhosted.org/six/&lt;br /&gt;
* Kodi test builds with Python 3 for Windows: http://mirrors.xbmc.org/test-builds/windows/win32/&lt;br /&gt;
* Kodi test builds with Python 3 for Linux Ubuntu: https://launchpad.net/~wsnipex/+archive/ubuntu/kodi-python3/+packages&lt;br /&gt;
* “Python 3 migration” section on the Kodi official forum: https://forum.kodi.tv/forumdisplay.php?fid=281&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Fourpointsix</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Migration_to_Python_3&amp;diff=253239</id>
		<title>Migration to Python 3</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Migration_to_Python_3&amp;diff=253239"/>
		<updated>2024-08-02T20:44:39Z</updated>

		<summary type="html">&lt;p&gt;Fourpointsix: Updated to reflect sunsetting of Python 2&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;After a successful GSOC 2017 project that brought Python 3 (3.6 exactly) to Kodi it was decided that Kodi 19.x Matrix would switch to Python 3 as an environment for running Python addons. Enough time has now passed that the last Python 2 release, Leia, has aged out of support. Therefore, all addon contributions must be Python 3-compatible.&lt;br /&gt;
&lt;br /&gt;
Since Python 3 is not backward compatible with 2.x versions, developers of older addons must convert their addons to be Python 3-compatible so that their addons will continue to run on current and future Kodi versions. This page contains information that should help addon developers in this conversion process.&lt;br /&gt;
&lt;br /&gt;
* [[General information about migration to Python 3]]&lt;br /&gt;
* [https://forum.kodi.tv/forumdisplay.php?fid=281 Python 3 migration section on the Kodi forum]&lt;br /&gt;
* [https://kodi.tv/article/the-sun-sets-on-python-2/ The Sun Sets on Python 2]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Fourpointsix</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Submitting_Add-ons&amp;diff=253238</id>
		<title>Submitting Add-ons</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Submitting_Add-ons&amp;diff=253238"/>
		<updated>2024-08-02T20:31:07Z</updated>

		<summary type="html">&lt;p&gt;Fourpointsix: Added Omega and Piers, removed update support for Leia and older. Unsure of skin repo requirements, so left those for others to update.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{mininav|[[Development]]|[[Add-on development]]}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Submitting a Compliant Add-on to the Kodi.tv Repo ===&lt;br /&gt;
&lt;br /&gt;
After you have read the [[Add-on rules|repository guidelines]] and made sure your addon is compliant with them, you may begin the submission process using the following steps.&lt;br /&gt;
&lt;br /&gt;
=== Allowed submissions ===&lt;br /&gt;
&lt;br /&gt;
We have restricted the allowed submissions of add-ons to past Kodi versions.&lt;br /&gt;
Several reasons:&lt;br /&gt;
* Kodi code improvements&lt;br /&gt;
* Reduce support load for add-on developers&lt;br /&gt;
* Reduce workload for repository maintainers&lt;br /&gt;
&lt;br /&gt;
Below is a table of on which submissions are allowed to official Kodi repository.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+ Allowed add-on submissions&lt;br /&gt;
! codename !! version !! update !! new&lt;br /&gt;
|-&lt;br /&gt;
| Dharma || 10.x || no || no&lt;br /&gt;
|-&lt;br /&gt;
| Eden || 11.x || no || no&lt;br /&gt;
|-&lt;br /&gt;
| Frodo || 12.x || no || no&lt;br /&gt;
|-&lt;br /&gt;
| Gotham || 13.x || no || no&lt;br /&gt;
|-&lt;br /&gt;
| Helix || 14.x || no || no&lt;br /&gt;
|-&lt;br /&gt;
| Isengard || 15.x || no || no&lt;br /&gt;
|-&lt;br /&gt;
| Jarvis || 16.x || no || no&lt;br /&gt;
|-&lt;br /&gt;
| Krypton || 17.x || no || no&lt;br /&gt;
|-&lt;br /&gt;
| Leia || 18.x || no || no&lt;br /&gt;
|-&lt;br /&gt;
| Matrix || 19.x || yes || yes&lt;br /&gt;
|-&lt;br /&gt;
| Nexus || 20.x || yes || yes&lt;br /&gt;
|-&lt;br /&gt;
| Omega || 21.x || yes || yes&lt;br /&gt;
|-&lt;br /&gt;
| Piers || 22.x || yes || yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An additional feature is that we use combined repositories. So if your add-on is Matrix/Nexus/Omega compatible, you only need to send it to the Matrix repository.&lt;br /&gt;
If it&#039;s only Omega+ compatible you need to send it to the Omega repository.&lt;br /&gt;
This of course requires that the minimal Kodi dependencies are set accordingly.&lt;br /&gt;
&lt;br /&gt;
Note that as of [https://kodi.tv/article/the-sun-sets-on-python-2/ April 2024], only Python 3 add-ons are accepted since the last Python 2 release, Leia, is out of support. Contributions to the Leia and older repositories will no longer be accepted.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+ Which repos are used for Python add-ons (scripts, scrapers and plugins)&lt;br /&gt;
! codename !! version !! repos !!colspan=&amp;quot;9&amp;quot;| repo&lt;br /&gt;
|-&lt;br /&gt;
| Dharma || 10.x || Dharma&lt;br /&gt;
|-&lt;br /&gt;
| Eden || 11.x || Eden&lt;br /&gt;
|-&lt;br /&gt;
| Frodo || 12.x || Frodo&lt;br /&gt;
|-&lt;br /&gt;
| Gotham || 13.x || Gotham&lt;br /&gt;
|-&lt;br /&gt;
| Helix || 14.x || Gotham || Helix&lt;br /&gt;
|-&lt;br /&gt;
| Isengard || 15.x || Gotham || Helix || Isengard&lt;br /&gt;
|-&lt;br /&gt;
| Jarvis || 16.x || Gotham || Helix || Isengard  || Jarvis&lt;br /&gt;
|-&lt;br /&gt;
| Krypton || 17.x || Gotham || Helix || Isengard  || Jarvis  || Krypton&lt;br /&gt;
|-&lt;br /&gt;
| Leia || 18.x || Gotham || Helix || Isengard  || Jarvis  || Krypton || Leia&lt;br /&gt;
|- &lt;br /&gt;
| Matrix|| 19.x || - || - || - || - || - || - || Matrix&lt;br /&gt;
|- &lt;br /&gt;
| Nexus|| 20.x || - || - || - || - || - || - || Matrix || Nexus&lt;br /&gt;
|- &lt;br /&gt;
| Omega|| 21.x || - || - || - || - || - || - || Matrix || Nexus || Omega&lt;br /&gt;
|- &lt;br /&gt;
| Piers|| 22.x || - || - || - || - || - || - || Matrix || Nexus || Omega || Piers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+ Which repos are used for skins&lt;br /&gt;
! codename !! version !! repos !!colspan=&amp;quot;8&amp;quot;| repo&lt;br /&gt;
|-&lt;br /&gt;
| Dharma || 10.x || Dharma&lt;br /&gt;
|-&lt;br /&gt;
| Eden || 11.x || Eden&lt;br /&gt;
|-&lt;br /&gt;
| Frodo || 12.x || Frodo&lt;br /&gt;
|-&lt;br /&gt;
| Gotham || 13.x || Gotham&lt;br /&gt;
|-&lt;br /&gt;
| Helix || 14.x || Gotham || Helix&lt;br /&gt;
|-&lt;br /&gt;
| Isengard || 15.x || || || Isengard&lt;br /&gt;
|-&lt;br /&gt;
| Jarvis || 16.x || || || || Jarvis&lt;br /&gt;
|-&lt;br /&gt;
| Krypton || 17.x || || || || || Krypton&lt;br /&gt;
|-&lt;br /&gt;
| Leia || 18.x || ||  || || || || Leia&lt;br /&gt;
|- &lt;br /&gt;
| Matrix|| 19.x || || || || || || || Matrix&lt;br /&gt;
|- &lt;br /&gt;
| Nexus|| 20.x || || || || || || || Matrix || Nexus&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+ Which repos are used for other add-ons&lt;br /&gt;
! codename !! version !! repos !!colspan=&amp;quot;9&amp;quot;| repo&lt;br /&gt;
|-&lt;br /&gt;
| Dharma || 10.x || Dharma&lt;br /&gt;
|-&lt;br /&gt;
| Eden || 11.x || Eden&lt;br /&gt;
|-&lt;br /&gt;
| Frodo || 12.x || Frodo&lt;br /&gt;
|-&lt;br /&gt;
| Gotham || 13.x || Gotham&lt;br /&gt;
|-&lt;br /&gt;
| Helix || 14.x || Gotham || Helix&lt;br /&gt;
|-&lt;br /&gt;
| Isengard || 15.x || Gotham || Helix || Isengard&lt;br /&gt;
|-&lt;br /&gt;
| Jarvis || 16.x || Gotham || Helix || Isengard  || Jarvis&lt;br /&gt;
|-&lt;br /&gt;
| Krypton || 17.x || Gotham || Helix || Isengard  || Jarvis  || Krypton&lt;br /&gt;
|-&lt;br /&gt;
| Leia || 18.x || Gotham || Helix || Isengard  || Jarvis  || Krypton || Leia&lt;br /&gt;
|- &lt;br /&gt;
| Matrix || 19.x || Gotham || Helix || Isengard  || Jarvis  || Krypton || Leia || Matrix&lt;br /&gt;
|- &lt;br /&gt;
| Nexus || 20.x || Gotham || Helix || Isengard  || Jarvis  || Krypton || Leia || Matrix || Nexus&lt;br /&gt;
|- &lt;br /&gt;
| Omega || 21.x || Gotham || Helix || Isengard  || Jarvis  || Krypton || Leia || Matrix || Nexus || Omega&lt;br /&gt;
|- &lt;br /&gt;
| Piers || 22.x || Gotham || Helix || Isengard  || Jarvis  || Krypton || Leia || Matrix || Nexus || Omega || Piers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{{see also|Addon.xml#Dependency_versions}}&lt;br /&gt;
&lt;br /&gt;
=== Github ===&lt;br /&gt;
&lt;br /&gt;
==== Pull requests ====&lt;br /&gt;
New add-ons or updates may be submitted directly to the [[Official add-on repository]] on Github as pull requests. We are aware that this requires some initial git knowledge and we strongly suggest to read up on this subject before submitting a pull request. &lt;br /&gt;
&lt;br /&gt;
To reduce size we have split up the git repositories in several locations. Please visit [[Official add-on repository]] to see where they are. Each contains a small readme with a short description of it&#039;s contents as well as a link to a short explanation on how to submit using git command line. There are also git tools available that have a graphic interface and the steps above should be done in a similar way. Please consult the manual of those programs.&lt;br /&gt;
&lt;br /&gt;
In addition to the [[Add-on rules|repository guidelines]] the following rules apply when submitting PRs on Github:&lt;br /&gt;
&lt;br /&gt;
* PR should contain one commit only.&lt;br /&gt;
* Commit message should have the format &amp;quot;[addonid] version&amp;quot;. Example: &amp;quot;[my.cool.addon] 1.0.1&amp;quot; &lt;br /&gt;
&lt;br /&gt;
If Team Kodi reviewers asked you to make some changes in your PR, follow this procedure: [[HOW-TO: Update a pull request to an official addon repository on GitHub]].&lt;br /&gt;
&lt;br /&gt;
Only PRs from the add-on author or his successor will be accepted. Patches should be submitted upstream to the original author first. For an easy way to create PR from your own git repository, see [[HOW-TO: create add-on PRs using Git Subtree Merging]].&lt;br /&gt;
&lt;br /&gt;
==== Issue ticket ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This route is only available for skins in https://github.com/xbmc/repo-skins.&lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For skins submissions you may also use the &amp;quot;issue&amp;quot; option where you submit a request to get you add-on added. In this ticket you need to provide the basic information needed so our repo maintainers know where to get the correct version. &lt;br /&gt;
This consists of &lt;br /&gt;
  - Add-on name: &lt;br /&gt;
  - Add-on ID:&lt;br /&gt;
  - Version number:&lt;br /&gt;
  - Kodi/repository version:&lt;br /&gt;
  - Code location URL:&lt;br /&gt;
  - Revision/tag: &lt;br /&gt;
  - Branch:&lt;br /&gt;
&lt;br /&gt;
Further information is provide when you initially create the issue on github as comments in the ticket.&lt;br /&gt;
Same [[Add-on rules|repository guidelines]] apply here as well.&lt;br /&gt;
&lt;br /&gt;
==== How to submit your add-on and subsequent updates ====&lt;br /&gt;
Submitting updates is done the same way as with pull requests or issue ticket.&lt;br /&gt;
&lt;br /&gt;
==== Repository lists ====&lt;br /&gt;
You can create pull requests or tickets on the following individual repositories.&lt;br /&gt;
&lt;br /&gt;
  https://github.com/xbmc/repo-plugins&lt;br /&gt;
  https://github.com/xbmc/repo-resources&lt;br /&gt;
  https://github.com/xbmc/repo-scrapers&lt;br /&gt;
  https://github.com/xbmc/repo-scripts&lt;br /&gt;
  https://github.com/xbmc/repo-skins&lt;br /&gt;
  https://github.com/xbmc/repo-webinterfaces&lt;br /&gt;
&lt;br /&gt;
=== Additional information ===&lt;br /&gt;
Note that skin .xbt files will be generated automatically for skins so you do not include this in your pull request or created tickets. &lt;br /&gt;
After the add-on has been added or updated it will be available from the Kodi repository in Kodi itself, on http://addons.kodi.tv/ and on the wiki page http://kodi.wiki/index.php?title=Category:All_add-ons.&lt;br /&gt;
&lt;br /&gt;
{{Note|Please locate you add-on in the root of the git repository. This to make sure we can easily pull the add-on into our repository.&lt;br /&gt;
Example: https://github.com/XBMC-Addons/service.xbmc.versioncheck}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{tip|We automatically combine all repos into one single repo list on our server and provide that list to Kodi. You only need to do a request for the minimum repo your add-on supports.}}&lt;br /&gt;
&lt;br /&gt;
=== The mailing list ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; MAILINGLIST IS NOT USED ANYMORE. ALL REQUESTS SHOULD GO THROUGH GITHUB &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-on development]]&lt;/div&gt;</summary>
		<author><name>Fourpointsix</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Talk:Add-on_rules&amp;diff=253237</id>
		<title>Talk:Add-on rules</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Talk:Add-on_rules&amp;diff=253237"/>
		<updated>2024-08-02T20:09:52Z</updated>

		<summary type="html">&lt;p&gt;Fourpointsix: Added note to remove Python 2&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Page protection rationale ==&lt;br /&gt;
&#039;&#039;&#039;@[[User:Ronie|Ronie]]:&#039;&#039;&#039; Sorry if this comes across as being a bit of a [[wikt:Buttinsky|buttinsky]], but may I ask why you set the protection flag on this page and at such a high level, considering that it exists in the Main namespace and isn&#039;t part of &amp;lt;code&amp;gt;Official:&amp;lt;/code&amp;gt; or some other more exclusive taxonomy? Honestly I&#039;m also rather confused at why you reverted [https://kodi.wiki/index.php?title=Add-on_rules&amp;amp;oldid=235813 the edit] by [[User:Te36|Te36]], which was well-sourced and informative, at least to me (though I do take vehement exception to said policy as a matter of principle), seeing as I wasn&#039;t aware that anything like it was so explicitly in effect until he brought it to light. I don&#039;t mean to be sharpshooting you here, I just think that we&#039;d all benefit from there being more of a discussion amongst editors when these instances arise, giving those of us without special powers the opportunity to learn what was being objected to and why, rather than just letting yet another wiki page stagnate as a result of hardly anyone being able to edit it and keep it reflective of changes in the status quo. That&#039;s why these Talk pages exist, right? Just my two cents... —[[User:RogueScholar|RogueScholar]] ([[User talk:RogueScholar|talk]]) 10:26, 17 October 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hello @[[User:RogueScholar|RogueScholar]], let me respond to your points&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. The edit by [[User:Te36|Te36]] was removed because it was not correct.&lt;br /&gt;
&lt;br /&gt;
* Kodi is not against porn and we simply consider it another genre. And inline with our general ethos, we will not dictate what users can or cannot do with Kodi.&lt;br /&gt;
* [[User:Te36|Te36]] quoted posts from 8 years ago and taken slightly out of context. Refusing to allow a porn scraper into the Official Repository is not the same as &amp;quot;not supporting porn&amp;quot;. If you browse through the forum there are plenty of adult related addons and 3rd party adult scrapers that members can use. If Kodi &amp;quot;does not support porn&amp;quot; (as stated by Te36) then these forum threads certainly would not be allowed on the forum.&amp;lt;br&amp;gt;&lt;br /&gt;
* The reason an adult scraper is not allowed in the official repo, and why existing scrapers do not automatically scrape adult titles, is to prevent younger users from &amp;quot;accidentally&amp;quot; installing the wrong scraper and to prevent a misidentified title from being scraped as an adult title and displayed with some confronting posters and fanart.&lt;br /&gt;
* Contrary to popular belief, Kodi scrapers &#039;&#039;can&#039;&#039; scrape adult content by using a Parsing NFO file. Using a nfo file is something done outside of Kodi (not automatically by Kodi) which shows &amp;quot;intent&amp;quot; rather than &amp;quot;accident&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Why was the Protection Flag set?&amp;lt;br&amp;gt;&lt;br /&gt;
* The flag should have always been set. It was an oversight that it was not set. &lt;br /&gt;
* Rules cannot be modified by the general public. They are rules set by Kodi. Changing rules does not happen on a whim and requires a discussion and voting by the Team.&amp;lt;br&amp;gt;&lt;br /&gt;
3. The Add-on rules are in the Main namespace&lt;br /&gt;
* You raise a valid point. This article is an Official article and should be in the Official namespace. I will move it across.&lt;br /&gt;
* I guess that after 8 years, nobody really gave it any consideration, until now.&lt;br /&gt;
&lt;br /&gt;
Also I have just remembered your PM. Sorry I was ill for a while and forgotten about it since. I&#039;ll respond soon.&lt;br /&gt;
&lt;br /&gt;
== Remove Python 2 reference ==&lt;br /&gt;
To reflect the recent sunset of Python 2, I suggest this change to the Guidelines section:&lt;br /&gt;
&lt;br /&gt;
* All add-ons must be compatible with Python 3. Contributions requiring Python 2 are no longer accepted. For more details see: [https://kodi.tv/article/the-sun-sets-on-python-2/ The Sun Sets on Python 2]&lt;br /&gt;
[[User:Fourpointsix|Fourpointsix]] ([[User talk:Fourpointsix|talk]]) 20:09, 2 August 2024 (UTC)&lt;/div&gt;</summary>
		<author><name>Fourpointsix</name></author>
	</entry>
</feed>