1. Application Programming Interface (API)

pushy.connect(target[, python="python"[, **kwargs]])

Create a Pushy connection.

Parameters:
  • target (string) –

    Identifies which transport to use, and the endpoint to connect to. The argument must be formatted as: transport:[transport-specific-address].

    >>> pushy.connect("local:")
    <pushy.client.PushyClient object at ...>
    
    >>> pushy.connect("ssh:remotehost")
    <pushy.client.PushyClient object at ...>
    
  • python (string) – Specifies the path to the Python executable to invoke on the remote host which is being connected to. By default it is simply “python”, in which case standard PATH lookup will be used.

Some transports will require additional information to create a connection, such as a username and password. To support this, all keyword arguments are passed through to the transport’s pushy.transport.Popen() function. The address component of target is passed to the Popen function with the name address. For details on the keyword arguments expected by the builtin transports, see pushy.transport.

class pushy.PushyClient

This class is instantiated by pushy.connect(), and is the primary interface for interacting with the remote interpreter. It provides methods for evaluating Python expressions, copying files between local and remote hosts, and for obtaining references to Python modules in the remote interpreter.

modules

Provides access to the remote interpreter’s modules. Accessing an attribute of modules is equivalent to importing a module.

>>> conn = pushy.connect("local:")
>>> conn.modules.os
<module 'os' from 'C:\Python26\lib\os.pyc'>
>>> os.getpid()
4772
>>> conn.modules.os.getpid()
5564
gc_enabled

Boolean flag to specify whether proxies should be garbage collected or not. Disabling garbage collection may improve the speed of Pushy, at the cost of memory growth as new objects are proxied. Garbage collection is enabled by default.

gc_interval

Time in seconds between reconciliation of garbage collected objects.

If gc_enabled is set to True, then object proxies may be garbage collected. When object proxies are garbage collected, their remote counterpart must be also be deleted (reconciled). The garbage collection process will enqueue deletions and, after gc_interval seconds have elapsed since the previous remote-deletion, send a message to the peer to delete the objects enqueued by the garbage collector. The default garbage collection interval is five seconds.

close()

Close the connection.

>>> conn = pushy.connect("local:")
>>> conn.close()
compile(code[, mode="exec"])

Compiles Python source or function objects in the remote Python interpreter, returning proxied code objects or function objects respectively.

Parameters:
  • code (string or function) – A string representing a Python expression, or a function object to be recompiled in the remote interpreter.
  • mode (string) – The compilation mode for compiling Python source (ignored for function compilation).
>>> conn = pushy.connect("local:")
>>> conn.compile("1+2", "eval")      # Returns a code object.
>>> conn.compile(lambda a, b: a + b) # Returns a function object.
eval(code[, globals=None[, locals=None]])

Evaluate an expression or code object in the remote Python interpreter.

Parameters:
  • code (string or code) – A string representing a Python expression, or a code object as returned by compile().
  • globals (dict) – A dictionary for global variables. If locals is not specified, then globals will be used for both global and local variables.
  • locals (any mapping type) – A dictionary for local variables.
>>> conn = pushy.connect("local:")
>>> assert conn.eval("1+2") == 3
>>> remote_str_type = conn.eval("str")
execute(source[, globals=None[, locals=None]])

Executes Python source code in the remote interpreter. This is a shortcut to eval(compile(source), globals, locals).

Parameters:
  • source (string) – A stirng representing a Python statement.
  • globals (dict) – A dictionary for global variables. If locals is not specified, then globals will be used for both global and local variables.
  • locals (any mapping type) – A dictionary for local variables.
>>> conn = pushy.connect("local:")
>>> locals_ = {}
>>> conn.execute("def abc():\n\tprint 123", locals=locals_)
>>> locals_["abc"]()
123
getfile(remote_path, local_path)

Copy a file from the remote host to the local host. If the transport class defines a getfile method, that will be used to perform the transfer. Otherwise, Pushy will fall back to a relatively inefficient, transport-independent method.

>>> conn = pushy.connect("local:")
>>> conn.getfile("/remote/path/to/foo.txt", "/local/path/to/bar.txt")
putfile(local_path, remote_path)

Copy a file from the local host to the remote host. If the transport class defines a putfile method, that will be used to perform the transfer. Otherwise, Pushy will fall back to a relatively inefficient, transport-independent method.

>>> conn = pushy.connect("local:")
>>> conn.putfile("/local/path/to/foo.txt", "/remote/path/to/bar.txt")

Previous topic

pushy – remote interpreter access

Next topic

2. Builtin Transport Modules

This Page