# OpenFlexure Microscope python

**URL:** <https://openflexure.discourse.group/t/openflexure-microscope-python/885>\
**Category:** Request Help\
**Created:** [29 May 2022 20:36 UTC](https://openflexure.discourse.group/t/openflexure-microscope-python/885 "2022-05-29T20:36:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pawel1010](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@pawel1010](https://openflexure.discourse.group/u/pawel1010)\
**Post date:** [29 May 2022 20:36 UTC](https://openflexure.discourse.group/t/openflexure-microscope-python/885/1 "2022-05-29T20:36:33Z")

</div>

For delta stage I wanted to run a program in python which consists from two parts:

- `main.py`: the script that executes the XYZ scan. Runs on the PC, talks to the RPi which is controlling the OpenFlexure stage
- `stage.py`: a plugin that was added to the OpenFlexure server code. This exposes a “moveMeasure” API which commands the stage to move to a position and then read the ADC (ADC is connected to RPi, it’s ADS 1115)

I’m updating post, I successful loaded the plugin to the openflexure server. I’ve made probably a mistake in plugin code, which is `stage.py`.

The issue is located on my GitHub, named “Sever plugin load success”, here is link: [GitHub](https://github.com/pawel1010/Openflexure-confocal-microscope)

I’ll be very grateful for your suggestions.

---

<div class="post-metadata">

**Author:** ![WilliamW](https://yyz2.discourse-cdn.com/free1/user_avatar/openflexure.discourse.group/williamw/32/106_2.png) [@WilliamW](https://openflexure.discourse.group/u/WilliamW)\
**Post date:** [29 May 2022 22:19 UTC](https://openflexure.discourse.group/t/openflexure-microscope-python/885/2 "2022-05-29T22:19:09Z")

</div>

I don’t use the Python client myself, but the website instructions say "The library can be installed with `pip install openflexure-microscope-client.`" are you running the Python client on the Pi controlling the stage, or from another computer?

---

<div class="post-metadata">

**Author:** ![pawel1010](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@pawel1010](https://openflexure.discourse.group/u/pawel1010)\
**Post date:** [30 May 2022 00:34 UTC](https://openflexure.discourse.group/t/openflexure-microscope-python/885/3 "2022-05-30T00:34:18Z")

</div>

I’m running the python on Raspberry Pi and I’m communicating with it from another computer.  
In script which runs on Raspberry Pi I have a line: `from openflexure_microscope.utilities import axes_to_array`  
which in my opinion requires ”openflexure-microscope” package.

---

<div class="post-metadata">

**Author:** ![r.w.bowman](https://yyz2.discourse-cdn.com/free1/user_avatar/openflexure.discourse.group/r.w.bowman/32/15_2.png) [@r.w.bowman](https://openflexure.discourse.group/u/r.w.bowman)\
**Post date:** [30 May 2022 09:08 UTC](https://openflexure.discourse.group/t/openflexure-microscope-python/885/4 "2022-05-30T09:08:48Z")

</div>

Hi @pawel1010, the Python code for the microscope is split into two packages (and is not as well documented as I’d like, sorry!).

- The **server** code (which runs on the Pi) is in a module called `openflexure_microscope` and is not published to PyPI, it’s just on GitLab and our build server. This code is not really intended for use outside of the microscope’s built-in Pi, and depends on things like the `picamerax` module which isn’t available on other platforms. I’d really like to have renamed the module to `openflexure_microscope_server` but for historical reasons we’ve not changed it. Maybe the next major release would be a good time to do that…
- The **client** code is intended to be used in Python scripts that control the microscope. This is in a package called `openflexure-microscope-client` which installs a module called `openflexure_microscope_client`. It should not depend on the server package, and should run anywhere - it’s basically just an HTTP client.

I am not sure there’s an equivalent neatly packaged function in the Python client, but there is [some code that does the same thing](https://gitlab.com/openflexure/openflexure-microscope-pyclient/-/blob/master/openflexure_microscope_client/microscope_client.py#L84).

I’d really like to revamp the python client, perhaps another task for the next major version…

---

<div class="post-metadata">

**Author:** ![pawel1010](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@pawel1010](https://openflexure.discourse.group/u/pawel1010)\
**Post date:** [1 June 2022 22:44 UTC](https://openflexure.discourse.group/t/openflexure-microscope-python/885/5 "2022-06-01T22:44:25Z")

</div>

To be more clear, I wanted to run module on Raspberry: [module](https://openflexure-microscope-software.readthedocs.io/en/master/_modules/openflexure_microscope/stage/sanga.html)

Which libraries require lines:

```auto
from openflexure_microscope.stage.base import BaseStage
from openflexure_microscope.utilities import axes_to_array

```

?  
Do I have to install this: [lib](https://pypi.org/project/openflexure-microscope/)?  
Are they already included in Raspbian-OpenFlexure system?

---

<div class="post-metadata">

**Author:** ![WilliamW](https://yyz2.discourse-cdn.com/free1/user_avatar/openflexure.discourse.group/williamw/32/106_2.png) [@WilliamW](https://openflexure.discourse.group/u/WilliamW)\
**Post date:** [5 June 2022 17:48 UTC](https://openflexure.discourse.group/t/openflexure-microscope-python/885/6 "2022-06-05T17:48:30Z")

</div>

I am not an very familiar with the Python part of the microscope. Reading Richard’s post I think he is saying that `openflexure_microscope` is running the server on the Pi, so it is already there on the Pi. However I have a feeling that it may not be in the user space.

The library that you link at the end of your post is is an old library, all the current Microscope things are in the Openflexure GitLab space : [OpenFlexure · GitLab](https://gitlab.com/openflexure)

---

<div class="post-metadata">

**Author:** ![pawel1010](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@pawel1010](https://openflexure.discourse.group/u/pawel1010)\
**Post date:** [5 June 2022 23:41 UTC](https://openflexure.discourse.group/t/openflexure-microscope-python/885/7 "2022-06-05T23:41:29Z")

</div>

I figure out that my python program is a plugin.  
I don’t know how to load python plugin to openflexure server, any suggestions?

---

<div class="post-metadata">

**Author:** ![WilliamW](https://yyz2.discourse-cdn.com/free1/user_avatar/openflexure.discourse.group/williamw/32/106_2.png) [@WilliamW](https://openflexure.discourse.group/u/WilliamW)\
**Post date:** [6 June 2022 08:22 UTC](https://openflexure.discourse.group/t/openflexure-microscope-python/885/8 "2022-06-06T08:22:33Z")

</div>

Does any of this help? [Extensions (openflexure.org)](https://openflexure.org/software/extensions/)?
