# How to send python code from an external application?

**URL:** <https://discourse.slicer.org/t/how-to-send-python-code-from-an-external-application/2161>\
**Category:** Support\
**Created:** [February 23, 2018, 8:20pm UTC](https://discourse.slicer.org/t/how-to-send-python-code-from-an-external-application/2161 "2018-02-23T20:20:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Soufane](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Ahmed\_Soufane](https://discourse.slicer.org/u/Ahmed_Soufane)\
**Post date:** [February 23, 2018, 8:20pm UTC](https://discourse.slicer.org/t/how-to-send-python-code-from-an-external-application/2161/1 "2018-02-23T20:20:39Z")

</div>

Hi,  
I was wondering how to send python code from an external application ?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [February 23, 2018, 9:36pm UTC](https://discourse.slicer.org/t/how-to-send-python-code-from-an-external-application/2161/2 "2018-02-23T21:36:42Z")

</div>

There’s not a standard way to send arbitrary python commands to slicer (and it might be considered unsafe in general). You could set up a socket to listen for strings and then execute them as python code. I have done experiments with embedding a web server in slicer and it can work.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [February 23, 2018, 10:14pm UTC](https://discourse.slicer.org/t/how-to-send-python-code-from-an-external-application/2161/3 "2018-02-23T22:14:18Z")

</div>

We have been experimenting with using “Slicer” (or more generally application that are qt+pythonqt+ctk based as a jupyter/ipython kernel).

See [https://github.com/commontk/QEmbedIPython](https://github.com/commontk/QEmbedIPython) and [http://jupyter.org/](http://jupyter.org/)

That said, there is nothing like this readily available in 3D Slicer.

Here what I envision:

- install a jupyter extension (e.g `pip install slicer-jupyter-bridge`) in the jupyter interface.
- install an extension in 3D Slicer using the extension manager
- and optionally you could even install something like [itk-jupyter-widgets](https://github.com/InsightSoftwareConsortium/itk-jupyter-widgets) to visualize images directly in jupyter

Let us know if you have any questions

Cc: @thewtex

---

<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:** [February 25, 2018, 11:19pm UTC](https://discourse.slicer.org/t/how-to-send-python-code-from-an-external-application/2161/4 "2018-02-25T23:19:31Z")

</div>

It would be awesome to have all these. Can QEmbedIPython be already used with Slicer or there are still some unresolved issues?
