lml - Load Me Later

0.2.0 · active · verified Fri Apr 10

lml is a Python library that provides a lazy plugin management system. It seamlessly finds lml-based plugins in the Python environment but loads them only on demand, making it suitable for plugins with bulky or memory-hungry external dependencies. The current version is 0.2.0, with releases occurring periodically, the latest being March 2025.

Warnings

Install

Imports

Quickstart

This example demonstrates how to define a plugin using `PluginInfo` and manage it with a custom `PluginManager`. It registers a 'Boost' plugin under the 'cuisine' category with the tag 'Portable Battery', and then retrieves and uses it.

from lml.plugin import PluginInfo, PluginManager

@PluginInfo("cuisine", tags=["Portable Battery"])
class Boost(object):
    def make(self, food=None, **keywords):
        print(f"I can cook {food} for robots")

class CuisineManager(PluginManager):
    def __init__(self):
        PluginManager.__init__(self, "cuisine")

    def get_a_plugin(self, food_name=None, **keywords):
        # 'key' is the primary key used during registration, often the first tag
        return PluginManager.get_a_plugin(self, key=food_name, **keywords)

if __name__ == '__main__':
    manager = CuisineManager()
    chef = manager.get_a_plugin("Portable Battery")
    if chef:
        chef.make(food="Portable Battery")
    else:
        print("No chef found for Portable Battery")

view raw JSON →