# How to improve SlicerWeb extension with python?

**URL:** <https://discourse.slicer.org/t/how-to-improve-slicerweb-extension-with-python/17480>\
**Category:** Development\
**Tags:** segmentation, python, volume, web\
**Created:** [May 5, 2021, 7:35pm UTC](https://discourse.slicer.org/t/how-to-improve-slicerweb-extension-with-python/17480 "2021-05-05T19:35:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pedro\_Vitor\_Abreu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pedro_vitor_abreu/32/10820_2.png) [@Pedro\_Vitor\_Abreu](https://discourse.slicer.org/u/Pedro_Vitor_Abreu)\
**Post date:** [May 5, 2021, 7:35pm UTC](https://discourse.slicer.org/t/how-to-improve-slicerweb-extension-with-python/17480/1 "2021-05-05T19:35:27Z")

</div>

Hello there, I’m new with Slicer and this is my first topic, so I hope I get it to make it clear and straightforward.

I’ve been trying to create a comunication between a Django server and Slicer. The Django server then would have a button that would be used to export opened segmentation files.

My main option was to use [SlicerWeb](https://github.com/pieper/SlicerWeb) extension, but I find that it can’t export segmentation files, though it can export volume files opened in Slicer perfectly well.

Is there any advice on how I could do that? I’ve been looking into the code of SlicerWeb but I couldn’t figure it out how to start. I guess that I could create a new function into SlicerWeb for a purpose like that.

Thanks  
Pedro

---

<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:** [May 5, 2021, 9:31pm UTC](https://discourse.slicer.org/t/how-to-improve-slicerweb-extension-with-python/17480/2 "2021-05-05T21:31:15Z")

</div>

Hi Pedro -

The SlicerWeb code should probably be refactored at some point, but for now it can be extended by adding a branch in [this set of if statements](https://github.com/Slicer/Slicer/blob/44a0a9a2873c3915fc8de7a179902e27749b141d/Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py#L656-L698) to create a new rest endpoint, for example `<root>/slicer/segmentations` that would map to a request handler like [this one for volumes](https://github.com/Slicer/Slicer/blob/44a0a9a2873c3915fc8de7a179902e27749b141d/Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py#L656-L698) through which you can either download or upload via nrrd format. It would just need to be call some of [the segmentation api](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#segmentations) in the request handler.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![Pedro\_Vitor\_Abreu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pedro_vitor_abreu/32/10820_2.png) [@Pedro\_Vitor\_Abreu](https://discourse.slicer.org/u/Pedro_Vitor_Abreu)\
**Post date:** [May 9, 2021, 4:15pm UTC](https://discourse.slicer.org/t/how-to-improve-slicerweb-extension-with-python/17480/3 "2021-05-09T16:15:53Z")

</div>

Hey Steve, thanks for the solution!

I’ll take a look at these codes you indicated. Definitely it’s gonna help me.

Thanks again!  
Pedro
