Skip to main content

ctypes-modbus

A lightweight Python Modbus client implemented as a thin wrapper around libmodbus.

This project is similar to pylibmodbus, but uses the built-in ctypes instead of cffi, eliminating external Python dependencies and reducing memory usage while maintaining comparable performance.

Dependencies

  • python3.8+
  • libmodbus5

Installation

  • apt-get install libmodbus5
  • pip install ctypes-modbus

Usage

import logging

from ctypes_modbus import Modbus

logging.basicConfig(level=logging.DEBUG)

mb = Modbus.RTU("/dev/ttyS0", 115200, "N", 8, 1, logger=logging.getLogger())
mb.set_slave(1)
# or
# mb = Modbus.TCP("localhost", 1502)

mb.connect()
mb.write_registers(0, [16, 17])
data = mb.read_registers(0, 2)
logging.info("REGISTERS: %s", [hex(n) for n in data])

Benchmarks

Reading one million registers.

*The memory plots exclude the Python interpreter overhead (~10.3 MB).

benchmark-results

benchmark.csv

Package;Time;RSS
ctypes_modbus;30.28;4596
pylibmodbus;28.48;7672
pymodbus;40.73;17328

License

MIT

Metadata

Release files for ctypes-modbus 0.1.0

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

Source distribution (sdist)

Source distribution for ctypes-modbus 0.1.0
File Size Uploaded Provenance Actions
ctypes_modbus-0.1.0.tar.gz 6.5 kB Without provenance Details for ctypes_modbus-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ctypes-modbus 0.1.0
File Interpreter ABI Platform Actions
ctypes_modbus-0.1.0-py3-none-any.whl Python 3 none any Details for ctypes_modbus-0.1.0-py3-none-any.whl

Total release size: 13.6 kB

Release files / ctypes_modbus-0.1.0.tar.gz

Download URL ctypes_modbus-0.1.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
549033688832d4f1230f7d0ddde8b1c831206b005a15b142ddde7c46dac0f8b7
BLAKE2b-256 checksum
How to use checksums
d4470c83cfe03c55fa29c82462f0c9dfc1cfb9044fd7e2312888d3eda527652a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / ctypes_modbus-0.1.0-py3-none-any.whl

Download URL ctypes_modbus-0.1.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3be7b2e3a7e4812e142f7ac387aa7d0da5fdfdc59a74502bafba36454c409d91
BLAKE2b-256 checksum
How to use checksums
e4c5e86a1e699fd54a4191ab349a9fde1c411fb506f921c704e7f208534741c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for ctypes-modbus 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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