Skip to main content

Python controller for Legato family of syringe pumps

Syringe logo by Freepik @ Flaticon.com
Tests Test Coverage Code style: black
License: GPL v3 Latest version GitHub issues

Control a syringe pumpt (e.g. Legato 100 / 101) using a computer. This package uses a COM port to communicate with the pump via an USB cable. It enables you to write python programs that control the pump, e.g. turn it on and off, set the flow rate, etc.

Installation

pip install python-syringe-pump

or

poetry add python-syringe-pump

Usage

Working example

Copy-paste this to get going!

import asyncio
import aioserial
from syringe_pump import Pump, Quantity

async def main():
    serial = aioserial.AioSerial(port="COM4", baudrate=115200, timeout=2)
    async with Pump(serial=serial) as pump:
        await pump.infusion_rate.set(Quantity("1 ml/min"))
        await pump.run()
        await asyncio.sleep(10)
    # pump will stop when exiting the context manager

asyncio.run(main())

Curious about the pieces of code above? Read on!

Serial port connection

The syringe_pump uses aioserial to communicate with the pump via the COM port. To use the controller, create a serial connection and pass it into the Pump class.

import aioserial
serial = aioserial.AioSerial(port="COM4", baudrate=115200, timeout=2)

Async communication

This package uses asyncio to communicate with the pump. As a result, you need to add a few await statements to your code, which may seem like a pain. However, the benefits will be worth it, especially when working with multiple pumps or sending experiment results via a network.

from syringe_pump import Pump, Quantity

pump = await Pump.from_serial(serial=serial)
await pump.infusion_rate.set(Quantity("1 ml/min"))
await pump.run()

Note: The from_serial class method will configure the pump to use the correct communication protocol and disable NVRAM, following manufacturer's recommendations.

Async context manager

In python, it's common to use context managers to handle external resources such as files, network connections, etc.

Instead of the above examle, you can use the Pump as such context manager, which will automatically stop the pump in case of an error or at the end of the program.

from syringe_pump import Pump, Quantity

async with Pump(serial=serial) as pump:
    await pump.infusion_rate.set(Quantity("1 ml/min"))
    await pump.run()

Running async code

To run the async code in a normal python file, you need to use the asyncio.run function or similar:

import asyncio
# in regular python file:

async def main():
    asyncio.sleep(1)

asyncio.run(main())

Note: To benefit from non-blocking asyncio code, use asyncio.sleep instead of time.sleep.

Note: in a jupyter notebook, you can use await directly in the cell:

# in jupyter notebook only:
await main()

API

Units

The pump controller uses the quantiphy package to handle flow rates, volumes etc.

Example usage:

from syringe_pump import Quantity
Quantity("1 ml/min")
Quantity("13.54 ml")

Pump class

The controller implements most of the functionality specified in Legato user Commands.

The methods and their parameters are easy to discover using autocomplete in your IDE.

Here's a quick overview of the popular methods:

  • run & stop: control the pump operation
  • set_brightness: control the onboard display. Set to 0 to turn off.
  • set_force & get_force: control the force applied to the syringe

Next, the pump controller has some properties that allow you to manage other parameters:

Pump.infusion_rate and Pump.withdrawal_rate

The pump flow rates can be controlled here, including ramping. Common methods available are:

  • set and get
  • set_ramp(start, end, duration)

Example:

rate = await pump.infusion_rate.get_rate()
await pump.infusion_rate.set_rate(2 * rate)
await pump.infusion_rate.set_ramp(2 * rate, 0, 10)

Pump.syringe

The syringe parameters can be controlled here. The pump uses them to convert between flow rates and volumes.

Important methods:

  • get_diameter and set_diameter
  • get_volume and set_volume
  • set_manufacturer - to use pre-defined settings for common syringes

Example:

from syringe_pump import Manufacturer
await pump.syringe.set_manufacturer(Manufacturer.HOSHI, Quantity("1 ml"))

Examples

See the examples folder for more examples.

Pump.infusion_volume and Pump.withdrawal_volume

Allows you to inspect and reset the volume dispensed by the pump. The pump keeps track of the volume since last reset by itself.

Methods:

  • get
  • clear

Pump.target_volume

Allows you to set a volume after which the pump will stop by itself. This is useful to prevent the pump from over-dispensing and damaging the syringe.

Methods:

  • set
  • clear
  • get - returns the target volume or None if not set

Note that there is only one target volume across infusion and withdrawal. Negative values are not allowed.

Pump.target_time

Allows you to set a time after which the pump will stop by itself. The time is represented as a datetime.timedelta object.

Methods:

  • set
  • clear
  • get - returns the target time or None if not set

Example:

from datetime import timedelta
await pump.target_time.set(timedelta(hours=2, minutes=10))

Note: it seems the pumpt can only handle target time or target volume, but not both.

Development

Have a look at CONTRIBUTING.md for more information on the scope of the project and how to contribute.

Credits

Project logo: Freepik @ Flaticon.com

Metadata

Release files for python-syringe-pump 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-syringe-pump 0.2.1
File Size Uploaded Provenance
python_syringe_pump-0.2.1.tar.gz 24.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for python-syringe-pump 0.2.1
File Interpreter ABI Platform
python_syringe_pump-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 49.3 kB

Release files / python_syringe_pump-0.2.1.tar.gz

Download URL python_syringe_pump-0.2.1.tar.gz
Size 24.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e9602f509da1d9f6bee5bcec6fec38eba7a5421468a60153f7e701b3ceb55dc3
BLAKE2b-256 checksum
How to use checksums
efb90832b6b59b3baefe49874c544c5ea68ad161caeb92afc5bc3feabeb22c3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.12 Linux/6.2.0-1012-azure

Release files / python_syringe_pump-0.2.1-py3-none-any.whl

Download URL python_syringe_pump-0.2.1-py3-none-any.whl
Size 25.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58241329487659a64a38edc51f2401f9684debdbd3134689856eee3c170f403c
BLAKE2b-256 checksum
How to use checksums
c52c0d95fee445d306a4b8bf12faf95bb4eaefe254e48f96d3490acb263f8170
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.12 Linux/6.2.0-1012-azure

Security for python-syringe-pump 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page