# SQL in a Plex windows plug-in

**URL:** <https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [January 12, 2013, 7:15pm UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980 "2013-01-12T19:15:03Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mstinaff](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mstinaff/32/3316_2.png) [@mstinaff](https://forums.plex.tv/u/mstinaff)\
**Post date:** [January 12, 2013, 7:15pm UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/1 "2013-01-12T19:15:03Z")

</div>

I am interested in porting the [Game Launcher Revised plug-in](http://forums.plexapp.com/index.php/topic/36540-game-launcher-revised) to windows ( or eventually generalizing it for cross platform use.) However it depends on sql (specifically sqlite3) which is [only available to MacOS plex installs](http://forums.plexapp.com/index.php/topic/40530-bug-windows-pms-python-lacks-sqlite/). I found this post about adding [3rd party Python Modules](http://forums.plexapp.com/index.php/topic/47441-3rd-party-python-modules/) but I must admit I am still a little in the dark. Before I dive deeper into any one path I am hoping someone might be able to help me with a few questions:

1. Is there any sort of SQL functionality available to plugins through the current Plug-in framework included with Plex?  
2. If I understand correctly, Plex uses some SQL solution to store the media database. Is this consistent across platforms?   
  
2a. Is there a way to leverage this?  
3. Barring any sort of consistent cross platform Plex approved SQL for plug-ins, what needs to go into the plug-in’s shared folder to add something like sqlite3? Every search I do for installing the module is either a reference to apt-get or a windows executable, neither of which really help me with weaving the module into Plex.  
  
  
  
Thank you so much for your time and to everyone who has helped make Plex so great.

---

<div class="post-metadata">

**Author:** ![El\_Massman](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/el_massman/32/75_2.png) [@El\_Massman](https://forums.plex.tv/u/El_Massman)\
**Post date:** [January 12, 2013, 10:54pm UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/2 "2013-01-12T22:54:29Z")

</div>

> [@](#):
>
> I am interested in porting the [Game Launcher Revised plug-in](http://forums.plexapp.com/index.php/topic/36540-game-launcher-revised) to windows ( or eventually generalizing it for cross platform use.) However it depends on sql (specifically sqlite3) which is [only available to MacOS plex installs](http://forums.plexapp.com/index.php/topic/40530-bug-windows-pms-python-lacks-sqlite/). I found this post about adding [3rd party Python Modules](http://forums.plexapp.com/index.php/topic/47441-3rd-party-python-modules/) but I must admit I am still a little in the dark. Before I dive deeper into any one path I am hoping someone might be able to help me with a few questions:  
> 1. Is there any sort of SQL functionality available to plugins through the current Plug-in framework included with Plex?  
> 2. If I understand correctly, Plex uses some SQL solution to store the media database. Is this consistent across platforms?   
> 2a. Is there a way to leverage this?  
> 3. Barring any sort of consistent cross platform Plex approved SQL for plug-ins, what needs to go into the plug-in's shared folder to add something like sqlite3? Every search I do for installing the module is either a reference to apt-get or a windows executable, neither of which really help me with weaving the module into Plex.  
>   
> Thank you so much for your time and to everyone who has helped make Plex so great.

  
  
Just want to draw your attention to this...  
  
http://forum.xbmc.org/showthread.php?tid=146711  
  
http://forums.plexapp.com/index.php/topic/56457-integrating-libretro-into-plex/  
  
Now that the source code for PHT is available I imagine this could be integrated and gamelauncher would seem to provide a suitable library for launching roms. (I realise this answers none of your questions, just want to get it on the radar of the Plex community!)

---

<div class="post-metadata">

**Author:** ![Gerk](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/gerk/32/81980_2.png) [@Gerk](https://forums.plex.tv/u/Gerk)\
**Post date:** [January 14, 2013, 1:09pm UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/3 "2013-01-14T13:09:04Z")

</div>

I think it would end up being very challenging to get this to work cross platform. OSX PMS uses OSXes supplied version of python – and version wise that means it can vary depending on which OSX version is being used and not all of them include sqlite3 by default. Also don’t forget that there is a Linux PMS. If you want to get it working for just windows (or have windows use it’s own lib) you’ll have to figure out which python version is being bundled and make sure to include appropriate libs. That also means that whenever they update windows PMS there’s a possibility of the plugin breaking. Good luck with it, but without built-in sqlite3 included I think you’re going to get frustrated trying to keep things running if you can even get it that far.

---

<div class="post-metadata">

**Author:** ![Murderous\_Moppet](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Murderous\_Moppet](https://forums.plex.tv/u/Murderous_Moppet)\
**Post date:** [January 18, 2013, 4:41am UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/4 "2013-01-18T04:41:27Z")

</div>

what does the plugin use sqlite for? maybe you can get away with something more basic?

---

<div class="post-metadata">

**Author:** ![mstinaff](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mstinaff/32/3316_2.png) [@mstinaff](https://forums.plex.tv/u/mstinaff)\
**Post date:** [January 19, 2013, 8:58pm UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/5 "2013-01-19T20:58:49Z")

</div>

It uses sqlite for storing all of the metadata it pulls down for the games and also uses lookups of the database to populate the menus when the user selects by platform, genre, release date, publisher etc. So if I understand correctly, very similar usage to how Plex is using its sql database for media metadata storage and organization. Perhaps there is a way to cache it all to local files, but that feels like hammering a nail with a shoe.

---

<div class="post-metadata">

**Author:** ![Gerk](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/gerk/32/81980_2.png) [@Gerk](https://forums.plex.tv/u/Gerk)\
**Post date:** [January 20, 2013, 4:48am UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/6 "2013-01-20T04:48:12Z")

</div>

Yep I’d have to agree that trying to do all of that in flat file of some sort and making it work within the channel does feel like hammering a nail with a shoe. You could try and hack something up for yourself and get it working and go from there, but I dunno if it’s something you’d want to try and upkeep for the long haul. I’d say try getting sqlite working in your windows and if nothing else it can be your own private games channel if it’s too complicated to get it working for the masses.

---

<div class="post-metadata">

**Author:** ![Murderous\_Moppet](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Murderous\_Moppet](https://forums.plex.tv/u/Murderous_Moppet)\
**Post date:** [January 22, 2013, 4:52pm UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/7 "2013-01-22T16:52:39Z")

</div>

it would be nice if the plex framework allowed you to have your own set of tables in the plex db.   
  
  
  
sounds like getting sqlite is your best bet.

---

<div class="post-metadata">

**Author:** ![Moby2kBug](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/moby2kbug/32/5797_2.png) [@Moby2kBug](https://forums.plex.tv/u/Moby2kBug)\
**Post date:** [April 6, 2013, 3:06am UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/8 "2013-04-06T03:06:51Z")

</div>

Since Plex already runs on Python 2.7 for the plugins, it has&nbsp;built in&nbsp;Sqlite 3 support.

But it looks Sqlite 3 is not allowed to be used. This is&nbsp;being&nbsp;accomplished&nbsp;by the use of RestrictedPython.

At least I get following error, if I try to access the module sqlite3 with "import sqlite3":

```
File "/share/MD0_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 345, in __import__
    raise e
ImportError: No module named _sqlite3
```

In sandbox.py I find:

```
from RestrictedPython.Guards import safe_builtins...

# Set up the default builtins
    standard_builtins = dict(safe_builtins)
    standard_builtins[' __import__'] = self. __import__   
```

But how RestrictedPython gets its information about no Sqlite 3 is allowed, I don't quite understand. That thing is really complicated to look at.

So I would also like to know, is that intentional? If so why?

How can I circumvent it for my lone installation here?

Maybe you will allow this with one of the future&nbsp;builds&nbsp;of Plex Media Server?

---

<div class="post-metadata">

**Author:** ![wyatt.mike\_gmail.com](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/wyatt.mike_gmail.com/32/3225_2.png) [@wyatt.mike\_gmail.com](https://forums.plex.tv/u/wyatt.mike_gmail.com)\
**Post date:** [April 6, 2013, 9:30am UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/9 "2013-04-06T09:30:20Z")

</div>

Plex channels have to run on Python 2.5, for osx.

---

<div class="post-metadata">

**Author:** ![Moby2kBug](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/moby2kbug/32/5797_2.png) [@Moby2kBug](https://forums.plex.tv/u/Moby2kBug)\
**Post date:** [April 6, 2013, 11:28am UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/10 "2013-04-06T11:28:58Z")

</div>

Oh, well Plex itself runs with Phyton 2.7 on my QNAP, so this is not the case for all distribution platforms?

Then back to the question:&nbsp;How can I circumvent it for my lone installation here?

Anyone knows how to tell that RestrictedPython to allow the module sqlite3?

---

<div class="post-metadata">

**Author:** ![Gerk](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/gerk/32/81980_2.png) [@Gerk](https://forums.plex.tv/u/Gerk)\
**Post date:** [April 6, 2013, 3:51pm UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/11 "2013-04-06T15:51:12Z")

</div>

For different platforms it's different versions of python. &nbsp;Some are bundled in versions (windows, possibly linux), OSX uses the OSes built-in python.

I \_think\_ that running escalated might allow you to do what you want. &nbsp;In your channels .plist file try to add the following (requires a PMS restart to pick up this change as well):

```
PlexPluginCodePolicy
Elevated
```

---

<div class="post-metadata">

**Author:** ![wyatt.mike\_gmail.com](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/wyatt.mike_gmail.com/32/3225_2.png) [@wyatt.mike\_gmail.com](https://forums.plex.tv/u/wyatt.mike_gmail.com)\
**Post date:** [April 7, 2013, 5:30pm UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/12 "2013-04-07T17:30:21Z")

</div>

They package their own Python on Linux as well it seems.  
  
  
Using elevated code policy is a good suggestion, also I’ve noticed that code under Libraries/Shared is less restricted.

---

<div class="post-metadata">

**Author:** ![navels](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/navels/32/2551_2.png) [@navels](https://forums.plex.tv/u/navels)\
**Post date:** [September 16, 2015, 12:30am UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/13 "2015-09-16T00:30:20Z")

</div>

Bump.

Anyone have any success getting past this error on Windows:

```
ImportError: No module named _sqlite3

```

I have cygwin installed with sqlite3/pysqlite.

Thanks,  
Lee

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 20, 2019, 10:44pm UTC](https://forums.plex.tv/t/sql-in-a-plex-windows-plug-in/26980/14 "2019-12-20T22:44:01Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
