A native, bidirectional bridge between ooRexx and Python 3, modelled after BSF4ooRexx. Binaries for Linux, macOS and Windows: releases (see Installing).
- ooRexx → Python: a Rexx program imports Python modules (numpy,
matplotlib, the standard library...) and uses Python objects as Rexx
objects (
.py,.PyObject), with keyword arguments, Python's operators, iteration and exceptions; a Python list can be used as a Rexx Array, counting from 1 (~makeArrayProxy); and Rexx classes extend Python classes, whose methods they override (::class Worker subclass PyObject,.py~extend, as ooRexx/.NET's.net~extend). - Python → ooRexx: a Python program creates ooRexx interpreters, runs
Rexx code and uses Rexx objects as Python objects (
oorexx.Interpreter,oorexx.RexxObject); Python functions can beADDRESSenvironments, and Rexx's standard streams go through Python's (sys.stdout...), each line marked as Rexx's (REXXout>, as in BSF4ooRexx). - Both ways at once, on any thread: Rexx calls Python, which calls back a Rexx object, which calls Python again.
- One build for every Python 3 from 3.9: the bridge uses Python's Stable ABI only, so the same binary works with 3.9, 3.10, 3.11, 3.12, 3.13, 3.14, 3.15 and later, with no virtual environments and no per-version builds.
np = .py~import("numpy") m = np~array(((1, 2), (3, 4))) say m~sum m~shape -- 10 (2, 2) say .py~round(np~linalg~det(m), 2) -- -2.0 ::requires "python.cls"
import oorexx with oorexx.Interpreter() as rexx: print(rexx.eval("6 * 7")) # 42 times = rexx.routine("use arg a, b; return a * b") print(times(6, 7)) # 42
Status: prototype. Both directions work and are covered by automated
tests (ooRexxUnit test groups and Python checks, every nutshell sample
included), on Linux x86_64, macOS (arm64 and x86_64) and Windows x64, with CPython
3.9–3.15, against ooRexx 5.3.0 (trunk, r13379, also the minimum:
docs/design.md, ooRexx versions). Every push runs them
all with every Python on all four (GitHub Actions:
.github/workflows/build.yml), except that on Windows the three thread
stress tests run with 3.9 and 3.15 only; a tag or a manual run runs them
with every Python there too. The design is still being discussed, and
parts of the API may change.
Two books, in the format of ooRexx's own and built with its documentation
tools, as PDF and HTML: ooRexx and Python: Reference (pythonref, in the
style of ooRexx's rexxref: every class, method and routine, with syntax
diagrams and small examples) and ooRexx and Python: Cookbook
(pythoncookbook: the main concepts, one recipe per sample). Each release
carries them; every push builds them (artifact oorexxpython-docs of the
Actions run).
Their sources are in docs/books.
You need ooRexx and Python on your computer, and then the bridge: on
Windows, its installer program; on Linux and macOS, its zip, whose
install.rex does the same. Either one puts the bridge into your ooRexx,
tells your Pythons where it is and records which Python Rexx programs use:
no environment variables to set.
- ooRexx 5.3.0, r13379 or later (beta). Get it from
SourceForge
and check that
rexx -vruns in a terminal. The bridge needs itslogicalwrapper.cls(Python'sboolin Rexx), new in r13278, and the fix for ooRexx bug #2122 (threads), in r13286, and ooRexx's.CommandHandler(RFE #882), and the fix for #2123 (conditions other than SYNTAX reach the bridge), in r13320, andRaiseConditionObject(RFE #883, a condition raised again as it is), in r13329, and the fixes for #2130 and #2132 (a raised condition keeps the call's value; no crash under threads), in r13344; r13379 is the revision the ooRexx bridges are built and tested on. 5.2.0, the current release, has none of them. - Python 3.9 or later, any version: the bridge is one binary for all of
them. If you want the samples that use numpy, matplotlib and pandas,
install them too:
pip install numpy matplotlib pandas. - The bridge, from
the releases page,
under the newest version, as below for each system. Both ways check both
directions at the end (
ooRexx/Python: installed and OK). - Try it. The samples are in ooRexx's samples folder, under
python. Go there and run one:rexx 01-hello.rex, orpython 30-run-rexx.py(python3on Linux and macOS). Their README lists them all.
- Python: from python.org or from the
Microsoft Store (Python install manager). It need not be on the
PATH. - Download
oorexxpython-VERSION-windows-x64.exeand run it. Windows may warn that the program is not signed ("Windows protected your PC": More info, Run anyway), as it does with ooRexx's own installer. - It finds ooRexx (or asks for its folder) and the Pythons installed on the
computer, and asks which of them will
import oorexxand which one Rexx programs use; another Python can be given by itspython.exe. - It puts the samples in
C:\Program Files\ooRexx\samples\python, the books in ooRexx'sdocfolder, and, in ooRexx's Start menu folder, the books (ooRexx Documentation), the samples' slide deck (ooRexx Samples) and "Uninstall ooRexx-Python". It can also be uninstalled from Settings > Apps. To update, run the new version's installer. - Unattended:
oorexxpython-VERSION-windows-x64.exe /S /PYTHON=C:\path\to\python.exe /D=C:\Program Files\ooRexx(/Dlast; several Pythons separated by;;/REXXPYTHON=for the one Rexx uses; without/PYTHON, every Python it finds). What it did is in%TEMP%\oorexxpython-install.log. - The zip works on Windows too, for a portable ooRexx or when you prefer the command line (below).
Download the zip for your system (linux-x64, macos-arm64 for Apple
silicon, macos-x64 for Intel Macs, windows-x64), unzip it anywhere, open a terminal in
the unzipped folder oorexxpython and run rexx install, as below. The
samples are then in ooRexx's samples folder, and the unzipped folder is no
longer needed: you can delete it.
-
Python: your distribution's
python3, with its shared library, which some distributions package apart. On Debian and Ubuntu, that islibpython3.X, X being your Python's (python3 --version): for example,sudo apt install libpython3.12.rexx installnotices when it is missing, and says what to install. -
ooRexx installed from a package (in
/usror/usr/local) needssudo, andsudomay find anotherpython3than yours, so name yours:cd /path/to/oorexxpython sudo rexx install --python $(which python3)
-
The samples end up in
/usr/local/share/ooRexx/samples/python(or/usr/share/..., where ooRexx is).
-
Python: the installer from python.org, or Homebrew's (
brew install python). -
An ooRexx in a system folder such as
/usr/localneedssudo, naming your Python as on Linux:cd /path/to/oorexxpython sudo rexx install --python $(which python3)
-
ooRexx in
C:\Program Files\ooRexx(the default) needs an administrator: open the terminal as administrator (right-click on Command Prompt or Terminal, "Run as administrator"), thencd C:\path\to\oorexxpython rexx install --python C:\path\to\python.exe(without
--python, thepythonon thePATH). -
The samples end up in
C:\Program Files\ooRexx\samples\python.
An ooRexx unzipped from one of the portable builds, with its bin on the
PATH, is installed into in the same way, without administrator rights:
rexx install (or rexx install --python /path/to/python).
rexx oorexxpython-uninstall status, from any folder, shows what was installed and where;rexx oorexxpython-uninstallremoves exactly that.- Updating: run the new version's
rexx install(or installer); it replaces the old one. - Another Python:
rexx install --python /path/to/python, as many times as you like (each Python gets its own link to the bridge);--userputs the link in your user folder, which needs no administrator. - Which Python Rexx uses: the one the installer recorded in
oorexxpython.cfg, next to the bridge: the first--python(or the one named with--rexx-python); installing again keeps that choice unless--rexx-pythonnames another. The environment variableORX_PYTHON, when set, takes precedence. Its installed packages are the ones Rexx programs see. - Without installing: the zip's own
README.mdsays which environment variables to set instead. - The newest build: every push to this repository builds the same zips,
available for 90 days as artifacts
oorexxpython-<platform>of its Actions run (you must be signed in to GitHub to download them).
To build the bridge yourself, or to work on it, you need Linux x86_64, macOS or Windows, with:
- a C++ compiler:
g++; Xcode's command line tools on macOS; MSVC on Windows, with the scripts run from Git Bash in a developer command prompt's environment; curl, and uv (orpip, whichsetup-pythons.shuses to install uv);- an ooRexx 5.3.0, r13379 or later, with its API headers: an installed ooRexx (
/usr/local), or one of ooRexx's portable builds from SourceForge with itsbin/on thePATH.
git clone https://github.com/JosepMariaBlasco/oorexxpython oorexxpython/scripts/setup-pythons.sh # CPython 3.9 ... 3.15, with uv oorexxpython/scripts/build.sh # the bridge, seconds oorexxpython/samples/run-one.sh 01-hello.rex
Everything goes into the directory that contains your clone
($ORXPY_WORK, overridable), next to it:
build/ oorexx.abi3.so, librexxpython.so, python.cls
(macOS: librexxpython.dylib; Windows: oorexx.pyd, rexxpython.dll)
pythons/ the CPython versions to test against
oorexxunit/ ooRexx's test framework (for the tests)
To use the bridge from your own programs:
- From Rexx: put the build directory on
REXX_PATHandLD_LIBRARY_PATH(DYLD_LIBRARY_PATHon macOS), and say which Python to use withORX_PYTHON(default: thepython3on thePATH; its installed packages are the ones Rexx sees):ORX_PYTHON=$(which python3) LD_LIBRARY_PATH=build REXX_PATH=build rexx prog.rex. On Windows the build directory goes on thePATHinstead, andORX_PYTHONdefaults to thepythonon thePATH. - From Python: put the build directory on
PYTHONPATHandimport oorexx:PYTHONPATH=build python3 prog.py. On Windows, ooRexx'sbindirectory must be on thePATH(orOOREXX_HOMEset): the module findsrexx.dllthere itself.
oorexxpython/scripts/setup-oorexxunit.sh # ooRexxUnit, from ooRexx's SVN # numpy, matplotlib and pandas in each Python, for Numpy.testGroup: for v in 3.9 3.10 3.11 3.12 3.13 3.14 3.15; do uv pip install --python "$(uv python find $v)" --break-system-packages numpy matplotlib pandas done oorexxpython/tests/run.sh # every test with every Python, ~1 min
run.sh runs each test file in its own process under a timeout (a deadlock
is a failure). PYTHONS="3.9 3.13" and TESTS=Threads.testGroup choose;
ORXPY_THREADS="16 16 2000" makes the threads stress test heavy.
UV_PYTHON_INSTALL_DIR defaults to $ORXPY_WORK/pythons, where
setup-pythons.sh installs them.
src/— the bridge.bridge.cpp—oorexx.abi3.so: both directions, the proxies, the locks,ADDRESS(Stable ABI only, ooRexx's public native API only).loader.cpp—librexxpython.so, the ooRexx package that finds and loads a Python when Rexx starts, then hands over to the bridge.python.cls— the Rexx side:.py,.PyObject,py.import& co.
samples/— short "nutshell" programs, one feature each, both ways; each shows the Python it replaces and its exact output (see its README).tests/—run.sh;rexx/(ooRexxUnit test groups: basics, booleans, callbacks, ADDRESS, numpy, lifetime, threads, subclassing, and all the samples),python/(the Python side),probe/(the conversion probe and its expected output, run bypython/t80_conversion_probe.py).scripts/—build.sh,setup-pythons.sh,setup-oorexxunit.sh,setup-oorexx-deb.sh(installs SourceForge's ooRexx package for Ubuntu 24.04 at the CI's revision,OOREXX_REVin the workflow), andsetup-oorexx.sh(builds ooRexx from SVN, for a revision with no package).docs/design.md— how the bridge works and why: names, values, keyword arguments, threads and locks, lifetime.docs/books/— two books in the format of ooRexx's own, built with its documentation tools: Reference (pythonref, in the style ofrexxref) and Cookbook (pythoncookbook, one recipe per sample); see its README.notes/oorexx-bugs.md— the ooRexx bugs the bridge's tests found, and what the code does about each.
The bridge was suggested by Rony G. Flatscher, author of
BSF4ooRexx, the ooRexx–Java
bridge it is modelled after; the .JSObject bridge of
ooRexx/WASM is its sister.
The tests use ooRexxUnit, ooRexx's own test framework (CPL 1.0), fetched from
ooRexx's SVN, not included here. tests/python/t70_identity_lifetime.py asks of this bridge
what Tom Dyer's qualification probes for his ooRexx/Python proof of concept in
Alchemy ask of his, contributed by
him under the Apache License 2.0; oorexx.RexxError's attributes follow his
bridge's.
Written by Josep Maria Blasco, with Claude (Anthropic) as coding assistant.
Apache License 2.0 (LICENSE).