# newbie plugin question regarding python classes

**URL:** <https://forums.plex.tv/t/newbie-plugin-question-regarding-python-classes/98805>\
**Category:** Dev/API Corner\
**Tags:** other-dev\
**Created:** [April 2, 2015, 9:46pm UTC](https://forums.plex.tv/t/newbie-plugin-question-regarding-python-classes/98805 "2015-04-02T21:46:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![agentplex007](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@agentplex007](https://forums.plex.tv/u/agentplex007)\
**Post date:** [April 2, 2015, 9:46pm UTC](https://forums.plex.tv/t/newbie-plugin-question-regarding-python-classes/98805/1 "2015-04-02T21:46:38Z")

</div>

I am trying to debug an agent plugin written by someone else and have some questions.

&nbsp;

The framework documentation says that plugins are not regular python programs, and that "All of the plug-in’s code needs to be contained within functions"

&nbsp;

[https://dev.plexapp.com/docs/](https://dev.plexapp.com/docs/)

&nbsp;

I have written some code for the scanner that I'd like to reuse in the plugin. They are in the form of a class that sits in a different .py file. I tried importing the files in the agent and got some mysterious errors (either import failed or some file descriptor error).

&nbsp;

I'd like to know if:

&nbsp;

1) from \_\_init\_\_.py, I can import code from different .py files. I can't get this to work with either the .py file in the same folder as \_\_init\_\_.py, or in a sub folder. If not, then I guess I have to write everything in one file which is not ideal but not a deal breaker.

&nbsp;

I did find an example of an existing plugin that imported a countrycode.py file, but I can't seem to find the difference between it and my .py file and why my import fails and the other one would work.

&nbsp;

2) is python classes supported (assume I write it in \_\_init\_\_.py)?

&nbsp;

I'd like to write a class that handles communication with a 3rd party entity. The reason for the class is I can keep track of some state information. Say I can initialize it with some credentials, etc, and subsequent method call would use those credentials to construct a query..

&nbsp;

I could do this with pure functions too, but it seems to be less elegant.

&nbsp;

Just wondering what I can and cannot do inside a plugin as the documentation doesn't contain much detail beyond stating functions...

&nbsp;

Thanks!

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![agentplex007](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@agentplex007](https://forums.plex.tv/u/agentplex007)\
**Post date:** [April 8, 2015, 5:59pm UTC](https://forums.plex.tv/t/newbie-plugin-question-regarding-python-classes/98805/2 "2015-04-08T17:59:27Z")

</div>

Figured out the answer. Classes are allowed, as long as they derive from object. So \_\_init\_\_() constructors are OK.

```
class Garage(object):
    def __init__ (self, car, level):
        pass
```

It's just that class/function variables can't begin with \_. Certain python operators such as 'open' is also not available, but that can be worked around.

---

<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:** [January 8, 2020, 7:48pm UTC](https://forums.plex.tv/t/newbie-plugin-question-regarding-python-classes/98805/3 "2020-01-08T19:48:14Z")

</div>


