RPyC
   HOME

TheInfoList



OR:

RPyC (pronounced ''are-pie-see''), or Remote Python Call, is a
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (prog ...
library for
remote procedure call In distributed computing, a remote procedure call (RPC) is when a computer program causes a procedure (subroutine) to execute in a different address space (commonly on another computer on a shared computer network), which is written as if it were a ...
s (RPC), as well as
distributed computing Distributed computing is a field of computer science that studies distributed systems, defined as computer systems whose inter-communicating components are located on different networked computers. The components of a distributed system commu ...
. Unlike regular RPC mechanisms, such as
ONC RPC __NOTOC__ Open Network Computing (ONC) Remote Procedure Call (RPC), commonly known as Sun RPC is a remote procedure call system. ONC was originally developed by Sun Microsystems in the 1980s as part of their Network File System project. ONC is ba ...
,
CORBA The Common Object Request Broker Architecture (CORBA) is a standard defined by the Object Management Group (OMG) designed to facilitate the communication of systems that are deployed on diverse platforms. CORBA enables collaboration between sy ...
or
Java RMI The Java Remote Method Invocation (Java RMI) is a Java API that performs remote method invocation, the object-oriented equivalent of remote procedure calls (RPC), with support for direct transfer of serialized Java classes and distributed garba ...
, RPyC is transparent, symmetric, and requires no special decoration or definition languages. Moreover, it provides programmatic access to any pythonic element, be it functions, classes, instances or modules.


Features

* Symmetric—there is no difference between the client and the server—both can serve. The only different aspect is that the client is usually the side that initiates the action. Being symmetric, for example, allows the client to pass callback functions to the server. * Transparent—remote objects look and behave the same as local objects would. * Exceptions propagate like local ones * Allows for synchronous and asynchronous operation: ** Synchronous operations return a ''NetProxy'' (see below) ** Asynchronous operations return an AsyncResult, which is like
promise A promise is a commitment by someone to do or not do something. As a noun ''promise'' means a declaration assuring that one will or will not do something. As a verb it means to commit oneself by a promise to do or give. It can also mean a capacity ...
objects ** AsyncResults can be used as events * Threads are supported (though not recommended) * UNIX specific: server integration with
inetd inetd (internet service daemon) is a super-server Daemon (computer software), daemon on many Unix systems that provides Internet services. For each configured service, it listens for requests from connecting clients. Requests are served by spawn ...


Architecture

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 Virtual private network (VPN) is a network architecture for virtually extending a private network (i.e. any computer network which is not the public Internet) across one or multiple other networks which are either untrusted (as they are not c ...
for achieving this. Once a client is connected to the server, it has one of two ways to perform remote operations: * The ''modules'' property, that exposes the server's modules namespace: doc = conn.modules.sys.path or conn.modules xml.dom.minidom"parseString("<some>xml</some>"). * The ''execute'' function, that executes the given code on the server: 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.


Usage

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: * Distributed computing (splitting workload between machines) * Distributed testing (running tests that connect multiple platforms and abstracting hardware resources) * Remote administration (tweaking config files from one central place, etc.) * Tunneling or chaining (crossing over routable network boundaries)


Demo

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


History

RPyC is based on the work of Eyal Lotem (aka 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 Asynchrony is any dynamic far from synchronization. If and as parts of an asynchronous system become more synchronized, those parts or even the whole system can be said to be in sync. Asynchrony or asynchronous may refer to: Electronics and com ...
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 A capability is the ability to execute a specified course of action or to achieve a desired outcome. Capability may also refer to: Business, economics, science and engineering * Capability (systems engineering), the ability to execute a specifi ...
-based security model, explicit services, and various other improvements.


References


External links

* {{DEFAULTSORT:Rpyc Articles with example Python (programming language) code Python (programming language) libraries Remote procedure call Software using the MIT license