API Reference¶
Generated from the source docstrings. The public API is re-exported from the
top-level pluginkit package.
Public API¶
pluginkit
¶
pluginkit: a small, strictly-typed, generics-first plugin framework for Python 3.13+.
Unlike untyped hook systems, pluginkit derives a hook call's return type from its
spec: pm.caller(spec) hands back a caller whose result is list[R]
(collecting), R | None (firstresult), or R (pipeline) - checked, not asserted.
Public API:
- :class:
ExtensionPoint/ :class:Extension- decorators that declare extension points and the extensions that fulfil them.@extension_pointbrands the declaration by dispatch mode. - :class:
ExtensionPointOpts/ :class:ExtensionOpts- the option records the markers stamp. - :class:
PluginManager- registers plugins and dispatches calls;caller(spec)returns a typed caller. - :class:
PluginResult/ :class:EntryPointLoadReport- structured provenance and discovery outcomes for production hosts. - :class:
CollectingSpec/ :class:FirstResultSpec/ :class:PipelineSpec- branded spec types, and :class:CollectingCaller/ :class:FirstResultCaller/ :class:PipelineCaller(and theAsync*variants) - the typed callers. - :class:
HookRelay/ :class:HookCaller/ :class:HookImpl- public low-level dispatch objects for inspection and advanced integrations. - :class:
PluginValidationError- raised when a plugin is invalid.
Classes¶
AsyncCollectingCaller
dataclass
¶
Bases: AsyncHookCaller
A collecting async hook's typed caller: await a call to get list[R].
Source code in src/pluginkit/aio.py
Methods:¶
__call__(*args, **kwargs)
async
¶
Await the collecting hook, returning each impl's result as list[R].
collect_with_plugins(*args, **kwargs)
async
¶
Await results paired with the plugin names that produced them.
Source code in src/pluginkit/aio.py
AsyncFirstResultCaller
dataclass
¶
Bases: AsyncHookCaller
A firstresult async hook's typed caller: await a call to get R | None.
Source code in src/pluginkit/aio.py
AsyncHookCaller
dataclass
¶
Bases: HookCaller
A HookCaller whose calls are coroutines that await async implementations.
Source code in src/pluginkit/aio.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
Methods:¶
__call__(*args, **kwargs)
async
¶
Await the hook: a list, a single value (firstresult), or the threaded value (pipeline).
Source code in src/pluginkit/aio.py
collect_with_plugins(*args, **kwargs)
async
¶
Await collecting implementations and preserve each result's plugin name.
Source code in src/pluginkit/aio.py
call_extra(functions, kwargs)
async
¶
Await the hook with extra one-off implementations that are not registered.
Source code in src/pluginkit/aio.py
call_historic(kwargs, result_callback=None)
¶
Historic hooks are not supported by the async manager.
AsyncPipelineCaller
dataclass
¶
Bases: AsyncHookCaller
A pipeline async hook's typed caller: await a call to get R.
Source code in src/pluginkit/aio.py
AsyncPluginManager
¶
Bases: PluginManager
A PluginManager whose hooks are awaited; impls may be coroutine functions.
Source code in src/pluginkit/aio.py
PluginValidationError
¶
Bases: Exception
Raised when a plugin or one of its hook implementations is invalid.
Source code in src/pluginkit/exceptions.py
CollectingCaller
dataclass
¶
Bases: HookCaller
A collecting hook's typed caller: a call returns list[R].
Source code in src/pluginkit/manager.py
EntryPointFailure
¶
EntryPointLoadReport
dataclass
¶
Structured outcome of resilient entry-point discovery.
Source code in src/pluginkit/manager.py
FirstResultCaller
dataclass
¶
Bases: HookCaller
A firstresult hook's typed caller: a call returns R | None.
Source code in src/pluginkit/manager.py
HistoricCaller
dataclass
¶
Bases: HookCaller
A historic hook's typed caller. Replay it with call_historic({...}).
Calling it directly raises - historic hooks have no plain call form - so the
typed __call__ is NoReturn rather than a value it never produces.
Source code in src/pluginkit/manager.py
HookCaller
dataclass
¶
Holds every implementation of one hook and dispatches calls to them.
Source code in src/pluginkit/manager.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
Methods:¶
__post_init__()
¶
Derive the argument-name set from the ordered parameters when given.
Source code in src/pluginkit/manager.py
check_arguments(kwargs)
¶
Fill any omitted defaulted args, then validate the call against the spec.
Returns the completed kwargs (defaults filled). Spec params with a default are optional at the call site; required params and unknown args are still rejected.
Source code in src/pluginkit/manager.py
add_impl(impl)
¶
Add an impl in priority order and replay any historic calls to it.
Source code in src/pluginkit/manager.py
remove_plugin(plugin_name)
¶
Drop every impl contributed by a plugin; return True if any were removed.
Source code in src/pluginkit/manager.py
has_plugin(plugin_name)
¶
Return whether the named plugin contributes any impl to this hook.
__call__(*args, **kwargs)
¶
Call the hook: a list, a single value (firstresult), or the threaded value (pipeline).
Source code in src/pluginkit/manager.py
collect_with_plugins(*args, **kwargs)
¶
Collect non-None results together with their registered plugin names.
Source code in src/pluginkit/manager.py
call_extra(functions, kwargs)
¶
Call the hook with extra one-off implementations that are not registered.
The extra functions run as normal-priority implementations for this call only, ordered after the already-registered ones. Useful for tests and for injecting a temporary implementation without mutating the manager.
Source code in src/pluginkit/manager.py
call_historic(kwargs, result_callback=None)
¶
Call a historic hook now and remember it for plugins registered later.
Source code in src/pluginkit/manager.py
implementations()
¶
HookImpl
dataclass
¶
One plugin's implementation of a hook, plus the kwargs it accepts.
Source code in src/pluginkit/manager.py
Attributes¶
order_key
property
¶
Sort key: tryfirst impls run first (0), normal next (1), trylast last (2).
Methods:¶
from_function(plugin_name, function, opts)
classmethod
¶
Build an impl, recording which keyword arguments the function declares.
Source code in src/pluginkit/manager.py
call(kwargs)
¶
Invoke the function, passing only the arguments it declares.
The caller guarantees every declared argument is present in kwargs, so the common "takes all the spec's arguments" case forwards kwargs directly and a subset impl indexes the few it wants - both avoiding a membership scan.
Source code in src/pluginkit/manager.py
HookRelay
¶
Attribute-style access to hook callers, e.g. pm.hook.add_ingredients(...).
Source code in src/pluginkit/manager.py
PipelineCaller
dataclass
¶
Bases: HookCaller
A pipeline hook's typed caller: a call returns R.
Source code in src/pluginkit/manager.py
PluginManager
¶
Registers plugins and exposes their hooks via a HookRelay.
Source code in src/pluginkit/manager.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | |
Methods:¶
__init__(project_name)
¶
Bind the manager to a project name shared with the markers.
Source code in src/pluginkit/manager.py
add_extension_points(namespace)
¶
Scan a module (or object) for extension points and create callers.
Every caller is built and validated before any is registered, so a namespace with an invalid spec leaves the manager unchanged rather than half-configured.
Source code in src/pluginkit/manager.py
caller(spec)
¶
Return the typed caller for an @extension_point-decorated function.
The result is a plain HookCaller, but its static type carries the extension
point's dispatch mode, so a call returns list[R] (collecting), R | None
(firstresult), or R (pipeline) - derived from the declaration, not asserted.
Source code in src/pluginkit/manager.py
register(plugin, name=None)
¶
Register a plugin object, wiring up every hook implementation it carries.
Source code in src/pluginkit/manager.py
unregister(name_or_plugin)
¶
Remove a plugin by name or by object; return the removed plugin or None.
Source code in src/pluginkit/manager.py
set_blocked(name)
¶
Block a plugin name: unregister it if present and refuse future registration.
is_blocked(name)
¶
is_registered(plugin)
¶
get_plugin(name)
¶
get_name(plugin)
¶
Return the registered name of a plugin object, or None.
Source code in src/pluginkit/manager.py
get_canonical_name(plugin)
¶
plugin_names()
¶
get_hookcallers(plugin)
¶
Return the hooks a registered plugin contributes to, or None if unknown.
Source code in src/pluginkit/manager.py
__repr__()
¶
load_entrypoints(group, *, ignore_errors=False)
¶
Discover and register external plugins advertised under an entry-point group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str
|
The entry-point group name to scan. |
required |
ignore_errors
|
bool
|
When True, skip plugins that fail to load or register instead of raising, so one broken plugin cannot block discovery. |
False
|
Returns:
| Type | Description |
|---|---|
int
|
The number of plugins successfully registered. |
Note
With ignore_errors=False, a failure part-way through leaves the
plugins registered before it registered; this method does not roll back
across plugins.
Source code in src/pluginkit/manager.py
load_entrypoints_report(group)
¶
Discover entry points resiliently and return structured outcomes.
Unlike strict :meth:load_entrypoints, this method always continues after
individual failures. The original exception is retained for host reporting.
Source code in src/pluginkit/manager.py
PluginResult
¶
CollectingSpec
¶
A collecting extension point: a call collects each extension's R into list[R].
Source code in src/pluginkit/markers.py
Extension
¶
Creates the @extension decorator bound to a project name.
Source code in src/pluginkit/markers.py
Methods:¶
__init__(project_name)
¶
Bind the marker to a project name used for the stamped attribute.
__call__(function=None, *, tryfirst=False, trylast=False, wrapper=False, optional=False, target=None)
¶
Stamp ExtensionOpts onto the function; supports bare and called forms.
Source code in src/pluginkit/markers.py
ExtensionOpts
dataclass
¶
Options attached to an extension.
Source code in src/pluginkit/markers.py
ExtensionPoint
¶
Creates the @extension_point decorator bound to a project name.
Source code in src/pluginkit/markers.py
Methods:¶
__init__(project_name)
¶
Bind the marker to a project name used for the stamped attribute.
__call__(function=None, *, firstresult=False, historic=False, pipeline=False)
¶
__call__(
function: None = ...,
*,
firstresult: Literal[True],
historic: bool = ...,
) -> Callable[[Callable[P, R]], FirstResultSpec[P, R]]
__call__(
function: None = ...,
*,
pipeline: Literal[True],
historic: bool = ...,
) -> Callable[[Callable[P, R]], PipelineSpec[P, R]]
Stamp ExtensionPointOpts onto the function; supports bare and called forms.
Source code in src/pluginkit/markers.py
ExtensionPointOpts
dataclass
¶
FirstResultSpec
¶
A firstresult extension point: a call returns the first non-None R, or None.
Source code in src/pluginkit/markers.py
HistoricSpec
¶
A historic extension point: replayed to late plugins, driven via call_historic.
Source code in src/pluginkit/markers.py
PipelineSpec
¶
A pipeline extension point: a call threads R through the extensions and returns it.
Source code in src/pluginkit/markers.py
Markers¶
The @extension_point / @extension decorators and the option records they stamp.
markers
¶
Decorators that declare extension points and the extensions that fulfil them.
A marker stamps a small frozen dataclass of options onto the decorated function under a project-namespaced attribute, so the manager can later recognise extension points and extensions by introspection.
@extension_point is typed by dispatch mode: it returns a branded spec type
(CollectingSpec / FirstResultSpec / PipelineSpec / HistoricSpec) that carries
the call signature (P) and per-extension return type (R). PluginManager.caller
reads that brand to hand back a caller whose result type is exactly right for the
mode - list[R], R | None, or R. The brand classes are type-level only; they are
never instantiated (an extension point is a declaration, not a callable you invoke
directly).
Classes¶
ExtensionPointOpts
dataclass
¶
ExtensionOpts
dataclass
¶
Options attached to an extension.
Source code in src/pluginkit/markers.py
CollectingSpec
¶
A collecting extension point: a call collects each extension's R into list[R].
Source code in src/pluginkit/markers.py
FirstResultSpec
¶
A firstresult extension point: a call returns the first non-None R, or None.
Source code in src/pluginkit/markers.py
PipelineSpec
¶
A pipeline extension point: a call threads R through the extensions and returns it.
Source code in src/pluginkit/markers.py
HistoricSpec
¶
A historic extension point: replayed to late plugins, driven via call_historic.
Source code in src/pluginkit/markers.py
ExtensionPoint
¶
Creates the @extension_point decorator bound to a project name.
Source code in src/pluginkit/markers.py
Methods:¶
__init__(project_name)
¶
Bind the marker to a project name used for the stamped attribute.
__call__(function=None, *, firstresult=False, historic=False, pipeline=False)
¶
__call__(
function: None = ...,
*,
firstresult: Literal[True],
historic: bool = ...,
) -> Callable[[Callable[P, R]], FirstResultSpec[P, R]]
__call__(
function: None = ...,
*,
pipeline: Literal[True],
historic: bool = ...,
) -> Callable[[Callable[P, R]], PipelineSpec[P, R]]
Stamp ExtensionPointOpts onto the function; supports bare and called forms.
Source code in src/pluginkit/markers.py
Extension
¶
Creates the @extension decorator bound to a project name.
Source code in src/pluginkit/markers.py
Methods:¶
__init__(project_name)
¶
Bind the marker to a project name used for the stamped attribute.
__call__(function=None, *, tryfirst=False, trylast=False, wrapper=False, optional=False, target=None)
¶
Stamp ExtensionOpts onto the function; supports bare and called forms.
Source code in src/pluginkit/markers.py
Manager¶
The plugin manager, structured discovery and attribution records, and public low-level dispatch objects. Prefer manager and caller methods for ordinary host code; mode-specific caller subclasses are typing facades rather than runtime classes.
manager
¶
The plugin manager: registers plugins and dispatches calls to their hooks.
A compact but hardened reimplementation of the pluggy ideas worth understanding:
- introspection-based discovery of specs and impls via stamped attributes;
- registration-time validation that impl arguments exist in the spec;
- per-impl keyword-argument filtering so an impl declares only what it needs;
- call ordering with tryfirst / trylast;
- collecting vs firstresult dispatch;
- generator wrappers that decorate the result and observe exceptions safely;
- historic hooks replayed to plugins registered later;
- plugin lifecycle: unregister, blocking, and lookup;
- external plugin discovery via the stdlib importlib.metadata.
The manager is safe to mutate (register / unregister / block) from multiple threads; hook calls are not internally locked and should be coordinated by the caller if they can race with registration.
Classes¶
HookImpl
dataclass
¶
One plugin's implementation of a hook, plus the kwargs it accepts.
Source code in src/pluginkit/manager.py
Attributes¶
order_key
property
¶
Sort key: tryfirst impls run first (0), normal next (1), trylast last (2).
Methods:¶
from_function(plugin_name, function, opts)
classmethod
¶
Build an impl, recording which keyword arguments the function declares.
Source code in src/pluginkit/manager.py
call(kwargs)
¶
Invoke the function, passing only the arguments it declares.
The caller guarantees every declared argument is present in kwargs, so the common "takes all the spec's arguments" case forwards kwargs directly and a subset impl indexes the few it wants - both avoiding a membership scan.
Source code in src/pluginkit/manager.py
PluginResult
¶
EntryPointFailure
¶
EntryPointLoadReport
dataclass
¶
Structured outcome of resilient entry-point discovery.
Source code in src/pluginkit/manager.py
HookCaller
dataclass
¶
Holds every implementation of one hook and dispatches calls to them.
Source code in src/pluginkit/manager.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
Methods:¶
__post_init__()
¶
Derive the argument-name set from the ordered parameters when given.
Source code in src/pluginkit/manager.py
check_arguments(kwargs)
¶
Fill any omitted defaulted args, then validate the call against the spec.
Returns the completed kwargs (defaults filled). Spec params with a default are optional at the call site; required params and unknown args are still rejected.
Source code in src/pluginkit/manager.py
add_impl(impl)
¶
Add an impl in priority order and replay any historic calls to it.
Source code in src/pluginkit/manager.py
remove_plugin(plugin_name)
¶
Drop every impl contributed by a plugin; return True if any were removed.
Source code in src/pluginkit/manager.py
has_plugin(plugin_name)
¶
Return whether the named plugin contributes any impl to this hook.
__call__(*args, **kwargs)
¶
Call the hook: a list, a single value (firstresult), or the threaded value (pipeline).
Source code in src/pluginkit/manager.py
collect_with_plugins(*args, **kwargs)
¶
Collect non-None results together with their registered plugin names.
Source code in src/pluginkit/manager.py
call_extra(functions, kwargs)
¶
Call the hook with extra one-off implementations that are not registered.
The extra functions run as normal-priority implementations for this call only, ordered after the already-registered ones. Useful for tests and for injecting a temporary implementation without mutating the manager.
Source code in src/pluginkit/manager.py
call_historic(kwargs, result_callback=None)
¶
Call a historic hook now and remember it for plugins registered later.
Source code in src/pluginkit/manager.py
implementations()
¶
CollectingCaller
dataclass
¶
Bases: HookCaller
A collecting hook's typed caller: a call returns list[R].
Source code in src/pluginkit/manager.py
FirstResultCaller
dataclass
¶
Bases: HookCaller
A firstresult hook's typed caller: a call returns R | None.
Source code in src/pluginkit/manager.py
PipelineCaller
dataclass
¶
Bases: HookCaller
A pipeline hook's typed caller: a call returns R.
Source code in src/pluginkit/manager.py
HistoricCaller
dataclass
¶
Bases: HookCaller
A historic hook's typed caller. Replay it with call_historic({...}).
Calling it directly raises - historic hooks have no plain call form - so the
typed __call__ is NoReturn rather than a value it never produces.
Source code in src/pluginkit/manager.py
HookRelay
¶
Attribute-style access to hook callers, e.g. pm.hook.add_ingredients(...).
Source code in src/pluginkit/manager.py
PluginManager
¶
Registers plugins and exposes their hooks via a HookRelay.
Source code in src/pluginkit/manager.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | |
Methods:¶
__init__(project_name)
¶
Bind the manager to a project name shared with the markers.
Source code in src/pluginkit/manager.py
add_extension_points(namespace)
¶
Scan a module (or object) for extension points and create callers.
Every caller is built and validated before any is registered, so a namespace with an invalid spec leaves the manager unchanged rather than half-configured.
Source code in src/pluginkit/manager.py
caller(spec)
¶
Return the typed caller for an @extension_point-decorated function.
The result is a plain HookCaller, but its static type carries the extension
point's dispatch mode, so a call returns list[R] (collecting), R | None
(firstresult), or R (pipeline) - derived from the declaration, not asserted.
Source code in src/pluginkit/manager.py
register(plugin, name=None)
¶
Register a plugin object, wiring up every hook implementation it carries.
Source code in src/pluginkit/manager.py
unregister(name_or_plugin)
¶
Remove a plugin by name or by object; return the removed plugin or None.
Source code in src/pluginkit/manager.py
set_blocked(name)
¶
Block a plugin name: unregister it if present and refuse future registration.
is_blocked(name)
¶
is_registered(plugin)
¶
get_plugin(name)
¶
get_name(plugin)
¶
Return the registered name of a plugin object, or None.
Source code in src/pluginkit/manager.py
get_canonical_name(plugin)
¶
plugin_names()
¶
get_hookcallers(plugin)
¶
Return the hooks a registered plugin contributes to, or None if unknown.
Source code in src/pluginkit/manager.py
__repr__()
¶
load_entrypoints(group, *, ignore_errors=False)
¶
Discover and register external plugins advertised under an entry-point group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str
|
The entry-point group name to scan. |
required |
ignore_errors
|
bool
|
When True, skip plugins that fail to load or register instead of raising, so one broken plugin cannot block discovery. |
False
|
Returns:
| Type | Description |
|---|---|
int
|
The number of plugins successfully registered. |
Note
With ignore_errors=False, a failure part-way through leaves the
plugins registered before it registered; this method does not roll back
across plugins.
Source code in src/pluginkit/manager.py
load_entrypoints_report(group)
¶
Discover entry points resiliently and return structured outcomes.
Unlike strict :meth:load_entrypoints, this method always continues after
individual failures. The original exception is retained for host reporting.
Source code in src/pluginkit/manager.py
Async¶
The async manager and hook caller.
aio
¶
Async dispatch: an AsyncPluginManager that awaits coroutine implementations.
The registration, validation and lifecycle machinery is reused unchanged from the synchronous manager; only the calling path is asynchronous. Implementations may be plain functions or coroutine functions - their results are awaited when awaitable. Collecting, firstresult and pipeline dispatch are all supported.
Wrappers in the async manager are async generators and are observe-only: they
run setup before yield and teardown after it (including in a finally), and
they observe exceptions thrown back in, but - because async generators cannot
return a value - they do not replace the result. Use the synchronous manager when
a wrapper must transform the result.
Classes¶
AsyncHookCaller
dataclass
¶
Bases: HookCaller
A HookCaller whose calls are coroutines that await async implementations.
Source code in src/pluginkit/aio.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
Methods:¶
__call__(*args, **kwargs)
async
¶
Await the hook: a list, a single value (firstresult), or the threaded value (pipeline).
Source code in src/pluginkit/aio.py
collect_with_plugins(*args, **kwargs)
async
¶
Await collecting implementations and preserve each result's plugin name.
Source code in src/pluginkit/aio.py
call_extra(functions, kwargs)
async
¶
Await the hook with extra one-off implementations that are not registered.
Source code in src/pluginkit/aio.py
call_historic(kwargs, result_callback=None)
¶
Historic hooks are not supported by the async manager.
AsyncCollectingCaller
dataclass
¶
Bases: AsyncHookCaller
A collecting async hook's typed caller: await a call to get list[R].
Source code in src/pluginkit/aio.py
Methods:¶
__call__(*args, **kwargs)
async
¶
Await the collecting hook, returning each impl's result as list[R].
collect_with_plugins(*args, **kwargs)
async
¶
Await results paired with the plugin names that produced them.
Source code in src/pluginkit/aio.py
AsyncFirstResultCaller
dataclass
¶
Bases: AsyncHookCaller
A firstresult async hook's typed caller: await a call to get R | None.
Source code in src/pluginkit/aio.py
AsyncPipelineCaller
dataclass
¶
Bases: AsyncHookCaller
A pipeline async hook's typed caller: await a call to get R.
Source code in src/pluginkit/aio.py
AsyncPluginManager
¶
Bases: PluginManager
A PluginManager whose hooks are awaited; impls may be coroutine functions.
Source code in src/pluginkit/aio.py
Exceptions¶
exceptions
¶
Exceptions raised by the plugin framework.
Classes¶
PluginValidationError
¶
Bases: Exception
Raised when a plugin or one of its hook implementations is invalid.
Source code in src/pluginkit/exceptions.py
Demo host¶
The bundled "smoothie kitchen" host that the walkthrough demos use.
Extension points¶
points
¶
Hook specifications for the host, plus a Protocol documenting the contract.
The @extension_point functions are what the manager discovers. The Protocol classes are a modern-Python touch: they let a type checker verify, structurally, that a plugin's method signatures line up with the hooks they implement -- no base class or inheritance required.