Check Extending TorchScript with Custom C++ Classes — PyTorch Tutorials 1.10.1+cu102 documentation 2. If I recall correctly, cython can integrate c++ modules, so perhaps a hybrid module (adapter / facade to cython parts) would do what you want.