zserio.cppbind module

The module provides helper for importing of optimized C++ classes.

zserio.cppbind.import_cpp_class(cppname: str, *, exception_class=None) Type[Any] | None[source]

Tries to import optimized C++ implementation of the given python class if ‘ZSERIO_PYTHON_IMPLEMENTATION’ environment variable is either unset or set to ‘cpp’.

Depending on the content of the ‘ZSERIO_PYTHON_IMPLEMENTATION’ environment variable, it either fails when no C++ implementation is available (‘cpp’) or ignores missing implementation and just return the original python class (None) or even does not try to load the C++ implementation if the variable is set to anyhing else (e.g. ‘python’).

Parameters:
  • pyclass – Pure python class implemenation for which the C++ optimized version should be loaded.

  • cppname – Name of optimized C++ class in case that it differs from the pyclass name.

  • exception_class – Exception to raise in case of an error.

Returns:

Requested implemenation of the given pyclass.

Raises:

PythonRuntimeException – When the requested implementation is not available.