|
1 | 1 | # GraalPy, the GraalVM Implementation of Python
|
2 | 2 |
|
3 |
| -GraalPy is an implementation of the Python language on top of GraalVM. |
4 |
| -A primary goal is to support PyTorch, SciPy, and their constituent libraries, as well as to work with other data science and machine learning libraries from the rich Python ecosystem. |
5 |
| -GraalPy can usually execute pure Python code faster than CPython, and nearly match CPython performance when C extensions are involved. |
6 |
| -GraalPy currently aims to be compatible with Python 3.10. |
7 |
| -While many workloads run fine, any Python program that uses external packages could hit something unsupported. |
8 |
| -At this point, the Python implementation is made available for experimentation and curious end-users. |
9 |
| -We welcome issue reports of all kinds and are working hard to close our compatibility gaps. |
| 3 | +GraalPy is a high-performance implementation of the [Python](https://www.python.org/) language for the JVM built on [GraalVM](https://www.graalvm.org/) technology. |
10 | 4 |
|
11 |
| -## Installation |
| 5 | +## Getting Started |
12 | 6 |
|
13 |
| -The easiest option to try GraalPy is [pyenv](https://github.com/pyenv/pyenv/), the Python version manager. |
14 |
| -It allows you to easily install different GraalPy releases. |
15 |
| -To install version 23.1.0, for example, just run `pyenv install graalpy-community-23.1.0`. |
| 7 | +<details> |
| 8 | +<summary><strong>Embedding GraalPy in Java</strong></summary> |
16 | 9 |
|
17 |
| -Another option is to use [Conda-Forge](https://conda-forge.org/). |
18 |
| -To get an environment with the latest version of GraalPy, use the following command: |
| 10 | +GraalPy is [available on Maven Central](https://central.sonatype.com/artifact/org.graalvm.polyglot/python) for inclusion in Java projects: |
19 | 11 |
|
20 |
| -```bash |
21 |
| -conda create -c conda-forge -n graalpy graalpy |
| 12 | +``` |
| 13 | +<dependency> |
| 14 | + <groupId>org.graalvm.polyglot</groupId> |
| 15 | + <artifactId>python</artifactId> |
| 16 | + <version>23.1.2</version> |
| 17 | + <type>pom</type> |
| 18 | +</dependency> |
22 | 19 | ```
|
23 | 20 |
|
24 |
| -To try GraalPy with a full GraalVM, including the support for Java embedding and interoperability with other languages, you can use the bundled releases from [www.graalvm.org](https://www.graalvm.org/downloads/). |
| 21 | +</details> |
25 | 22 |
|
26 |
| ->**Note:** There is currently no installer for Windows. |
| 23 | +<details> |
| 24 | +<summary><strong>Replacing CPython with GraalPy</strong></summary> |
27 | 25 |
|
28 |
| -## Building from Source |
| 26 | +* Linux |
29 | 27 |
|
30 |
| -#### Requirements |
| 28 | + The easiest way to install GraalPy on Linux is to use [Pyenv](https://github.com/pyenv/pyenv) (the Python version manager). |
| 29 | + To install version 23.1.1 using Pyenv, run the following commands: |
| 30 | + ```bash |
| 31 | + pyenv install graalpy-23.1.1 |
| 32 | + ``` |
| 33 | + ```bash |
| 34 | + pyenv shell graalpy-23.1.1 |
| 35 | + ``` |
| 36 | + |
| 37 | + Alternatively, you can download a compressed GraalPy installation file from [GitHub releases](https://github.com/oracle/graalpython/releases). |
| 38 | + |
| 39 | + 1. Find the download that matches the pattern _graalpy-XX.Y.Z-linux-amd64.tar.gz_ or _graalpy-XX.Y.Z-linux-aarch64.tar.gz_ (depending on your platform) and download. |
| 40 | + 2. Uncompress the file and update your `PATH` environment variable to include the _graalpy-XX.Y.Z-linux-amd64/bin_ (or _graalpy-XX.Y.Z-linux-aarch64/bin_) directory. |
31 | 41 |
|
32 |
| -* [mx](https://github.com/graalvm/mx) |
| 42 | +* macOS |
33 | 43 |
|
34 |
| - There is a separate Python tool for GraalVM development. This tool must be downloaded and added to your PATH: |
35 |
| - |
36 |
| - ```shell |
37 |
| - git clone https://github.com/graalvm/mx.git |
38 |
| - export PATH=$PWD/mx:$PATH |
| 44 | + The easiest way to install GraalPy on macOS is to use [Pyenv](https://github.com/pyenv/pyenv) (the Python version manager). |
| 45 | + To install version 23.1.1 using Pyenv, run the following commands: |
| 46 | + ```bash |
| 47 | + pyenv install graalpy-23.1.1 |
39 | 48 | ```
|
40 |
| -* LabsJDK |
41 |
| - |
42 |
| - The following command will download and install JDKs upon which to build GraalVM. If successful, it will print the path for the value of your `JAVA_HOME` environment variable. |
43 |
| - ```shell |
44 |
| - mx fetch-jdk |
| 49 | + ```bash |
| 50 | + pyenv shell graalpy-23.1.1 |
45 | 51 | ```
|
46 |
| - |
47 |
| -#### Building |
| 52 | + Alternatively, you can download a compressed GraalPy installation file from [GitHub releases](https://github.com/oracle/graalpython/releases). |
| 53 | + |
| 54 | + 1. Find the download that matches the pattern _graalpy-XX.Y.Z-macos-amd64.tar.gz_ or _graalpy-XX.Y.Z-macos-aarch64.tar.gz_ (depending on your platform) and download. |
| 55 | + 2. Remove the quarantine attribute. |
| 56 | + ```bash |
| 57 | + sudo xattr -r -d com.apple.quarantine /path/to/graalpy |
| 58 | + ``` |
| 59 | + For example: |
| 60 | + ```bash |
| 61 | + sudo xattr -r -d com.apple.quarantine ~/.pyenv/versions/graalpy-23.1.1 |
| 62 | + ``` |
| 63 | + 3. Uncompress the file and update your `PATH` environment variable to include to the _graalpy-XX.Y.Z-macos-amd64/bin_ (or _graalpy-XX.Y.Z-macos-aarch64/bin_) directory. |
| 64 | + |
| 65 | +* Windows |
| 66 | + |
| 67 | + The Windows support of GraalPy is still experimental, so not all features and packages may be available. |
| 68 | + |
| 69 | + 1. Find and download a compressed GraalPy installation file from [GitHub releases](https://github.com/oracle/graalpython/releases) that matches the pattern _graalpy-XX.Y.Z-windows-amd64.tar.gz_. |
| 70 | + 2. Uncompress the file and update your `PATH` variable to include to the _graalpy-XX.Y.Z-windows-amd64/bin_ directory. |
| 71 | + |
| 72 | +</details> |
| 73 | +<details> |
| 74 | +<summary><strong>Using GraalPy in Github Actions</strong></summary> |
| 75 | + |
| 76 | +The _setup-python_ action supports GraalPy: |
| 77 | + |
| 78 | +``` |
| 79 | + - name: Setup GraalPy |
| 80 | + uses: actions/setup-python@main |
| 81 | + with: |
| 82 | + python-version: graalpy # or graalpy23.1 to pin a version |
| 83 | +``` |
| 84 | +
|
| 85 | +</details> |
| 86 | +<details> |
| 87 | +<summary><strong>Migrating Jython Scripts to GraalPy</strong></summary> |
| 88 | +
|
| 89 | +To run Jython scripts, you will need a GraalPy distribution running on the JVM so you can access Java classes from Python scripts. |
| 90 | +
|
| 91 | +* Linux |
| 92 | + |
| 93 | + 1. Find and download a compressed GraalPy installation file from [GitHub releases](https://github.com/oracle/graalpython/releases) that matches the pattern _graalpy-jvm-XX.Y.Z-linux-amd64.tar.gz_ or _graalpy-jvm-XX.Y.Z-linux-aarch64.tar.gz_ (depending on your platform) and download. |
| 94 | + 2. Uncompress the file and update your `PATH` environment variable to include the _graalpy-jvm-XX.Y.Z-linux-amd64/bin_ (or _graalpy-jvm-XX.Y.Z-linux-aarch64/bin_) directory. |
| 95 | + 3. Run your scripts with `graalpy --python.EmulateJython`. |
48 | 96 |
|
49 |
| -Run `mx --dy /compiler python-gvm` in the root directory of the `graalpython` repository. |
50 |
| -If the build succeeds, it will print the full path to the `graalpy` executable as the last line of output. |
51 |
| -This builds a `bash` launcher that executes GraalPy on the JVM. |
52 |
| -To build a native launcher for lower footprint and better startup, run `mx python-svm` instead. |
| 97 | +* macOS |
53 | 98 |
|
54 |
| -For more information and some examples of what you can do with GraalPy, see the [reference documentation](https://www.graalvm.org/reference-manual/python/). |
| 99 | + 1. Find and download a compressed GraalPy installation file from [GitHub releases](https://github.com/oracle/graalpython/releases) that matches the pattern _graalpy-jvm-XX.Y.Z-macos-amd64.tar.gz_ or _graalpy-jvm-XX.Y.Z-macos-aarch64.tar.gz_ (depending on your platform) and download. |
| 100 | + 2. Remove the quarantine attribute. |
| 101 | + ```bash |
| 102 | + sudo xattr -r -d com.apple.quarantine /path/to/graalpy |
| 103 | + ``` |
| 104 | + For example: |
| 105 | + ```bash |
| 106 | + sudo xattr -r -d com.apple.quarantine ~/.pyenv/versions/graalpy-23.1.1 |
| 107 | + ``` |
| 108 | + 3. Uncompress the file and update your `PATH` environment variable to include to the _graalpy-jvm-XX.Y.Z-macos-amd64/bin_ (or _graalpy-jvm-XX.Y.Z-macos-aarch64/bin_) directory. |
| 109 | + 4. Run your scripts with `graalpy --python.EmulateJython`. |
55 | 110 |
|
56 |
| -## Polyglot Usage |
| 111 | +* Windows |
57 | 112 |
|
58 |
| -See the [documentation](docs/user/Interoperability.md) that describes how we implement |
59 |
| -cross-language interoperability. |
60 |
| -This should give you an idea about how to use it. |
| 113 | + 1. Find and download a compressed GraalPy installation file from [GitHub releases](https://github.com/oracle/graalpython/releases) that matches the pattern _graalpy-jvm-XX.Y.Z-windows-amd64.tar.gz_. |
| 114 | + 2. Uncompress the file and update your `PATH` variable to include to the _graalpy-jvm-XX.Y.Z-windows-amd64/bin_ directory. |
| 115 | + 3. Run your scripts with `graalpy --python.EmulateJython`. |
61 | 116 |
|
62 |
| -## Jython Support |
| 117 | +</details> |
63 | 118 |
|
64 |
| -We are working on a mode that is "mostly compatible" with some of Jython's |
65 |
| -features, minus of course that Jython implements Python 2.7 and we implement |
66 |
| -Python 3.10+. |
| 119 | +## Current Status |
| 120 | +
|
| 121 | + |
| 122 | + |
| 123 | +
|
| 124 | +## Aims and Benefits of GraalPy |
| 125 | +
|
| 126 | +* **Convenient, low-overhead integration with Java and other languages.** |
| 127 | +
|
| 128 | + Java, JavaScript, Ruby, and other languages that run on the JVM can be used [conveniently with GraalPy](docs/user/Interoperability.md). |
| 129 | + GraalPy also integrates with JVM tools such as VisualVM or JFR, and comes with [profilers, memory samplers, and debuggers](docs/user/Tooling.md) provided as part of GraalVM's Truffle framework. |
| 130 | + |
| 131 | +* **Compatible with the Python ecosystem** |
| 132 | +
|
| 133 | + We run the CPython test suite on every commit and are passing ~75% of it. |
| 134 | + We also run the tests of the [top 600 PyPI packages](https://hugovk.github.io/top-pypi-packages/) on GraalPy every day. |
| 135 | + For more than 96% of the top 600 packages, there is at least one recent version that installs successfully and we are currently passing over 50% of all test cases in those top 600 packages. |
| 136 | +
|
| 137 | +* **Run Python code faster** |
| 138 | +
|
| 139 | + GraalPy can usually execute pure Python code faster than CPython. |
| 140 | + We see a geomean speedup of 4 on the [Python Performance Benchmark Suite](https://pyperformance.readthedocs.io/) over CPython. |
| 141 | +
|
| 142 | +* **Support C extensions** |
| 143 | +
|
| 144 | + GraalPy supports most of the public [CPython C API](https://docs.python.org/3/c-api/index.html) as well as the [HPy API](https://hpyproject.org/). |
| 145 | + It supports many native libraries including PyTorch, Tensorflow, SciPy, as well many other data science and machine learning libraries from the rich Python ecosystem. |
| 146 | + Performance when C extensions are involved is close to CPython, but can vary a lot depending on the specific interactions of C extension code and Python code. |
| 147 | +
|
| 148 | +## Python on the JVM |
| 149 | +
|
| 150 | +GraalPy is a first-class citizen of the JVM ecosystem that you can easily embed in your Java applications. |
| 151 | +You can use GraalPy with GraalVM JDK, Oracle JDK, or OpenJDK. |
| 152 | +You can easily add GraalPy to your Java application using [Maven build tools](docs/user/PythonStandaloneBinaries.md#embedding-graalpy-in-a-java-application). |
| 153 | +Python objects support the same [interoperability protocol](docs/user/Interoperability.md) as other GraalVM languages and behave naturally in Java. |
| 154 | +There are also [many options](docs/user/PythonNativeimages.md) to tweak GraalPy for GraalVM Native Images to reduce footprint. |
| 155 | +When embedded into Java, GraalPy also emulates many of the Python [OS interfaces](docs/user/OsInterface.md#java-backend) with standard Java APIs, so embedders have full control over standard streams, file system, or socket access. |
| 156 | +
|
| 157 | +## Migration from CPython |
| 158 | +
|
| 159 | +GraalPy should in many cases work as a drop-in replacement for CPython. |
| 160 | +You can use `pip` to install packages as usual. |
| 161 | +However, packages with C code usually do not provide binaries for GraalPy, so they will be automatically compiled during installation. |
| 162 | +This means that build tools have to be available and installation may take longer. |
| 163 | +We provide [Github actions](scripts/wheelbuilder) to help you build binary packages with the correct dependencies. |
| 164 | +
|
| 165 | +## Migration from Jython |
| 166 | +
|
| 167 | +Most existing Jython code that uses Java integration will be based on a stable Jython release—however, these are only available in Python 2.x versions. |
| 168 | +First, to migrate your code from Python 2 to Python 3, follow [the official guide from the Python community](https://docs.python.org/3/howto/pyporting.html). |
| 169 | +To facilitate migration from Jython, GraalPy provides a mode that is "mostly compatible" with some of Jython's features, minus of course that Jython implements Python 2.7 and we implement Python 3+. |
67 | 170 | We describe the current status of the compatibility mode [here](docs/user/Jython.md).
|
68 | 171 |
|
69 |
| -We are working on a mode that is "mostly compatible" with some of Jython's features, considering the fact that Jython implements Python 2.7 and we implement Python 3.10+. |
70 |
| -For more details about compatibility, see [here](docs/user/Jython.md). |
| 172 | +## Documentation |
| 173 | +
|
| 174 | +More user documentation is available in [docs/user](docs/user). |
| 175 | +
|
| 176 | +## Contact |
| 177 | +
|
| 178 | +The best way to get in touch with us is to join the `#graalpy` channel on [GraalVM Slack](https://www.graalvm.org/slack-invitation/). |
71 | 179 |
|
72 | 180 | ## Contributing
|
73 | 181 |
|
|
0 commit comments