# How to turn a python extension into a C++ one?

**URL:** https://discourse.slicer.org/t/how-to-turn-a-python-extension-into-a-c-one/47476
**Category:** Development
**Created:** [June 27, 2026, 11:51am UTC](https://discourse.slicer.org/t/how-to-turn-a-python-extension-into-a-c-one/47476 "2026-06-27T11:51:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Long\_Zhang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/long_zhang/32/13519_2.png) [@Long\_Zhang](https://discourse.slicer.org/u/Long_Zhang)
#### Post date: [June 27, 2026, 11:51am UTC](https://discourse.slicer.org/t/how-to-turn-a-python-extension-into-a-c-one/47476/1 "2026-06-27T11:51:03Z")

</div>

I want to speedup the extension, and I wonder if this is a feasible way. and how to do it.

---

<div class="post-metadata">

### Author: ![shai-ikko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shai-ikko/32/15765_2.png) [@shai-ikko](https://discourse.slicer.org/u/shai-ikko)
#### Post date: [July 1, 2026, 2:17pm UTC](https://discourse.slicer.org/t/how-to-turn-a-python-extension-into-a-c-one/47476/2 "2026-07-01T14:17:01Z")

</div>

It depends on which extension you are looking at, and what it does. Many extensions just invoke ITK algorithms and/or VTK visualizations, and then there’s little to gain from a compiled extension. Others do relatively simple mathematical operations on volumes, and are sometimes written to do this by looping on arrays in Python – and then can be sped up by orders of magnitude by using numpy array operations instead, while staying in Python.

To turn a Python extension into a C++ one, you essentially need to rewrite it. This also requires building your extension, which may not be trivial (depending on your familiarity with creating C++ extensions for Slicer).

To summarize: It can be done, but – unless you are doing something extremely special – I would recommend looking at other options first.
