<!-- Source: https://medius.k4tech.net/bindings/python -->
# Install

_pip install medius_

Install with [pip](https://pip.pypa.io). No compile step:

```bash
pip install medius
```

Prebuilt [wheels](https://packaging.python.org/en/latest/specifications/binary-distribution-format/) cover Linux, macOS, and 64-bit Windows. The [Bindings overview](/bindings.md) shows how the Python package, the [C ABI](/bindings/c.md), and the Rust [medius crate](https://crates.io/crates/medius) fit together.

## Requirements

_What you need_

| Requirement | Value |
| --- | --- |
| Python | `3.8` or newer |
| Platforms with a prebuilt wheel | Linux ([glibc](https://www.gnu.org/software/libc/) / [manylinux](https://github.com/pypa/manylinux)), macOS, Windows x64 |
| [Rust toolchain](https://rustup.rs) | not needed |
| Other Python packages | none; it uses the standard library's `[ctypes](https://docs.python.org/3/library/ctypes.html)` |

On [musl](https://musl.libc.org) Linux or 32-bit Windows there's no prebuilt wheel, so `pip` builds from source and needs a Rust toolchain. Those users follow [Build & features](/bindings/python/build.md).

## Verify

_Print the version_

If this prints a version, you're ready for your [first program](/bindings/python/quickstart.md).

```bash
python -c "import medius; print(medius.version_string(), 'abi', medius.abi_version())"
# 3.0.0 abi 3
```

> **Warning**
>
> An `[OSError](https://docs.python.org/3/library/exceptions.html#OSError)` on import means the native library didn't load: you're on an unsupported platform, or `MEDIUS_LIB` points somewhere bad. See [how the library is found](/bindings/python/build.md#loading).

## Connect

_Find the box, then hand it back_

Here it is in three lines, so you can check the [box](/native/hardware.md) is reachable. [`Device.find()`](/bindings/python/api.md#connect) opens the first box it sees and runs the [handshake](/native/connection.md#handshake); the `[with](https://docs.python.org/3/reference/datamodel.html#context-managers)` block closes the link on exit.

```python
from medius import Device

with Device.find() as dev:
    v = dev.query_version()
    print(f"firmware {v.fw_major}.{v.fw_minor}.{v.fw_patch}, proto {v.proto_ver}")
```

No port? `find()` raises [`NotFoundError`](/bindings/python/types.md#subclasses). Pass an explicit path with [`Device.open("/dev/ttyACM0")`](/bindings/python/api.md#connect) (Windows: `"COM3"`), or list what's present with [`medius.find_ports()`](/bindings/python/api.md#connect). Errors are covered on [Calls & errors](/bindings/python/usage.md#errors).
