Skip to content

Pluggable class

This is the reference for the wrapper object Pluggable that contains all the parameters, attributes and functions. It wraps an Extension.

ravyn.Pluggable

Pluggable(cls, **options)

The Pluggable is a wrapper around an Extension to initialize it lazily.

Read more about the Pluggables and learn how to use them.

Example

from typing import Optional

from loguru import logger
from pydantic import BaseModel

from ravyn import Ravyn, Extension, Pluggable
from ravyn.types import DictAny


class PluggableConfig(BaseModel):
    name: str


class MyExtension(Extension):
    def __init__(
        self,
        app: Optional["Ravyn"] = None,
        config: PluggableConfig = None,
        **kwargs: "DictAny",
    ):
        super().__init__(app, **kwargs)

    def extend(self, config: PluggableConfig) -> None:
        logger.success(f"Successfully passed a config {config.name}")


my_config = PluggableConfig(name="my extension")

pluggable = Pluggable(MyExtension, config=my_config)
# or
# pluggable = Pluggable("path.to.MyExtension", config=my_config)

app = Ravyn(routes=[], extensions={"my-extension": pluggable})
Source code in ravyn/pluggables/base.py
62
63
64
def __init__(self, cls: type[ExtensionProtocol] | str, **options: Any):
    self.cls_or_string = cls
    self.options = options

cls_or_string instance-attribute

cls_or_string = cls

options instance-attribute

options = options

cls property

cls