pyrpc
A tiny RPC bridge between Arduino and Python using MsgPack over serial.
It lets you expose C++ functions on an Arduino board and call them directly from Python, with automatic (de)serialization of basic types, containers, and structs.
Arduino side
Install pyrpc from the Arduino Library Manager.
#include <pyrpc.h>
double sum(int i, float d) {
return i + d;
}
void setup() {
Serial.begin(115200);
pyrpc::begin();
// register an onConnect procedure (called when Python connects)
pyrpc::registerOnConnect([]() {
// do whatever you need here
});
pyrpc::registerRpc(
"sum",
sum,
F("@brief sum two numbers @return double @arg i integer @arg d float")
);
}
void loop() {
pyrpc::process(); // handle incoming RPC calls
}
Upload this sketch to your Arduino (baudrate must match the Python side).
Python side
Install the Python package:
pip install ardupyrpc
Call your Arduino procedures from Python:
from ardupyrpc import Rpc
# on_connect=True sends an onConnect message to the Arduino after connecting
rpc = Rpc("/dev/ttyACM0", baudrate=115200, on_connect=True)
print(rpc.help) # shows all available remote procedures
result = rpc.call("sum", 3, 1.5)
print("sum result:", result)
rpc.close()
A more complete example is available in the examples/ folder.
Current limitations
When STL containers are not supported, there is a limation of 128 bytes for the serialized data. This means that complex nested structures may not work as expected and the help command may fail to retrieve the full documentation.
Metadata
Release files for ardupyrpc 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ardupyrpc-1.0.0.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ardupyrpc-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / ardupyrpc-1.0.0.tar.gz
| Download URL | ardupyrpc-1.0.0.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f68554385eac321e13d5349abfb0b7aa336dfed333aa4de0da1a767ff6814da0
|
|
BLAKE2b-256 checksum How to use checksums |
a0f80e123a4774eac12caf78188ab2c773ec4d750124f617f798f530e0796dca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / ardupyrpc-1.0.0-py3-none-any.whl
| Download URL | ardupyrpc-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c35ce362a4828ca1ed806e95df471e223307aa89c9ca7bc08db8bdf2b3f9036b
|
|
BLAKE2b-256 checksum How to use checksums |
d1be72d62e5d158f73416d0a19a6c29ff8f5ad9ec42780adbe66fe016c1d7f3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|