Skip to main content

Polyester

Polyester makes it possible to use R from Python by running R in a background process and communicating through a lightweight message protocol.

The goal is simplicity and reliability — especially on Windows — while keeping the design extensible to other languages in the future.


Quick Example

from polyester import RInterpreter

# Start an R interpreter
R = RInterpreter()

# Simple calculations (both return a RemoteRObject)
x = R.eval("sin(100)")
y = R.env.cos(100)

# Get results in python
print(x.fetch(), y.fetch())

# Bring a dataframe from R to Python (different backends supported)
iris_df = R.eval("iris").fetch('polars')
print(iris_df.head())

# Print head without first fetching to python
R.print(R.eval("head(iris)"))

Core Concepts

Polyester revolves around a single concept: an interpreter.

An interpreter manages:

  • A background R process
  • A private remote environment
  • Communication over JSON Lines
  • Data exchange using Apache Arrow

Interpreter API

An interpreter supports the following operations:

Operation Parameters Returns Description
insert x: simple/dataframe RemoteObject Send Python data to R
get x: Remote simple/dataframe Retrieve data from R
R.env.name or R.env[name] name: str RemoteName (lazy) Reference a remote symbol
R.env.name = value or R.env[name] = value name: str, value: simple/Remote – Assign remotely
eval code: str/Template RemoteObject Evaluate R code
exec code: str/Template – Execute R code (no return value)
call f: Remote, *args, **kwargs RemoteObject Call a remote function
print x: str – Print a remote object
module x: str RemoteModule Reference a remote namespace or package
expression x: str RemoteExpression Create a remote expression

Remote names and objects

  • RemoteObject A concrete object that exists in the remote R environment. Automatically cleaned up when the Python object is deleted.

  • RemoteName A lazy reference to a symbol or expression in R. It may or may not exist until evaluated.

Example:

R.env.x = 10
result = R.get(R.env.x)   # 10

# This can also be written the following way
result = R.env.x.fetch()   # 10

The following methods can be used on both RemoteName and RemoteObject:

Method Parameters Returns Description
obj.fetch – simple/dataframe Same as R.get(self)
obj.call *args, **kwargs RemoteObject Call a remote function
obj.pipe f, *args, **kwargs RemoteObject Pipe object through f
  • RemoteModule A remote namespace to help construct RemoteNames.

Example:

base = R.module("base")

# The __ is translated to a dot (calls base::data.frame)
df = base.data__frame(year = [2010, 2020],
                      population = [1_080_095, 1_120_015],
                      temperature = [20, 22]) 

# Functions in base (and other built-ins) can also be accessed through R.env directly
df = R.env.data__frame(...)
  • RemoteExpression Pass a literal expression as an argument. Can be used to construct datatypes like formulae or function parameters that use Non Standard Evaluation. Objects can be interpolated if given a t-string.

Example:

nice_temperature = 21
subset_df = base.subset(df, R.expr(t"temperature >= {nice_temperature}"))

Data Exchange

DataFrames are transferred using Apache Arrow files for efficiency.

You can request a specific backend when retrieving:

df = iris_rdf.fetch("pandas")

If no df_backend is provided, polars will be used.


Important Notes

⚠ Do not print to stdout from R.

Polyester uses stdout for protocol communication. Printing to stdout() inside R will corrupt the communication channel.

If you need logging inside R, use:

message("debug info")

or write to stderr().

In python, R.print can be used to print a remote object.


Why Not Use rpy2?

rpy2 is a mature and powerful solution.

However:

  • rpy2 is currently difficult to use on Windows in many environments.
  • Polyester runs R as a subprocess and avoids tight binary coupling.
  • The architecture is language-agnostic and may support additional languages (e.g., Julia) in the future.

If rpy2 becomes reliably usable in all target environments, Polyester may optionally integrate with it.


Design Goals

  • ✅ Windows support
  • ✅ Minimal external dependencies
  • ✅ Simple, explicit API
  • ✅ Subprocess isolation
  • 🔄 Possible future multi-language support

Performance is important, but clarity and robustness are higher priorities at this stage.


Implementation Details

  • R is started as a background subprocess.
  • Communication happens over JSON Lines.
  • DataFrames are exchanged via Apache Arrow files.
  • Remote objects are reference-tracked and cleaned up automatically.

Status

Completed

  • Start R subprocess in background
  • JSON Lines protocol for communication
  • DataFrame transfer using Apache Arrow
  • Remote object lifecycle management

Metadata

Release files for polyester 0.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for polyester 0.2.7
File Interpreter ABI Platform Actions
polyester-0.2.7-py3-none-any.whl Python 3 none any Details for polyester-0.2.7-py3-none-any.whl

Release files / polyester-0.2.7-py3-none-any.whl

Download URL polyester-0.2.7-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b15d53d97f945592508c3e055ef6c07025740b64f67c44efdcd0aec0bcf22d3
BLAKE2b-256 checksum
How to use checksums
b95a4fc2abe01cb4290539294125fcb097e3349af3997d0a0ba08edd8055a83b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.0

Security for polyester 0.2.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page