Skip to content

plugin

Plugin support for rdf.

There are a number of plugin points for rdf: parser, serializer, store, query processor, and query result. Plugins can be registered either through setuptools entry_points or by calling rdf.plugin.register directly.

If you have a package that uses a setuptools based setup.py you can add the following to your setup:

entry_points = {
    'rdf.plugins.parser': [
        'nt =     rdf.plugins.parsers.ntriples:NTParser',
        ],
    'rdf.plugins.serializer': [
        'nt =     rdf.plugins.serializers.NTSerializer:NTSerializer',
        ],
    }

See the setuptools dynamic discovery of services and plugins for moreinformation.

Classes:

Functions:

  • get

    Return the class for the specified (name, kind). Raises a

  • plugins

    A generator of the plugins.

  • register

    Register the plugin for (name, kind). The module_path and

Attributes:

PluginT module-attribute

PluginT = TypeVar('PluginT')

__all__ module-attribute

__all__ = ['register', 'get', 'plugins', 'PluginException', 'Plugin', 'PluginT', 'PKGPlugin']

all_entry_points module-attribute

all_entry_points = entry_points()

graph_parsers module-attribute

graph_parsers = {(name) for parser in (plugins(kind=Parser))}

graph_result_parsers module-attribute

graph_result_parsers = graph_parsers - result_parsers

rdflib_entry_points module-attribute

rdflib_entry_points = {'rdf.plugins.store': Store, 'rdf.plugins.serializer': Serializer, 'rdf.plugins.parser': Parser, 'rdf.plugins.resultparser': ResultParser, 'rdf.plugins.resultserializer': ResultSerializer, 'rdf.plugins.queryprocessor': Processor, 'rdf.plugins.queryresult': Result, 'rdf.plugins.updateprocessor': UpdateProcessor}

result_parsers module-attribute

result_parsers = {(name) for parser in (plugins(kind=ResultParser))}

PKGPlugin

PKGPlugin(name: str, kind: Type[PluginT], ep: EntryPoint)

Bases: Plugin[PluginT]

Methods:

Attributes:

Source code in rdflib/plugin.py
def __init__(self, name: str, kind: Type[PluginT], ep: EntryPoint):
    self.name = name
    self.kind = kind
    self.ep = ep
    self._class: Optional[Type[PluginT]] = None

ep instance-attribute

ep = ep

kind instance-attribute

kind = kind

name instance-attribute

name = name

getClass

getClass() -> Type[PluginT]
Source code in rdflib/plugin.py
def getClass(self) -> Type[PluginT]:  # noqa: N802
    if self._class is None:
        self._class = self.ep.load()
    return self._class

Plugin

Plugin(name: str, kind: Type[PluginT], module_path: str, class_name: str)

Bases: Generic[PluginT]

Methods:

Attributes:

Source code in rdflib/plugin.py
def __init__(
    self, name: str, kind: Type[PluginT], module_path: str, class_name: str
):
    self.name = name
    self.kind = kind
    self.module_path = module_path
    self.class_name = class_name
    self._class: Optional[Type[PluginT]] = None

class_name instance-attribute

class_name = class_name

kind instance-attribute

kind = kind

module_path instance-attribute

module_path = module_path

name instance-attribute

name = name

getClass

getClass() -> Type[PluginT]
Source code in rdflib/plugin.py
def getClass(self) -> Type[PluginT]:  # noqa: N802
    if self._class is None:
        module = __import__(self.module_path, globals(), locals(), [""])
        self._class = getattr(module, self.class_name)
    return self._class

PluginException

PluginException(msg: Optional[str] = None)

Bases: Error

Source code in rdflib/exceptions.py
def __init__(self, msg: Optional[str] = None):
    Exception.__init__(self, msg)
    self.msg = msg

get

get(name: str, kind: Type[PluginT]) -> Type[PluginT]

Return the class for the specified (name, kind). Raises a PluginException if unable to do so.

Source code in rdflib/plugin.py
def get(name: str, kind: Type[PluginT]) -> Type[PluginT]:
    """
    Return the class for the specified (name, kind). Raises a
    PluginException if unable to do so.
    """
    try:
        p: Plugin[PluginT] = _plugins[(name, kind)]
    except KeyError:
        raise PluginException("No plugin registered for (%s, %s)" % (name, kind))
    return p.getClass()

plugins

plugins(name: Optional[str] = ..., kind: Type[PluginT] = ...) -> Iterator[Plugin[PluginT]]
plugins(name: Optional[str] = ..., kind: None = ...) -> Iterator[Plugin]
plugins(name: Optional[str] = None, kind: Optional[Type[PluginT]] = None) -> Iterator[Plugin[PluginT]]

A generator of the plugins.

Pass in name and kind to filter… else leave None to match all.

Source code in rdflib/plugin.py
def plugins(
    name: Optional[str] = None, kind: Optional[Type[PluginT]] = None
) -> Iterator[Plugin[PluginT]]:
    """
    A generator of the plugins.

    Pass in name and kind to filter... else leave None to match all.
    """
    for p in _plugins.values():
        if (name is None or name == p.name) and (kind is None or kind == p.kind):
            yield p

register

register(name: str, kind: Type[Any], module_path, class_name)

Register the plugin for (name, kind). The module_path and class_name should be the path to a plugin class.

Source code in rdflib/plugin.py
def register(name: str, kind: Type[Any], module_path, class_name):
    """
    Register the plugin for (name, kind). The module_path and
    class_name should be the path to a plugin class.
    """
    p = Plugin(name, kind, module_path, class_name)
    _plugins[(name, kind)] = p