Skip to main content

tModbus

Homepage Documentation GitHub License Release Python Versions Testing

About

A modern Python Modbus library that is fully typed and well-tested.

Modbus is based on the master/slave communication pattern. We choose to use the terminology client and server instead, as it is more clear.

Features

  • Pure Python library with minimal dependencies
  • Fully typed
  • Full test coverage
  • Support for Modbus TCP, RTU, ASCII, RTU-over-TCP and UDP clients
  • Support for Modbus TCP, RTU, ASCII, RTU-over-TCP and UDP servers
  • Support for TCP over SSL/TLS client and server connections, including Modbus/TCP Security (mbaps) with mutual authentication and role-based access control (RBAC)
  • Auto reconnect and retry functionality (which can be enabled optionally)
  • Extensible with custom Modbus functions and exception codes
  • Open source (BSD)

Supported function codes

  • Read coils (0x01)
  • Read discrete inputs (0x02)
  • Read holding registers (0x03)
  • Read input registers (0x04)
  • Write single coil (0x05)
  • Write single register (0x06)
  • Read exception status (0x07)
  • Write multiple coils (0x0F)
  • Write multiple registers (0x10)
  • Report server ID (0x11)
  • Read file record (0x14)
  • Write file record (0x15)
  • Mask write register (0x16)
  • Read/write multiple registers (0x17)
  • Read FIFO queue (0x18)
  • Read device identification (0x2B / 0x0E)

Examples

A simple example of an Async TCP client:

import asyncio

from tmodbus import create_async_tcp_client


async def main() -> None:
    """Show example of reading a Modbus register."""
    async with create_async_tcp_client("127.0.0.1", 502, unit_id=1) as client:
        response = await client.read_holding_registers(start_address=100, quantity=2)
        print("Contents of holding registers 100 and 101: ", response)


if __name__ == "__main__":
    asyncio.run(main())

Various client and server examples (including Modbus Security) can be found in the examples folder.

Dependencies

async-serial

This library uses serialx to access the serial port when using async RTU or ASCII.

Use pip install tmodbus[async-serial] to install.

Changelog & releases

This repository keeps a change log using GitHub's releases functionality. The format of the log is based on Keep a Changelog.

Releases are based on Semantic Versioning, and use the format of MAJOR.MINOR.PATCH. In a nutshell, the version will be incremented based on the following:

  • MAJOR: Incompatible or major changes.
  • MINOR: Backwards-compatible new features and enhancements.
  • PATCH: Backwards-compatible bugfixes and package updates.

Contributing

This is an active open-source project. We are always open to people who want to use the code or contribute to it.

We've set up a separate document for our contribution guidelines.

Thank you for being involved! :heart_eyes:

Setting up a development environment

This Python project is fully managed using the uv dependency manager.

You need at least:

  • Python 3.12+
  • uv

To install all packages, including all development requirements:

uv sync  --all-extras --dev

As this repository uses the pre-commit framework, all changes are linted and tested with each commit. You can run all checks and tests manually, using the following command:

uv run pre-commit run --all-files

To run just the Python tests:

uv run pytest

Protocol-Specification

Download files

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

Source Distribution

tmodbus-0.5.2.tar.gz (157.6 kB view details)

Uploaded Source

Built Distribution

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

tmodbus-0.5.2-py3-none-any.whl (94.2 kB view details)

Uploaded Python 3

File details

Details for the file tmodbus-0.5.2.tar.gz.

File metadata

  • Download URL: tmodbus-0.5.2.tar.gz
  • Upload date:
  • Size: 157.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tmodbus-0.5.2.tar.gz
Algorithm Hash digest
SHA256 8701c4d9a513f82dc53be893354db6f7d867db4803eb1619ce6a8347bdcb5fa7
MD5 3da28e7778eb60cfb0858da1cc8a5e6b
BLAKE2b-256 ad2b9d0acb91671bb9b43ea0f377f1227c39db8499ac04e2f308c79f7db7c0b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for tmodbus-0.5.2.tar.gz:

Publisher: pypi-publish.yml on wlcrs/tmodbus

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

File details

Details for the file tmodbus-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: tmodbus-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 94.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tmodbus-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ea82215774b29079e6cb1bddbde611ef10f965501dc8a006f663911bd6cee003
MD5 dd05e6759a6cbf775808bf2626d909b4
BLAKE2b-256 a23435edd407c79c70cf8f430cb70e8008df105a68a5a36cc856652a8de9bc66

See more details on using hashes here.

Provenance

The following attestation bundles were made for tmodbus-0.5.2-py3-none-any.whl:

Publisher: pypi-publish.yml on wlcrs/tmodbus

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

Release history Release notifications | RSS feed

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

This release

0.5.2 This release

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

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