py_adapter.plugin

Plugin logic including plugin manager and hook specifications

hook = <pluggy._hooks.HookimplMarker object>

Decorator for plugin hook functions

manager() PluginManager[source]

Return a manager to discover and load plugins for providing hooks

Plugins are automatically loaded through (setuptools) entrypoints, group inference_server.

plugin_hook(plugin_name: str, hook_name: str) HookCaller[source]

Return a hook (caller) for a single named plugin and hook name

Parameters:
  • plugin_name – The name of the plugin to return the hook for

  • hook_name – The name of the hook function

exception InvalidFormat(plugin_name: str, hook_name: str)[source]

Bases: ValueError

There is no plugin supporting the given format name

serialize(obj: py_adapter.Basic, stream: BinaryIO, py_type: Type, writer_schema: bytes) BinaryIO[source]

Hook specification. Serialize a Python object of basic types to the format supported by the implementing plugin.

Although we write to the stream, we also return the stream from this function. We need to return something to avoid pluggy thinking the hook is not implemented.

Parameters:
  • obj – Python object to serialize

  • stream – File-like object to serialize data to

  • py_type – Original Python class associated with the basic object

  • writer_schema – Data schema to serialize the data with, as JSON bytes.

serialize_many(objs: Iterable[py_adapter.Basic], stream: BinaryIO, py_type: Type, writer_schema: bytes) BinaryIO[source]

Hook specification. Serialize multiple Python objects of basic types to the format supported by the implementing plugin.

Although we write to the stream, we also return the stream from this function. We need to return something to avoid pluggy thinking the hook is not implemented.

Parameters:
  • objs – Python objects to serialize

  • stream – File-like object to serialize data to

  • py_type – Original Python class associated with the basic object

  • writer_schema – Data schema to serialize the data with, as JSON bytes.

deserialize(stream: BinaryIO, py_type: Type, writer_schema: bytes, reader_schema: bytes) py_adapter.Basic[source]

Hook specification. Deserialize data as an object of basic Python types

Parameters:
  • stream – File-like object to deserialize

  • py_type – Python class the basic object will ultimately be deserialized into

  • writer_schema – Data schema used to serialize the data with, as JSON bytes.

deserialize_many(stream: BinaryIO, py_type: Type, writer_schema: bytes, reader_schema: bytes) Iterator[py_adapter.Basic][source]

Hook specification. Deserialize data as an iterator over objects of basic Python types

Parameters:
  • stream – File-like object to deserialize

  • py_type – Python class the basic object will ultimately be deserialized into

  • writer_schema – Data schema used to serialize the data with, as JSON bytes.