Skip to main content

Fast, full-featured Modbus TCP + Serial bindings for Python — powered by Rust

Project description

modbus-rs (Python)

Fast Modbus TCP + Serial bindings for Python, powered by Rust.

  • PyPI package: modbus-rs
  • Import name: modbus_rs

Install

pip install modbus-rs

Quick Start

Synchronous TCP client

import modbus_rs

with modbus_rs.TcpClient("192.168.1.10", port=502, unit_id=1) as client:
    client.connect()
    regs = client.read_holding_registers(0, 10)
    print(regs)

Async TCP client

import asyncio
import modbus_rs

async def main():
    async with modbus_rs.AsyncTcpClient("192.168.1.10", unit_id=1) as client:
        regs = await client.read_holding_registers(0, 10)
        print(regs)

asyncio.run(main())

Serial client (RTU)

import modbus_rs

with modbus_rs.SerialClient("/dev/ttyUSB0", baud_rate=9600, unit_id=1) as client:
    client.connect()
    regs = client.read_holding_registers(0, 5)
    print(regs)

Async TCP server

import asyncio
import modbus_rs

class MyApp(modbus_rs.ModbusApp):
    def handle_read_holding_registers(self, address, count):
        return [address + i for i in range(count)]

async def main():
    server = modbus_rs.AsyncTcpServer("0.0.0.0", MyApp(), port=5020, unit_id=1)
    await server.serve_forever()

asyncio.run(main())

Exceptions

  • ModbusError
  • ModbusTimeout
  • ModbusConnectionError
  • ModbusProtocolError
  • ModbusDeviceException
  • ModbusConfigError
  • ModbusInvalidArgument

Build from Source

cd mbus-ffi
maturin develop --features python,full

Run Python Tests

cd mbus-ffi
maturin develop --features python,full
cd ..
pytest mbus-ffi/tests/python/ -q

Run Python Examples

The examples live in this repository under mbus-ffi/examples.

1) Build/install the extension from source

git clone https://github.com/Raghava-Ch/modbus-rs.git
cd modbus-rs/mbus-ffi
maturin develop --features python,full

2) Start the example server (terminal 1)

cd ../examples/python_server
python3 python_server.py --host 127.0.0.1 --port 5020 --unit-id 1

3) Run the sync client (terminal 2)

cd ../python_client
python3 python_client.py --host 127.0.0.1 --port 5020 --unit-id 1

4) Run the async client (terminal 2)

cd ../python_async_client
python3 async_client.py --host 127.0.0.1 --port 5020 --unit-id 1

Optional: multi-server async demo

Start 3 servers on ports 5020, 5021, and 5022, then run:

cd ../python_async_client
python3 async_client.py --host 127.0.0.1 --port 5020 --multi

More Docs

  • Project docs: documentation/python_bindings.md
  • Full crate README (C/WASM/Python): mbus-ffi/README.md

License

Copyright (C) 2026 Raghava Challari

This project is currently licensed under GNU GPL v3.0. See LICENSE for details.

This crate is licensed under GPLv3. If you require a commercial license to use this crate in a proprietary project, please contact ch.raghava44@gmail.com to purchase a license.

Project details


Download files

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

Source Distribution

modbus_rs-0.8.0.tar.gz (1.3 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

modbus_rs-0.8.0-cp311-cp311-win_amd64.whl (566.2 kB view details)

Uploaded CPython 3.11Windows x86-64

modbus_rs-0.8.0-cp311-cp311-manylinux_2_34_aarch64.whl (874.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

modbus_rs-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (791.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

modbus_rs-0.8.0-cp311-cp311-macosx_11_0_arm64.whl (658.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

modbus_rs-0.8.0-cp311-cp311-macosx_10_12_x86_64.whl (685.6 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

File details

Details for the file modbus_rs-0.8.0.tar.gz.

File metadata

  • Download URL: modbus_rs-0.8.0.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for modbus_rs-0.8.0.tar.gz
Algorithm Hash digest
SHA256 eeedbb9e6b462d6f48f3af84c9e4ecfbeb436d8d5233a38407f00e57a9b2a62b
MD5 f9a310a84b006addb10d83aea8ff19bd
BLAKE2b-256 ba73e337f78382405638caea87d4a9a72f641dd0d7c2a08a0131235ef4bb6e74

See more details on using hashes here.

Provenance

The following attestation bundles were made for modbus_rs-0.8.0.tar.gz:

Publisher: release-python.yml on Raghava-Ch/modbus-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modbus_rs-0.8.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: modbus_rs-0.8.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 566.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for modbus_rs-0.8.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5d027a95491989958926236c5648471abdd6a02e269587a59eb01a0cfa6fb04a
MD5 457437fd81d59f1023d3de2cd4089659
BLAKE2b-256 9257371e305e2b11ba72c0db7cd11b952d37f7a77c4fa0f5a70a8b5d45aa7a4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for modbus_rs-0.8.0-cp311-cp311-win_amd64.whl:

Publisher: release-python.yml on Raghava-Ch/modbus-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modbus_rs-0.8.0-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for modbus_rs-0.8.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 bf41ede16ad3f12a9cace852e5fdf50f1954a5788b519a130f47ac520a12934c
MD5 9afa6cd520c17b8fdaf08418670aa239
BLAKE2b-256 c4f878cac0278a4c40c6562985d7fae034c3fd9c3f9da51c6777bf83bef44d3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for modbus_rs-0.8.0-cp311-cp311-manylinux_2_34_aarch64.whl:

Publisher: release-python.yml on Raghava-Ch/modbus-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modbus_rs-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for modbus_rs-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 db412f2b463147cacdc29c0d9b4e61604dc91da99eb95c4e0d4fcba9f79e3155
MD5 444e897967531c8f959d360bd4f9d6c1
BLAKE2b-256 48a44396c5b1930850c28218f4ba2dd7c504fadaa2e593bf5d7878d91ac2e711

See more details on using hashes here.

Provenance

The following attestation bundles were made for modbus_rs-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-python.yml on Raghava-Ch/modbus-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modbus_rs-0.8.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for modbus_rs-0.8.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a79a15b2cacc93b357aac4a0f1346444346350df929eec38aa1422de725cc1c8
MD5 c81d7756efc5b69b43a9838bf96b565b
BLAKE2b-256 0702c9787bf35a40352cafc113a6130611832819dabb3d532c25685176af90b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for modbus_rs-0.8.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release-python.yml on Raghava-Ch/modbus-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modbus_rs-0.8.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for modbus_rs-0.8.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 de1f187ff9df1d84c5c824b0e70d41fbdf946102a22ad18d3fb371ae1943ff93
MD5 c2d07e37c452a84c0a5bdb80d9303ae1
BLAKE2b-256 982e78671f776a273d1f64768181bdd65b16a8c87fa4884d9c85b272e81a730e

See more details on using hashes here.

Provenance

The following attestation bundles were made for modbus_rs-0.8.0-cp311-cp311-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on Raghava-Ch/modbus-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page