Skip to content

SEP 6: Spyder API

Gonzalo Peña-Castellanos edited this page Apr 7, 2015 · 4 revisions
# spyder_widget_example.py


class SpyderWidgetAPI:
    def __init__(self, widget, plugin):
        self.widget = widget
        self.plugin = plugin

    # Stable API available to the public / plugin developers
    def public_api_method_1(self):
        # Calls to private api (only, so no `_`, or `__` methods)
        self.widget.private_api_method_1()

    def public_api_method_2(self):
        # Calls to private api (only, so no `_`, or `__` methods)
        ....

class SpyderWidget:
    def __init__(self, plugin):
        self.api = SpyderWidgetAPI(self, plugin)
        ....

    # Not necessarily stable API available to core developers of Spyder
    def private_api_method_1(self):
        # Calls to private api or more private methods of super private methods
        # A method to be called from anywhere in spyder

    def _private_method_1(self):
        # Calls to private api or private methods of super private methods
        # A method to be called from anywhere within this spyder module

    def __super_private_method_1(self):
        # Calls to private api or private methods of super private methods
        # A method to be called from within this SpyderWidget class only

Which from the internal console would be called something like....

spy.window.editor.api.public_method_1()

This way we can completely decouple internal and public api, and get (at the expense of some extra classes...) a clean (??) separation. We can also implement counters in the public API.

Or even create a module to handle all this api in a single place (call, import) so we could have.

from spyder.api import variabe_explorer

variabe_explorer.public_api_method_1()
...

Where spyder.api module would import all the available api's in spyder

Clone this wiki locally