> For the complete documentation index, see [llms.txt](https://zapit.gitbook.io/user-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zapit.gitbook.io/user-guide/running-experiments/python/connecting-python-to-zapit.md).

# Connecting Python to Zapit

Zapit's [Python Bridge](https://github.com/Zapit-Optostim/zapit-Python-Bridge) uses the [MATLAB Engine](https://uk.mathworks.com/help/matlab/matlab-engine-for-python.html) to call Zapit from Python.  The MATLAB GUI is used for calibrating the scanners and the sample. After this point all subsequent operations for which you might have used the MATLAB API can be done in Python. Zapit must remain running in MATLAB throughout. &#x20;

#### Setting up

1. Close Zapit if open.&#x20;
2. Edit your `zapitSystemSettings.yml` file, setting `general.openPythonBridgeOnStart` to `1`.
3. Restart Zapit. You should see the message "Opened Python Bridge" at the command line.

Now install the Python Bridge:

```
pip install zapit-Python-Bridge
```

#### Test the bridge

Open a stim config file in Zapit and open an ipython session. Test the connection by querying the number of stimulus conditions in the loaded stimulus config file.

<pre class="language-python"><code class="lang-python"><strong>import zapit_python_bridge.bridge as zpb
</strong>hZP = zpb.bridge()
hZP.num_stim_cond()
</code></pre>

&#x20;
