This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
|
| RPyC | |
|---|---|
| Developer | Tomer Filiba |
| Release | 17 December 2005 |
| Stable release | 6.0.0
/ 23 February 2024 |
| Written in | Python |
| Operating system | Cross-platform |
| Type | Remote Procedure Call |
| License | MIT License |
| Website | rpyc |
| Repository | |
RPyC (pronounced are-pie-see), or Remote Python Call, is a Python library for remote procedure calls (RPC), as well as distributed computing.
RPyC gives the programmer a slave python interpreter at his or her control. In this essence, RPyC is different from other RPCs, that require registration of resources prior to accessing them. As a result, using RPyC is much more straightforward, but this comes at the expense of security (you cannot limit access). RPyC is intended to be used within a trusted network, there are various schemes including VPN for achieving this.
Once a client is connected to the server, it has one of two ways to perform remote operations:
doc = conn.modules.sys.path or conn.modules["xml.dom.minidom"].parseString("<some>xml</some>").conn.execute("print 'hello world'")Remote operations return something called a NetProxy, which is an intermediate object that reflects any operation performed locally on it to the remote object. For example, conn.modules.sys.path is a NetProxy for the sys.path object of the server. Any local changes done to conn.modules.sys.path are reflected immediately on the remote object. Note: NetProxies are not used for simple objects, such as numbers and strings, which are immutable.
Async is a proxy wrapper, meaning, it takes a NetProxy and returns another that wraps it with asynchronous functionality. Operations done to an AsyncNetProxy return something called AsyncResult. These objects have a '.is_ready' predicate, '.result' property that holds the result (or blocks until it arrives), and '.on_ready' callback, which will be called when the result arrives.
Originally, RPyC was developed for managing distributed testing of products over a range of different platforms (all capable of running python). However, RPyC has evolved since then, and now its use cases include:
import rpyc
conn = rpyc.classic.connect("hostname") # assuming a classic server is running on 'hostname'
print(conn.modules.sys.path)
conn.modules.sys.path.append("lucy")
print(conn.modules.sys.path[-1])
# a version of 'ls' that runs remotely
def remote_ls(path):
ros = conn.modules.os
for filename in ros.listdir(path):
stats = ros.stat(ros.path.join(path, filename))
print("%d\t%d\t%s" % (stats.st_size, stats.st_uid, filename))
remote_ls("/usr/bin")
# and exceptions...
try:
f = conn.builtin.open("/non/existent/file/name")
except IOError:
pass
RPyC is based on the work of Eyal Lotem (a.k.a. Lotex) on PyInvoke, which is no longer maintained. The first public release was 1.20, which allowed for symmetric and transparent RPC, but not for asynchronous operation. Version 1.6, while never publicly released, added the concept of 'events', as a means for the server to inform the client. Version 2.X, the first release of which was 2.2, added thread synchronization and the Async concept, which can be used as a superset of events. Version 2.40 adds the execute method, that can be used to execute code on the other side of the connection directly. RPyC 3 is a complete rewrite of the library, adding a capability-based security model, explicit services, and various other improvements.