API Reference¶
Complete API documentation for PKL.
Core Components¶
PKL provides a comprehensive plugin system with the following components:
- PluginHost - Main plugin management system
- Plugin - Plugin representation and control
- Events - Event system (Event, HostEvent, EventBase, @event decorator)
- Resources - Resource management with automatic cleanup
- Context - Plugin context tracking and awareness
- Utilities - Helper functions and decorators
Quick Links¶
Main Classes¶
PluginHost- Plugin host systemPlugin- Plugin instanceEvent- Plugin-owned eventHostEvent- System-level eventResource- Base class for resourcesEventSubscription- Event subscription resource
Decorators¶
@event()- Create plugin or host events@syscall- Preserve plugin context
Functions¶
load_plugin()- Load a pluginget_current_plugin()- Get current pluginget_default_host()- Get default hostset_default_host()- Set default hostget_logger()- Get plugin loggerset_timeout()- Schedule one-time callbackset_interval()- Schedule repeating callback
Constants¶
PluginState- Plugin state enumlog- Logging proxy
Import Patterns¶
import pkl
# Main API
host = pkl.PluginHost()
plugin = pkl.load_plugin(path)
current = pkl.get_current_plugin()
# Decorators
@pkl.event()
def my_event():
yield
@pkl.syscall
def my_api():
return \"Hello\"
# Utilities
pkl.log.info(\"Message\")
logger = pkl.get_logger(\"component\")
timer = pkl.set_timeout(callback, 5.0)
# Plugin imports
from pkl.plugins import other_plugin
other_plugin.do_something()