A TCP-based server/client library for making method calls from a client to a python object on the server
Project description
python-remote-object
Python TCP server and client which allows clients to make calls and get returns from a python object instantiated on the server.
This package was originally developed to be used along side pyUSB
, serial
,
pyVISA
, etc, where an external hardware component could be connected to a
computer for which a python-based API for the component already existed. This
package could then take an instance of that python driver, and allow other
computers (potentially off-site) to make API calls and so control the external
hardware remotely.
For example, one could connect a raspberry pi up to their digital oscilloscope via usb, and now your oscilloscope is "wifi-enabled"
Security Note
ONLY INTERACT WITH SERVERS THAT YOU TRUST. The remote_object.client.Client
object uses pickle.load
to deserialize data and objects from the server. This
process is able to execute arbitrary code on your machine. This can easily be
exploited by malicious agents to compromise your system. The pickle
library,
and by extension python-remote-object
, leave it to the user to make wise
decisions about what they chose to unpickle. Be smart.
Installation
Pip
To get the current stable version, install using pip:
$ pip3 install remote_object
Development Version
To get the development version, clone this repo, then inside the folder create a python3
virtual environment, activate it, and install using setuptools:
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ python3 setup.py install
Basic Use
If you have an instance of a python object, pyobj
, using the base server
class remote_object.server.Server
will allow you to create a TCP server
which hosts pyobj
.
On the client end, you must create an instance of the remote_object.client.Client
object pointed at the server's address and port. By default, calling a method
on the Client
instance will pass that call across the TCP connection to the
server, where the Server
instance will make that method call on pyobj
. Any
errors or return values will then be passed back to the Client
instance and
raised or returned respectively.
For example, the server might look like:
from remote_object.server import Server
HOST, PORT = 'your-ip-address', 9999
class Test:
def __init__(self):
self.a = "attribute a"
def __repr__(self):
return "<Test Class>"
def b(self,message):
return "method b: " + message
with Server((HOST, PORT),Test()) as server:
server.serve_forever()
The client might then look like:
from remote_object.server import Client
with Client(HOST, PORT) as client:
print(client) # prints: <Remote Wrapper <Test Class>>
print(client.a()) # prints "attribute a"
print(client.b("Hello!")) # prints "method b: Hello!"
print(client.c()) # raises AttributeError
Note here that attributes are treated like methods without arguments, and
attempting to call method which does not exist will raise an AttributeError
.
See examples/errors
for additional info.
Development
For development, clone this directory, then have fun! Pro-tip: setup a python virtual environment in the main directory:
$ python3 -m venv venv
$ source venv/bin/activate
Installing
(venv) $ python3 setup.py install
Creating source packages
(venv) $ python3 setup.py sdist bdist_wheel
Uploading to PyPI
(venv) $ python3 -m twine upload dist/*
See: [https://packaging.python.org/tutorials/packaging-projects/]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file remote-object-0.2.4.tar.gz
.
File metadata
- Download URL: remote-object-0.2.4.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c167763bbc47ec4327516f315d4016ad8dfa2dad3dbc8c92927bbcd1d439136 |
|
MD5 | 2fb9d2e683f8de62f6f4baa8c627b720 |
|
BLAKE2b-256 | b4d09a5b02e0e915d0871932b7c27b52e0e0e75cad270449d57e86a0df596781 |
File details
Details for the file remote_object-0.2.4-py3.7.egg
.
File metadata
- Download URL: remote_object-0.2.4-py3.7.egg
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52cacd4538c85761ce6f572e059e13317ed3bb91f6a3acaf1ec197d34c25a73a |
|
MD5 | 4f86e87603c0c8458fe15aa8e0b9dd5e |
|
BLAKE2b-256 | 47397110d1ecf975a40527bb3e5fc8bf97a2815712582b555ded99717fd46647 |
File details
Details for the file remote_object-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: remote_object-0.2.4-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e37928f94f5201603236ad5da96e8b74b85759af891d6e58e05466059afbb031 |
|
MD5 | b61f30cbbbf758c2e20aa9ae12c6103c |
|
BLAKE2b-256 | 3227a46ae71fedcef2dd36a173c5ccf48bfa6f7a75da1a67e18ff709bbd6931b |