# IO in python module

**URL:** https://discourse.itk.org/t/io-in-python-module/2846
**Category:** Engineering
**Created:** [March 17, 2020, 8:57pm UTC](https://discourse.itk.org/t/io-in-python-module/2846 "2020-03-17T20:57:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [March 17, 2020, 8:57pm UTC](https://discourse.itk.org/t/io-in-python-module/2846/1 "2020-03-17T20:57:49Z")

</div>

I have started to work on the wrapping of IO in RTK:

> <https://github.com/SimonRit/RTK/pull/307>

  
There is something which is not clear to me. When working with C++, I can register IO factories so that this is quite transparent for the user, the adequate ImageIO is automatically detected:  

> <https://github.com/SimonRit/RTK/blob/master/src/rtkIOFactories.cxx#L59-L68>

  
In an [example](https://github.com/KitwareMedical/ITKIOScanco/blob/master/examples/ITKIOScanco.ipynb) that I found, it seems that one has to specify manually the IO using the `SetImageIO` method of the image reader. Is there a way to avoid this and to register factories in a module? My PR attempted to do this with the `rtk::HisImageIO` but that does not work so far…

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [March 17, 2020, 9:28pm UTC](https://discourse.itk.org/t/io-in-python-module/2846/2 "2020-03-17T21:28:55Z")

</div>

Specifying `FACTORY_NAMES` like this should do it:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/99b11184c89a15ec50daf1086d720c63fd33d2b0/Modules/IO/BMP/itk-module.cmake#L11>

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [March 17, 2020, 9:57pm UTC](https://discourse.itk.org/t/io-in-python-module/2846/3 "2020-03-17T21:57:14Z")

</div>

Thanks. That’s what I tried for one factory in my PR but that did not seem to work, I haven’t found what’s wrong yet. Is it supposed to work even if a separate wheel package is created for the module? If yes, why is this not used in [ITKIOScanco](https://github.com/KitwareMedical/ITKIOScanco/blob/master/examples/ITKIOScanco.ipynb) example?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [March 18, 2020, 1:39am UTC](https://discourse.itk.org/t/io-in-python-module/2846/4 "2020-03-18T01:39:00Z")

</div>

`FACTORY_NAMES` might only work at compile time? @matt.mccormick can probably explain better.

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [March 18, 2020, 1:27pm UTC](https://discourse.itk.org/t/io-in-python-module/2846/5 "2020-03-18T13:27:08Z")

</div>

I confirm that it works if I compile all the wrappings. I guess it comes down to this generated file

> <https://github.com/InsightSoftwareConsortium/ITK/blob/master/CMake/itkImageIOFactoryRegisterManager.h.in>

  
which cannot contain the factories added by a module. I see no obvious solution for this…

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [March 18, 2020, 5:47pm UTC](https://discourse.itk.org/t/io-in-python-module/2846/6 "2020-03-18T17:47:33Z")

</div>

Yes, the `itk::ImageIOFactoryRegisterManager` is configured at ITK build time, so externally built remote modules will not be in the list of registered factories.

I will work on a patch to register remote module IO factories at runtime.
