# Python Reader Plugin For ParaView Help

**URL:** https://discourse.paraview.org/t/python-reader-plugin-for-paraview-help/11560
**Category:** ParaView Support
**Tags:** python, vtk
**Created:** [March 3, 2023, 6:24pm UTC](https://discourse.paraview.org/t/python-reader-plugin-for-paraview-help/11560 "2023-03-03T18:24:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Joshua\_Vazquez](https://discourse.paraview.org/user_avatar/discourse.paraview.org/joshua_vazquez/32/11065_2.png) [@Joshua\_Vazquez](https://discourse.paraview.org/u/Joshua_Vazquez)
#### Post date: [March 3, 2023, 6:24pm UTC](https://discourse.paraview.org/t/python-reader-plugin-for-paraview-help/11560/1 "2023-03-03T18:24:41Z")

</div>

Hello,  
I’m trying to make a ParaView Reader Plugin using python that can read HDF files. I started working on this code by stripping down a filter template to the bare minimum and tried to turn it into a reader by looking at other reader plugin examples. However, while the stripped down filter works fine when put into ParaView as a filter, when I changed the filter specific lines to turn it into a reader I kept getting the same error.

Whenever I would change the first line from .filter to .reader it wouldn’t work.  
@smproxy.filter  
@smproxy.reader

This is the error I get.  
 ![image](https://discourse.paraview.org/uploads/default/original/2X/4/47bb80b2308802c6741c0eadaf8575667e485841.png)

This is the code I have so far.

```auto
from paraview.util.vtkAlgorithm import *
from vtkmodules.numpy_interface import dataset_adapter as dsa
from vtkmodules.vtkCommonDataModel import vtkDataSet
import numpy as np

@smproxy.reader(name="MyWRFReader", label="My WRF Reader")
@smproperty.input(name="Input", port_index=0)
@smdomain.datatype(dataTypes=["vtkPointSet"])
@smdomain.xml("""<InputArrayDomain attribute_type="point" name="input_normal" number_of_components="3" />""")
@smhint.filechooser(extensions="csv", file_description="Numpy CSV files")
class MyWRFReader(VTKPythonAlgorithmBase):
    def __init__ (self):
        VTKPythonAlgorithmBase. __init__ (self, nInputPorts=0, nOutputPorts=1, outputType="vtkPointSet")
        self._filename = None
       

   # def RequestData(self, request, inInfoVec, outInfoVec):
        """inData = self.GetInputData(inInfo, 0, 0)
        outData = self.GetOutputData(outInfo, 0)
        assert inData is not None
        if outData is None or (not outData.IsA(inData.GetClassName())):
            outData = inData.NewInstance()
            outInfo.GetInformationObject(0).Set(outData.DATA_OBJECT(), outData)
        return super().RequestDataObject(request, inInfo, outInfo)"""

    @smproperty.stringvector(name="Normal")
    
    def SetNormalArray(self, name):
        if name != self.NormalArray:
            self.NormalArray = name
            self.Modified()

    @smproperty.doublevector(name="Factor", default_values="1")
    @smdomain.doublerange(min=0, max=10)
    def SetFactor(self, i):
        if i != self.WarpFactor:
            self.WarpFactor = i
            self.Modified()

    def RequestData(self, request, inInfo, outInfo):
       from vtkmodules.vtkCommonDataModel import imageToVTK
       from vtkmodules.numpy_interface import dataset_adapter as dsa
       output = vtkPolyData.GetData(outInfo)

       return 1

```

[MyWRFReader.py](https://discourse.paraview.org/uploads/short-url/uCWpQUp3zAOrtJPqjs94ICPzNAY.py) (1.8 KB)

This is my first time working with python on a ParaView Plugin so I might be missing other stuff. Is there something wrong or missing with the code for it to not work?

Thanks.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [March 8, 2023, 12:40pm UTC](https://discourse.paraview.org/t/python-reader-plugin-for-paraview-help/11560/2 "2023-03-08T12:40:21Z")

</div>

Is your ParaView built with Python ?

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [March 8, 2023, 2:44pm UTC](https://discourse.paraview.org/t/python-reader-plugin-for-paraview-help/11560/3 "2023-03-08T14:44:31Z")

</div>

Here’s the error when loading the plugin:

```auto
Generic Warning: In vtkPVPythonAlgorithmPlugin.cxx, line 184
Failed to load Python plugin:
Failed to call `paraview.detail.pythonalgorithm.load_plugin`.

Traceback (most recent call last):
  File "C:\Users\uayachit\Downloads\ParaView-5.11.0-RC2-Windows-Python3.9-msvc2017-AMD64\ParaView-5.11.0-RC2-Windows-Python3.9-msvc2017-AMD64\bin\Lib\site-packages\paraview\detail\pythonalgorithm.py", line 509, in load_plugin
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\uayachit\Downloads\MyWRFReader.py", line 6, in <module>
    @smproxy.reader(name="MyWRFReader", label="My WRF Reader")
TypeError: reader() missing 1 required positional argument: 'file_description'

```

You’re missing a required argument to `reader()` decorator.

When loading Python plugins, the error shown in the popup can be a little confusing. Since the plugin loader attempts first to load it as Python plugin and if that fails attempts to load the same file as a standard plugin – causing a rather cryptic popup message. You can get the full error message by looking at the **Output Messages** panel.

---

<div class="post-metadata">

### Author: ![Joshua\_Vazquez](https://discourse.paraview.org/user_avatar/discourse.paraview.org/joshua_vazquez/32/11065_2.png) [@Joshua\_Vazquez](https://discourse.paraview.org/u/Joshua_Vazquez)
#### Post date: [March 24, 2023, 4:46pm UTC](https://discourse.paraview.org/t/python-reader-plugin-for-paraview-help/11560/4 "2023-03-24T16:46:56Z")

</div>

It is the binary version for Windows from [paraview.org](http://paraview.org) 5.11.0

---

<div class="post-metadata">

### Author: ![Joshua\_Vazquez](https://discourse.paraview.org/user_avatar/discourse.paraview.org/joshua_vazquez/32/11065_2.png) [@Joshua\_Vazquez](https://discourse.paraview.org/u/Joshua_Vazquez)
#### Post date: [March 24, 2023, 4:50pm UTC](https://discourse.paraview.org/t/python-reader-plugin-for-paraview-help/11560/5 "2023-03-24T16:50:22Z")

</div>

I edited the above code to the following and the pop up error went away.

```plaintext
from vtkmodules.numpy_interface import dataset_adapter as dsa
from vtkmodules.vtkCommonDataModel import vtkDataSet
import numpy as np

@smproxy.reader(name="PythonHDFReader", label="Python-based HDF Reader",
                extensions="hdf", file_description="HDF files")
@smproperty.input(name="Input", port_index=0)
@smdomain.datatype(dataTypes=["vtkPointSet"])
@smdomain.xml("""<InputArrayDomain attribute_type="point" name="input_normal" number_of_components="3" />""")

class HDF5Reader(VTKPythonAlgorithmBase):
    def __init__ (self):
        super(). __init__ (nInputPorts=1, nOutputPorts=1, outputType="vtkPointSet")
        self.WarpFactor = 1.0
        self.NormalArray = ""

        return 1

    def RequestData(self, request, inInfo, outInfo):
        from vtkmodules.vtkCommonDataModel import imageToVTK
        from vtkmodules.numpy_interface import dataset_adapter as dsa
                
        output = vtkPolyData.GetData(outInfo)
          
        return 1  

```
