Skip to main content

Read the Docs PyPI Downloads GitHub Sponsors

Open Plugin Loader

An MIT LICENSE library made to make packaging and loading of plugins easy for projects.

OPL is not going to help you make your plugin api itself, but it will make your experience loading plugins much easier. It also will make the experience of your users significantly easier as well by standardizing plugin packaging. Multiple of your projects can use the same plugin packaging strategy and thus users will not be required to relearn anything for each of your projects.

Features

  • Packaging plugins into an archive (targz) with their pypi dependencies pre-packaged
  • Plugin sorting/dependency sorting. Ensures that plugins will be loaded in the correct order.
  • Plugin import hook to allow plugins to depend on each other.
  • Customization of plugin loading- choose to load them via dynamic import (default) or use a custom loading strategy (for example, a custom, sandboxed environment).
  • Plugin api versioning. Ensure plugins follow versioning standards
  • Plugin Manager using the strategy pattern. Change any individual component to suite your needs.

Features Not Provided

  • Sandboxed loading strategy. Sandbox security is not our expertise. I would rather we provide only what we can reasonable ensure the quality of.

Planned Features

  • Plugin Signing

Getting Started: Making a Plugin (Default Strategy):

Making a plugin is fairly simple. A plugin has a few basic parts:

  • A pyproject.toml (optional)
  • A plugin.toml
  • A plugin entry point (default __init__.py, can be modified in your plugin.toml)

pyproject.toml configuration options

All configuration options are listed below.

# Your full pyproject
# ...
[tool.plugin]
includes = ["mypy"] # package includes. A list of strings. ONLY USE PACKAGE NAMES, NOT VERSIONS OR SPECIFIERS.
# It will use the version it finds first in your package search order.
# `includes` get added into a packaged plugin in a `site-packages` folder.

src="src/" # source directory (a string). Lets you have slightly more control over plugin packaging.

# More options can be added by custom plugin loaders (obviously), so keep that in mind.

plugin.toml configuration options

Your plugin.toml contains plugin specific information and WILL be packaged in your final plugin.

# Can and will be changed by custom plugin loaders
name = "ExamplePlugin"
author = "Abby"
entry = "main" # Entry file
version = "1.0" # plugin version

min_api_version = "0.1.0"
max_api_version = "0.1.10"

# versions can be formated as follows:
# - string: "major.minor[.<patch>[-<tag>]]"
# - table: {major=1, minor=0, patch=0, tag="Beta"}
# - list/tuple: [1, 0, 0, "beta"], [1, 0], [1, 0, 0]


# (Optional from here on)
dependencies = [
    {plugin_id="author.name", min_version="0.1.0", max_version="0.1.0"},
    # ... more dependencies
]

# you can add as much additional data as you want.
# It will get saved under "aditional_meta" in `PluginMetadata`

main.py (our entry in this example)

# Whatever you want here!

print("Holy moly, we loaded it!")

Final structure

Here is the final file structure of our plugin

exampleplugin/
├── .venv/ # our virtual environment during development
│   └── ...
├── .git/
│   └── ...
├── src/
│   ├── main.py
│   └── plugin.toml
├── pyproject.toml
├── # misc
├── README.md
├── .gitignore
└── uv.lock

Packaging Our Plugin:

This heavily depends on your loading strategy, but there is a generic command provided. It uses the default strategy.

uv run build-plugin ./ ./build
#                   ^     ^
#                   |     | - build/output directory
#                   |
#                   | - src directory (gets modified if a pyproject is present in that folder)

Alternatively: We Can Make a Build Script.

This should mostly be provided by the plugin api you are using or create, but for testing we can also just build out our own.

plugin_api_version = ApiVersion(1, 0, None, None)

src = Path("./")
dest = src / "build"

meta_loader = DefaultMetadataLoader() # loads the metadata for our plugin
archiver = DefaultPluginArchiver()

# load our metadata and archive our plugin
meta = meta_loader.load_metadata(src, plugin_api_version)
archiver.archive_plugin(meta, src, dest)

Getting Started: Loading plugins (Default Strategy):

Project structure

ourproject/
├── .venv/ # our virtual environment during development
│   └── ...
├── .git/
│   └── ...
├── plugins/
│   └── Abby.ExamplePlugin.tar.gz # our example plugin!
├── src/
│   ├── ourproject/ # plugin api
│   │   └── ...
│   └── main.py # Our application
├── pyproject.toml
├── README.md
├── .gitignore
└── uv.lock

Loading plugins

Loading plugins is actually fairly easy (assuming you are okay with the defaults).

from openpluginloader.defaultstrategy import create_default_manager
from openpluginloader.versioning import ApiVersion
from openpluginloader.utility import set_default_module_cache

from pathlib import Path

import ourproject # import our api.

# makes our current imports available to plugins. VERY IMPORTANT
set_default_module_cache()
# You can also manually set `utility.DEFAULT_MODS` if you want more careful control
# ONLY MODIFY DEFAULT_MODS, DO NOT INSTANTIATE A NEW DICT! THIS WILL BREAK THINGS!

API_VERSION = ApiVersion(1, 0, 0, None)

manager = create_default_manager(API_VERSION, Path("plugins/"))
manager.initialize_hooks() # initialize very important import hooks

plugins = manager.discover_plugins() # discovers plugins and sorts them.
manager.load_all_plugins()

Loading individual plugins:

from openpluginloader.defaultstrategy import create_default_manager
from openpluginloader.versioning import ApiVersion
from openpluginloader.utility import set_default_module_cache

from pathlib import Path

import ourproject # import our api.

# makes our current imports available to plugins. VERY IMPORTANT
set_default_module_cache()
# You can also manually set `utility.DEFAULT_MODS` if you want more careful control
# ONLY MODIFY DEFAULT_MODS, DO NOT INSTANTIATE A NEW DICT! THIS WILL BREAK THINGS!

API_VERSION = ApiVersion(1, 0, 0, None)

manager = create_default_manager(API_VERSION, Path("plugins/"))
manager.initialize_hooks() # initialize very important import hooks

plugins = manager.discover_plugins() # discovers plugins and sorts them.

import plugins.ExamplePlugin # imports `__init__.py` from our ExamplePlugin
# alternatively
import plugins.ExamplePlugin.__ENTRY__ # imports a plugin's entry point (defined in plugin.toml)
# alternatively again
import plugins.ExamplePlugin.main # import a specific module from ExamplePlugin

Side Note:

My account (ArachnidAbby) has an old package called "OpenPluginApi". Although that project has inspired me to make this, I would NOT recommend using it. I wrote it when I was around 14. It is not very useful or good. It is not meant to be used with this project.

Metadata

Release files for openpluginloader 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openpluginloader 2.0.0
File Size Uploaded Provenance Actions
openpluginloader-2.0.0.tar.gz 18.6 kB Without provenance Details for openpluginloader-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for openpluginloader 2.0.0
File Interpreter ABI Platform Actions
openpluginloader-2.0.0-py3-none-any.whl Python 3 none any Details for openpluginloader-2.0.0-py3-none-any.whl

Total release size: 43.6 kB

Release files / openpluginloader-2.0.0.tar.gz

Download URL openpluginloader-2.0.0.tar.gz
Size 18.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7951f9dfc73f9d9cb5c59c2df7ceb73c7947ccec02c12685dafb2caa6b2f89bf
BLAKE2b-256 checksum
How to use checksums
5262fc24d195724e422ccfdc70fe3de35117bac576370a45fafa125aac27e477
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / openpluginloader-2.0.0-py3-none-any.whl

Download URL openpluginloader-2.0.0-py3-none-any.whl
Size 25.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba60bb8b86add4614a82a299cce4115055ba4a018ca5cea5f68a13d3b10444e9
BLAKE2b-256 checksum
How to use checksums
b1335f9e7fb3b6ae55a4646314ccbfb17e34956a2f90f614ded004d0dc674968
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for openpluginloader 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page