Package: pymodbus
Pymodbus is a full Modbus protocol implementation offering client/server with synchronous/asynchronous API a well as simulators.Current release is3.6.4.Bleeding edge (not released) isdev.All changes are described inrelease notesand all API changes aredocumentedA big thanks to all thevolunteersthat helps make pymodbus a great project.Source code ongithubPymodbus in a nutshellPymodbus consist of 5 parts:client, connect to your favorite device(s)server, simulate your favorite device(s)repl, a commandline text based client/server simulatorsimulator, an html based server simulatorexamples, showing both simple and advances usageCommon featuresFull modbus standard protocol implementationSupport for custom function codessupport serial (rs-485), tcp, tls and udp communicationsupport all standard frames: socket, rtu, rtu-over-tcp, tcp and asciidoes not have third party dependencies, apart from pyserial (optional)very lightweight projectrequires Python >= 3.8thorough test suite, that test all corners of the libraryautomatically tested on Windows, Linux and MacOS combined with python 3.8 - 3.12strongly typed API (py.typed present)The modbus protocol specification: Modbus_Application_Protocol_V1_1b3.pdf can be found onmodbus orgClient Featuresasynchronous API and synchronous API for applicationsvery simple setup and call sequence (just 6 lines of code)utilities to convert int/float to/from multiple registerspayload builder/decoder to help with complex dataClient documentationServer Featuresasynchronous implementation for high performancesynchronous API classes for conveniencesimulate real life devicesfull server control context (device information, counters, etc)different backend datastores to manage register valuescallback to intercept requests/responseswork on RS485 in parallel with other devicesServer documentationREPL Featuresserver/client commandline emulatoreasy test of real device (client)easy test of client app (server)simulation of broken requests/responsessimulation of error responses (hard to provoke in real devices)REPL documentationSimulator Featuresserver simulator with WEB interfaceconfigure the structure of a real devicemonitor traffic onlineallow distributed team members to work on a virtual device using internetsimulation of broken requests/responsessimulation of error responses (hard to provoke in real devices)Simulator documentationUse CasesThe client is the most typically used. It is embedded into applications,
where it abstract the modbus protocol from the application by providing an
easy to use API. The client is integrated into some well known projects likehome-assistant.Although most system administrators will find little need for a Modbus
server, the server is handy to verify the functionality of an application.The simulator and/or server is often used to simulate real life devices testing
applications. The server is excellent to perform high volume testing (e.g.
houndreds of devices connected to the application). The advantage of the server is
that it runs not only a “normal” computers but also on small ones like Raspberry PI.Since the library is written in python, it allows for easy scripting and/or integration into their existing
solutions.For more information please browse the project documentation:https://readthedocs.org/docs/pymodbus/en/latest/index.htmlInstallThe library is available on pypi.org and github.com to install withpipfor those who just want to use the librarygit clonefor those who wants to help or just are curiousBe aware that there are a number of project, who have forked pymodbus andseems just to provide a version frozen in timeextended pymodbus with extra functionalityThe latter is not because we rejected the extra functionality (we welcome all changes),
but because the codeowners made that decision.In both cases, please understand, we cannot offer support to users of these projects as we do not known
what have been changed nor what status the forked code have.A growing number of Linux distributions include pymodbus in their standard installation.You need to have python3 installed, preferable 3.11.Install with pipYou can install using pip by issuing the following
commands in a terminal window:pip install pymodbusIf you want to use the serial interface:pip install pymodbus[serial]This will install pymodbus with the pyserial dependency.Pymodbus offers a number of extra options:repl, needed by pymodbus.replserial, needed for serial communicationsimulator, needed by pymodbus.simulatordocumentation, needed to generate documentationdevelopment, needed for developmentall, installs all of the abovewhich can be installed as:pip install pymodbus[<option>,...]It is possible to install old releases if needed:pip install pymodbus==3.5.4Install with githubOn github, forkhttps://github.com/pymodbus-dev/pymodbus.gitClone the source, and make a virtual environment:git clone git://github.com/<your account>/pymodbus.git
cd pymodbus
python3 -m venv .venvActivate the virtual environment, this command needs repeated in every new terminal:source .venv/bin/activateTo get a specific release:git checkout v3.5.2or the bleeding edge:git checkout devSome distributions have an old pip, which needs to be upgraded:pip install –upgrade pipInstall required development tools:pip install ".[development]"Install all (allows creation of documentation etc):pip install “.[all]”Install git hooks, that helps control the commit and avoid errors when submitting a Pull Request:cp githooks/* .git/hooksThis installs dependencies in your virtual environment
with pointers directly to the pymodbus directory,
so any change you make is immediately available as if installed.The repository contains a number of important branches and tags.devis where all development happens, this branch is not always stable.masteris where are releases are kept.vX.Y.Z(e.g. v2.5.3) is a specific releaseExample CodeFor those of you that just want to get started fast, here you go:from pymodbus.client import ModbusTcpClient

client = ModbusTcpClient('MyDevice.lan')
client.connect()
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()We provide a couple of simple ready to go clients:async clientsync clientFor more advanced examples, check outExamplesincluded in the
repository. If you have created any utilities that meet a specific
need, feel free to submit them so others can benefit.Also, if you have a question, pleasecreate a post in discussions q&a topic,
so that others can benefit from the results.If you think, that something in the code is broken/not running well, pleaseopen an issue,
read the Template-text first and then post your issue with your setup information.Example documentationContributingJust fork the repo and raise your Pull Request againstdevbranch.We always have more work than time, so feel free to open a discussion / issue on a theme you want to solve.If your company would like your device tested or have a cloud based device
simulation, feel free to contact us.
We are happy to help your company solve your modbus challenges.That said, the current work mainly involves polishing the library and
solving issues:Fixing bugs/feature requestsArchitecture documentationFunctional testing against any reference we can findThere are 2 bigger projects ongoing:rewriting the internal part of all clients (both sync and async)Add features to and simulator, and enhance the web designDevelopment InstructionsThe current code base is compatible with python >= 3.8.Here are some of the common commands to perform a range of activities:source .venv/bin/activate   <-- Activate the virtual environment
./check_ci.sh               <-- run the same checks as CI runs on a pull request.Make a pull request:git checkout dev          <-- activate development branch
git pull                  <-- update branch with newest changes
git checkout -b feature   <-- make new branch for pull request
... make source changes
git commit                <-- commit change to git
git push                  <-- push to your account on github

on github open a pull request, check that CI turns green and then wait for review comments.Test your changes:cd test
pytestArchitectureThere are no documentation of the architecture (help is welcome), but most classes and
methods are documented:Pymodbus internalsGenerate documentationRemarkAssumes that you have installed documentation tools:;pip install “.[documentation]”to build do:cd doc
./build_htmlThe documentation is available in <root>/build/htmlRemark: this generates a new zip/tgz file of examples which are uploaded.License InformationReleased under theBSD License