PotionUI Docs v0.3.0

The Plugin API

src.plugin_api is the surface a plugin imports from. It is the only part of the backend a plugin may import.

On this page
python
from src.plugin_api import User, get_current_active_user, generate_ulid

db is the one export to import differently — inside the function that uses it, never at your module's top level:

python
def list_rows():
    from src.plugin_api import db
    with db.get_cursor() as cursor:
        ...

A module-level from src.plugin_api import db copies the database handle into your module's namespace the first time your plugin is imported, and keeps that copy for the life of the process. Anything that later swaps the application's database — a test harness, most commonly — swaps the handle your module is no longer reading. Importing inside the function resolves it fresh on every call.

Everything else under src/ is internal. It is refactored, renamed and moved as the application changes, and none of those changes are announced. A plugin that imports an internal path will keep working right up until it doesn't — and it will fail at load time, in someone else's installation.

55 sections#