Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

https://travis-ci.org/AdvancedClimateSystems/uModbus.svg https://coveralls.io/repos/AdvancedClimateSystems/uModbus/badge.svg?service=github https://img.shields.io/pypi/v/uModbus.svg

uModbus

uModbus or (μModbus) is a pure Python implementation of the Modbus protocol as described in the MODBUS Application Protocol Specification V1.1b3. uModbus implements both a Modbus client (or master in Modbus language) and a Modbus server (or slave). The “u” or “μ” in the name comes from the the SI prefix “micro-”. uModbus is very small and lightweight. The source can be found on GitHub. Documentation is available at Read the Docs.

Quickstart

Creating a Modbus server is easy:

#!/usr/bin/env python
# scripts/examples/simple_data_store.py
import logging
from socketserver import TCPServer
from collections import defaultdict

from umodbus import get_server, RequestHandler, conf
from umodbus.utils import log_to_stream

# Add stream handler to logger 'uModbus'.
log_to_stream(level=logging.DEBUG)

# A very simple data store which maps addresss against their values.
data_store = defaultdict(int)

# Enable values to be signed (default is False).
conf.SIGNED_VALUES = True

TCPServer.allow_reuse_address = True
app = get_server(TCPServer, ('localhost', 502), RequestHandler)


@app.route(slave_ids=[1], function_codes=[3, 4], addresses=list(range(0, 10)))
def read_data_store(slave_id, function_code, address):
    """" Return value of address. """
    return data_store[address]


@app.route(slave_ids=[1], function_codes=[6, 16], addresses=list(range(0, 10)))
def write_data_store(slave_id, function_code, address, value):
    """" Set value for address. """
    data_store[address] = value

if __name__ == '__main__':
    try:
        app.serve_forever()
    finally:
        app.shutdown()
        app.server_close()

Doing a Modbus request requires even less code:

#!/usr/bin/env python
# scripts/examples/simple_tcp_client.py
import socket

from umodbus import conf
from umodbus.client import tcp

# Enable values to be signed (default is False).
conf.SIGNED_VALUES = True

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 502))

# Returns a message or Application Data Unit (ADU) specific for doing
# Modbus TCP/IP.
message = tcp.write_multiple_coils(slave_id=1, starting_address=1, values=[1, 0, 1, 1])

# Response depends on Modbus function code. This particular returns the
# amount of coils written, in this case it is.
response = tcp.send_message(message, sock)

sock.close()

Features

The following Modbus functions have been implemented:

  • 01: Read Coils

  • 02: Read Discrete Inputs

  • 03: Read Holding Registers

  • 04: Read Input Registers

  • 05: Write Single Coil

  • 06: Write Single Register

  • 15: Write Multiple Coils

  • 16: Write Multiple Registers

Other featues:

  • Support for signed and unsigned register values.

Roadmap

uModbus is far from complete. The next, unordered list shows what is going to be implemented in the future:

  • Support for all Modbus functions

  • Modbus RTU

  • Use asyncio for handling of requests

  • Other Modbus ‘flavours’, so uModbus is able to handle 32 bit values.

License

uModbus software is licensed under Mozilla Public License. © 2015 Advanced Climate Systems.

Metadata

Release files for uModbus 0.6.0a2

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

Source distribution (sdist)

Source distribution for uModbus 0.6.0a2
File Size Uploaded Provenance Actions
uModbus-0.6.0a2.tar.gz 22.1 kB Without provenance Details for uModbus-0.6.0a2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uModbus 0.6.0a2
File Interpreter ABI Platform Actions
uModbus-0.6.0a2-py2.py3-none-any.whl Python 3, Python 2 none any Details for uModbus-0.6.0a2-py2.py3-none-any.whl

Total release size: 49.0 kB

Release files / uModbus-0.6.0a2.tar.gz

Download URL uModbus-0.6.0a2.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6d008c60faa1938f9f4d6c3bce37fcb7b2a8985132e64b37e4e7e0c019cda445
BLAKE2b-256 checksum
How to use checksums
b50a28b4c56e4d2b9ade5df9a2a5419dbc342f99449b69ac82e8d027cd016086
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / uModbus-0.6.0a2-py2.py3-none-any.whl

Download URL uModbus-0.6.0a2-py2.py3-none-any.whl
Size 26.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e2a8cb3cb7074151f6eaac5bdff0d3333d588735b4efef3c380acaa59b7731af
BLAKE2b-256 checksum
How to use checksums
61ad2a5c3f6f90c194e21333b815efe005472fe229044fab62bb3b254aeea3cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for uModbus 0.6.0a2

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