Getting Started¶
Installing¶
To install Pizco you need to to install PyZMQ following the instructions here. If you are having trouble at this step, a few Python distributions like EPD and Anaconda have PyZMQ preinstalled.
Then install, Pizco using pip or easy_install:
$ easy_install pizco
or:
$ pip install pizco
Basic usage¶
Consider the:
from myproject import Robot
robot = Robot()
print(robot.name)
robot.move_arm()
robot.age = 28
Pizco provides two classes t:
- Server: wraps an object and exposes its attributes via a ZMQ socket.
- Proxy: connects to a server, redirects attribute request to it, and collect the response.
Creating a Server is quite simple, just instantiate a Server using the object as the first parameter:
# This is your stuff
from myproject import Robot
from pizco import Server
server = Server(Robot())
If no endpoint is given, the server will bind to a random tcp port.
You can specify the endpoint with the second argument:
server = Server(Robot(), 'tcp://127.0.0.1:8000')
Any valid ZMQ endpoints is valid:
inproc: local in-process (inter-thread) communication transport
example: inproc://robbie-the-robot
ipc: local inter-process communication transport
example: ipc://robbie-the-robot
tcp: unicast transport using TCP
example: tcp://127.0.0.1:8000
In the client side, you need to create a proxy:
from pizco import Proxy
robot = Proxy('tcp://127.0.0.1:8000')
and now you can use the proxy as if it was the actual object:
print(robot.name)
robot.move_arm()
robot.age = 28
Notice that the only needed change was to the initialization code.
Remote exceptions¶
Exception in the served object are caught remotely and re-raised by the proxy and therefore the following code:
try:
robot.age = input()
except ValueError as ex:
print('That is not a valid age for the robot')
will work the same way if the robot is the actual object or just a Proxy to it.
Note
The remote traceback is not propagated the proxy in the current version of Pizco.