Skip to main content

A simple Modbus/TCP library for Python

Project description

A simple Modbus/TCP client library for Python.

Since version 0.1.0, a server is also available for test purpose only (don’t use in project).

pyModbusTCP is pure Python code without any extension or external module dependency.


The module is currently test on Python 2.7, 3.4, 3.5, 3.6, 3.7, 3.8 and 3.9.



You can install this package from:

PyPI, the easy way:

sudo pip install pyModbusTCP


git clone
cd pyModbusTCP
sudo python install

GitHub with pip:

sudo pip install git+

Usage example

See examples/ for full scripts.

include (for all samples)

from pyModbusTCP.client import ModbusClient

module init (TCP always open)

# TCP auto connect on first modbus request
c = ModbusClient(host="localhost", port=502, unit_id=1, auto_open=True)

module init (TCP open/close for each request)

# TCP auto connect on modbus request, close after it
c = ModbusClient(host="", auto_open=True, auto_close=True)

module init (with accessor functions)

c = ModbusClient()"localhost")
# managing TCP sessions with call to

Read 2x 16 bits registers at modbus address 0 :

regs = c.read_holding_registers(0, 2)
if regs:
    print("read error")

Write value 44 and 55 to registers at modbus address 10 :

if c.write_multiple_registers(10, [44,55]):
    print("write ok")
    print("write error")


Documentation available online at

Know issue

On windows OS with older Python version (<3), win_inet_pton module is require. This avoid exception “AttributeError: ‘module’ object has no attribute ‘inet_pton’”.

install win_inet_pton:

sudo pip install win_inet_pton

import win_inet_pton at beginning of your code:

import win_inet_pton
from pyModbusTCP.client import ModbusClient

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyModbusTCP, version 0.1.10
Filename, size File type Python version Upload date Hashes
Filename, size pyModbusTCP-0.1.10.tar.gz (17.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page