# Call Slicer plug-in from external python program

**URL:** <https://discourse.slicer.org/t/call-slicer-plug-in-from-external-python-program/37900>\
**Category:** Development\
**Created:** [August 15, 2024, 9:58am UTC](https://discourse.slicer.org/t/call-slicer-plug-in-from-external-python-program/37900 "2024-08-15T09:58:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ning\_w](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ning_w/32/68617_2.png) [@ning\_w](https://discourse.slicer.org/u/ning_w)\
**Post date:** [August 15, 2024, 9:58am UTC](https://discourse.slicer.org/t/call-slicer-plug-in-from-external-python-program/37900/1 "2024-08-15T09:58:30Z")

</div>

I am trying to do secondary development based on 3D slicer, using Python language, and now I have encountered a problem, and I am here to ask for your help. I want to use the plug-in OpenIGTLink that calls slcier externally, can I achieve this function? Or can I install this plug-in into my secondary development software? Can you give me some suggestions or ideas?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 15, 2024, 12:32pm UTC](https://discourse.slicer.org/t/call-slicer-plug-in-from-external-python-program/37900/2 "2024-08-15T12:32:23Z")

</div>

You can use [pyigtl](https://pypi.org/project/pyigtl/) Python package to send/receive data to/from 3D Slicer in any Python environment via OpenIGTL protocol.

---

<div class="post-metadata">

**Author:** ![ning\_w](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ning_w/32/68617_2.png) [@ning\_w](https://discourse.slicer.org/u/ning_w)\
**Post date:** [August 16, 2024, 9:24am UTC](https://discourse.slicer.org/t/call-slicer-plug-in-from-external-python-program/37900/3 "2024-08-16T09:24:22Z")

</div>

Thank you very much for your answer, but I want to call this plugin now, is there any way? Use Python language, or can this plugin be installed on the software I developed?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 16, 2024, 10:47am UTC](https://discourse.slicer.org/t/call-slicer-plug-in-from-external-python-program/37900/4 "2024-08-16T10:47:01Z")

</div>

If your program is in Python then you can use pyigtl, if in C/C++ then you can use [GitHub - openigtlink/OpenIGTLink: Free, open-source network communication library for image-guided therapy](https://github.com/openigtlink/OpenIGTLink)

---

<div class="post-metadata">

**Author:** ![ning\_w](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ning_w/32/68617_2.png) [@ning\_w](https://discourse.slicer.org/u/ning_w)\
**Post date:** [August 16, 2024, 9:20am UTC](https://discourse.slicer.org/t/call-slicer-plug-in-from-external-python-program/37900/5 "2024-08-16T09:20:09Z")

</div>

I am trying to do secondary development based on slicer, and I have made a new software using Python. Now I have a problem: how to install the slicer plug-in: OpenIGTLink in my software? Or how to use Python code in the compiler pycharm to call this plug-in? Please help me, as a beginner, I really need help.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 16, 2024, 10:51am UTC](https://discourse.slicer.org/t/call-slicer-plug-in-from-external-python-program/37900/6 "2024-08-16T10:51:20Z")

</div>

You can only use Slicer extensions in the Slicer application. You can use OpenIGTLink library or pyigtl in your software to communicate with Slicer.

---

<div class="post-metadata">

**Author:** ![ning\_w](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ning_w/32/68617_2.png) [@ning\_w](https://discourse.slicer.org/u/ning_w)\
**Post date:** [August 19, 2024, 1:42am UTC](https://discourse.slicer.org/t/call-slicer-plug-in-from-external-python-program/37900/7 "2024-08-19T01:42:14Z")

</div>

Thank you very much. According to your guidance, I have connected to the data sent by plus server in my python code, using pyigtl, and got: message = client.wait\_for\_message(“ToolToReference”, timeout=5). How can I use this probe model to connect to my NDI? Later, I also want to use the registration plug-in: Fiducial Registration Wizard. How can I implement this function in my python code? Please help me, I really want to learn. Thank you again.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 19, 2024, 7:25am UTC](https://discourse.slicer.org/t/call-slicer-plug-in-from-external-python-program/37900/8 "2024-08-19T07:25:37Z")

</div>

If you want to call Slicer functions you can use the [`/slicer` endpoint](https://slicer.readthedocs.io/en/latest/user_guide/modules/webserver.html#slicer-endpoints) in the REST API of Slicer. You can simply plain Python `requests` to run Python commands the same way as you would run them in the Python console of Slicer.

For your convenience, you canuse slicerio package to start the Slicer application ([`slicerio.server.start_server`](https://github.com/lassoan/slicerio/blob/0566bf6616cd561d24a64225523f005f7c3c90ee/slicerio/server.py#L10)).
