Python Runtime Semantics in pyrt

Overview

pyrt provides the Python 3 runtime semantics required by R packages generated with pyport:

  • Reference-semantics containers (py_list(), py_dict(), py_set(), py_tuple())
  • C3 MRO classes, multiple inheritance, descriptors (py_property(), py_super())
  • 0-based negative and step slicing (py_slice(), py_getitem(), py_setitem())
  • Arbitrary-precision integers (gmp::bigz) with floor division toward \(-\infty\)
  • Bit-exact CPython 3.12 random (py_random) and numpy.random.RandomState
  • Standard library (math, itertools, functools, collections, datetime, re, json) and numpy / scipy / pandas bridges via py_stdlib()
library(pyrt)

# Reference-semantics list
xs <- py_list(list(10L, 20L, 30L))
alias <- xs
xs$append(40L)
py_len(alias)
#> [1] 4

# Bit-exact CPython 3.12 random
rng <- py_random$Random(42L)
rng$random()
#> [1] 0.6394268