Skip to main content

A Python client to remotely access the R statistic package via network

Project description

What pyRserve does

pyRserve is a library for connecting Python to R (an excellent statistic package). Running Rserve in R attaches the R-interpreter to a network socket, waiting for pyRserve to connect to it. Through such a connection, variables can be get and set in R from Python, and also R-functions can be called remotely.

In contrast to rpy or rpy2 the R process does not have to run on the same machine, it can run on a remote machine and all variable access and function calls will be delegated there through the network.

Furthermore - and this makes everything feel very pythonic - all data structures will automatically be converted from native R to native Python and numpy types and back.

Supported platforms

This package has been mainly developed under Linux, and hence should run on all standard unix platforms, as well as on MacOS. pyRserve has also been successfully used on Windows machines. Unittests have been used on the Linux and MacOS side, however they might just work fine for Windows.

It has been tested to work with Python 2.7.x, 3.6 to 3.9.

The latest development has been tested with some previous and current versions of R and Rserve.

License

pyRserve has been written by Ralph Heinkel (ralph-heinkel.com) and is released under MIT license.

Quick installation

From your unix/macOS,windows command line run:

pip install pyRserve

For a fully functional setup also R and Rserve have to be installed. See section installation in the pyRserve documentation for instructions.

Quick usage

Open a first shell and start up the R server, by calling the module Rserve that provides the actual network connectivity for R:

$ R CMD Rserve

R (Rserve) will now listen on port 6311 (on localhost). Of course Rserve can be configured to listen on an exposed port and hence will be accessible from remote hosts as well.

Open a second shell, start Python, import pyRserve, and initialize the connection to Rserve:

$ python
>>> import pyRserve
>>> conn = pyRserve.connect()

The default connection will be done on localhost:6311. Other hosts can be reached by calling pyRserve.connect(host=..., port=...) as well.

The conn object provides a namespace called conn.r that directly maps all variables and other global symbols (like functions etc) and hence makes them accessible from Python.

Now create a vector in R, access the vector from Python (will be converted into a numpy array), and call the sum()-function in R:

>>> conn.r("vec <- c(1, 2, 4)")
>>> conn.r.vec                 # access vector 'vec' as an attribute of 'conn.r'
array([1., 2., 4.])
>>> conn.r.sum(conn.r.vec)     # 'sum' in running in the R-interpreter, returning the result to Python
7.0

The other way around also works:

>>> conn.r.somenumber = 444         # set a variable called 'somenumber' in the R interpreter...
>>> conn.r("somenumber * 2")        # ... and double the number
888.0

Source code repository

pyRserve is now hosted on GitHub at https://github.com/ralhei/pyRserve.

Documentation

Documentation can be found at https://pyrserve.readthedocs.io.

Support

For discussion of pyRserve and getting help please use the Google newsgroup available at http://groups.google.com/group/pyrserve.

Issues with the code (like bugs, etc.) should be reported on GitHub at https://github.com/ralhei/pyRserve/issues.

Missing features

  • Authentication is implemented in Rserve but not yet in pyRserve

  • TLS encryption is not implemented yet in pyRserve. However using ssh tunnels can solve security issues in the meantime (see documentation).

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

pyRserve-1.0.0b1.tar.gz (30.9 kB view details)

Uploaded Source

Built Distribution

pyRserve-1.0.0b1-py2.py3-none-any.whl (32.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pyRserve-1.0.0b1.tar.gz.

File metadata

  • Download URL: pyRserve-1.0.0b1.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for pyRserve-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 dc1521a18647dcdaea2313da89854bdb23f856d7492cbb434a5bacb2ae2825b2
MD5 56bc77c092c9ddc96c392a0de580e010
BLAKE2b-256 1e8f7609ee079e1b320fde3473d42b0e6e438314eeb2884a26f2f960b8d897f4

See more details on using hashes here.

File details

Details for the file pyRserve-1.0.0b1-py2.py3-none-any.whl.

File metadata

  • Download URL: pyRserve-1.0.0b1-py2.py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for pyRserve-1.0.0b1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5b81794e64fae70ded7adf76c6412ecf92b1e8854d3bba355bb7db92423cea32
MD5 cbb5f02c4f765e544fa59dbe9e45ea25
BLAKE2b-256 d3aed7309a39acd043c399727ba64a3498d213a402db01b4beb01371781a1a50

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page