Kodi Community Forum

Full Version: Share data between service and add-on
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!
What is the best way to share data between service and add-on? I have a service that gets some data from the internet, and then i want to display this data in my add-on.
Where to save the file from service, or how is the best way to implement this?
Which service and which add-on?
An addon profile folder .../userdata/addon_data/my.addon/ is usually a recommended place to save all addon-specific data. The path can be retrieved via addon.getAddonInfo('profile') method.

As for data format, pickling is the most natural format for storing Python objects, but you can use any data format you like: JSON, SQLite, CSV and so on.
I've been contemplating on this issue as well.
Not to share between service and addon but when your addon calls itself to list something else.

I've seen some addon use xbmcgui.Window(10000).setProperty() / getProperty()

xbmcswift2 has some sort of storage mechanism that uses files.

there's also "import shelve" from python.

I have only tested the Window(10000) method.
I implemented a solution and posted it some time ago, but not a lot of enthusiasm and not the simplest thing to include.

209171 (thread)
(2016-07-30, 09:18)gedisony Wrote: [ -> ]xbmcswift2 has some sort of storage mechanism that uses files.

there's also "import shelve" from python.

Both of those use pickles "under the hood". BTW, because xbmcswift2 is abandoned and seriously outdated, I have developed my own plugin framework that also includes a dict-like persistent storage based on pickle. As I've said, pickle is the most natural format for storing non-relational Python data, provided that you don't need stored data to be human-readable (although pickles are readable to some degree).