Skip to main content

Application-agnostic plugin framework built on pluggy

Project description

PluginForge

Application-agnostic Python plugin framework built on pluggy.

PluginForge adds the layers that pluggy is missing: YAML configuration, plugin lifecycle management, enable/disable per config, dependency resolution, FastAPI integration, and i18n support.

Installation

pip install pluginforge

With optional FastAPI support:

pip install pluginforge[fastapi]

Quickstart

1. Create a plugin

from pluginforge import BasePlugin

class HelloPlugin(BasePlugin):
    name = "hello"
    version = "1.0.0"
    description = "A hello world plugin"

    def activate(self):
        print(f"Hello plugin activated with config: {self.config}")

    def get_routes(self):
        from fastapi import APIRouter
        router = APIRouter()

        @router.get("/hello")
        def hello():
            return {"message": self.config.get("greeting", "Hello!")}

        return [router]

2. Configure your app

# config/app.yaml
app:
  name: "MyApp"
  version: "1.0.0"
  default_language: "en"

plugins:
  entry_point_group: "myapp.plugins"
  enabled:
    - "hello"
  disabled: []
# config/plugins/hello.yaml
greeting: "Hello from PluginForge!"

3. Use PluginManager

from pluginforge import PluginManager

pm = PluginManager("config/app.yaml")

# Register plugins directly (or use entry points for auto-discovery)
pm.register_plugins([HelloPlugin])

# Access plugins
for plugin in pm.get_active_plugins():
    print(f"Active: {plugin.name} v{plugin.version}")

# Mount FastAPI routes
from fastapi import FastAPI
app = FastAPI()
pm.mount_routes(app)  # Routes at /api/plugins/{name}/

Features

  • YAML Configuration - App config, per-plugin config, and i18n strings
  • Plugin Lifecycle - init, activate, deactivate with error handling
  • Enable/Disable - Control plugins via config lists
  • Dependency Resolution - Topological sorting with circular dependency detection
  • FastAPI Integration - Auto-mount plugin routes under /api/plugins/{name}/
  • Alembic Support - Collect migration directories from plugins
  • i18n - Multi-language strings from YAML with fallback

Entry Point Discovery

Register plugins as entry points in your pyproject.toml:

[project.entry-points."myapp.plugins"]
hello = "myapp.plugins.hello:HelloPlugin"

Then use discover_plugins() instead of register_plugins():

pm = PluginManager("config/app.yaml")
pm.discover_plugins()  # Auto-discovers from entry points

i18n

# config/i18n/en.yaml
common:
  save: "Save"
  cancel: "Cancel"
pm.get_text("common.save", "en")  # "Save"
pm.get_text("common.save", "de")  # "Speichern"

Development

# Install dependencies
poetry install --with dev

# Run tests
poetry run pytest

# Lint
poetry run ruff check pluginforge/ tests/

# Format
poetry run ruff format pluginforge/ tests/

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pluginforge-0.2.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pluginforge-0.2.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file pluginforge-0.2.0.tar.gz.

File metadata

  • Download URL: pluginforge-0.2.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.13 Linux/6.8.0-106-lowlatency

File hashes

Hashes for pluginforge-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b5cefa29fc15dc719c647a27e5dbd8b7e107bd50b19fdb3108d2c190ddc0ab00
MD5 4d4207a2e26f9b45116e0cd2f51b693b
BLAKE2b-256 8a314270cbb4471d4990ef719cb495d3a3712770785adc2a8b424cd864c40a29

See more details on using hashes here.

File details

Details for the file pluginforge-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pluginforge-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.13 Linux/6.8.0-106-lowlatency

File hashes

Hashes for pluginforge-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c5df4da0ce7a245e41f1e16bd7112b7d6dae013d0b7e4b9d11620fd0a2c4759
MD5 442ec255e0aa2d7a245edf5f1a3d031c
BLAKE2b-256 4f32cef33ae1a701b9261dd38f79fdcb6852cf7163b67a46b0f52d485bc2f3c8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page