You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With GraalPy, you can distribute Python applications or libraries as standalone binaries or JAR files without any external dependencies.
10
10
The [Truffle framework](https://github.com/oracle/graal/tree/master/truffle) on which GraalPy is built, and the [Sulong LLVM runtime](https://github.com/oracle/graal/tree/master/sulong) that GraalPy leverages for managed execution of Python's native extensions enables users to completely virtualize all filesystem accesses of Python programs, including those to the standard library and installed packages.
11
11
12
-
GraalPy comes with a module that can create standalone binaries or Java-Python polyglot project skeletons.
13
-
The binaries bundle everything into one native executable.
14
-
The polyglot skeletons are set up with Maven to to generate a standalone binary for a simple java - python hello world example and can be used as a starting point or inspiration for further java-python polyglot development.
12
+
GraalPy comes with a module that can create Python binaries for Linux, Windows, and macOS.
13
+
The binaries bundle everything into a single-file native executable.
15
14
16
-
### Prerequisite
17
-
18
-
A GraalPy distribution.
19
-
TODO - add link
15
+
The tool can also generate a skeleton Maven project that sets up a polyglot embedding of Python packages into Java.
16
+
The polyglot skeletons are set up with Maven to to generate a standalone binary for a simple Java-Python HelloWorld example and can be used as a starting point or inspiration for further Java-Python polyglot development.
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..
12
+
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.
13
13
GraalPy can usually execute pure Python code faster than CPython, and nearly match CPython performance when C extensions are involved.
14
14
While many workloads run fine, any Python program that uses external packages could hit something unsupported.
15
15
At this point, the Python implementation is made available for experimentation and curious end-users.
16
16
See the [FAQ](FAQ.md) for commonly asked questions about this implementation.
17
17
18
-
## Installing GraalPy
18
+
## GraalPy Distributions
19
+
20
+
As of GraalVM for JDK 21, the Python runtime (GraalPy) is available as a standalone distribution.
19
21
20
-
### Linux and macOS
22
+
A GraalPy standalone built on top of Oracle GraalVM (Oracle GraalPy) is licensed under the [GraalVM Free Terms and Conditions (GFTC)](https://www.oracle.com/downloads/licenses/graal-free-license.html) license, which permits use by any user including commercial and production use. Redistribution is permitted as long as it is not for a fee.
23
+
Oracle GraalPy provides the best experience: it comes with additional optimizations, is significantly faster and more memory-efficient.
21
24
22
-
The easiest way to install GraalPy on Linux and macOS platforms is to use [pyenv](https://github.com/pyenv/pyenv/), the Python version manager.
23
-
For example, to install version 22.3.0, for example, run the following commands:
25
+
A GraalPy standalone built on top of GraalVM Community Edition (GraalPy Community) is fully open-source.
26
+
To distinguish between them, GraalPy Community has the suffix `-community` in the name.
24
27
25
28
```bash
26
-
pyenv install graalpy-22.3.0
27
-
pyenv shell graalpy-22.3.0
29
+
# Oracle GraalPy
30
+
graalpy-VERSION-PLATFORM.tar.gz
31
+
# GraalPy Community
32
+
graalpy-community-VERSION-PLATFORM.tar.gz
28
33
```
29
34
30
-
Another option is to use [Conda-Forge](https://conda-forge.org/).
31
-
To get an environment with the latest version of GraalPy, use the following command:
35
+
Two language runtime options are available for both Oracle and Community GraalPy: Native and JVM.
36
+
In the Native configuration, GraalPy is ahead-of-time compiled to a standalone native executable.
37
+
This means that you do not need a JVM installed on your system to use it and it is size-compact.
38
+
In the JVM configuration, you can use Java interoperability easily, and peak performance may be higher than the native configuration.
39
+
A JVM standalone that comes with a JVM has the `-jvm` suffix in a name: `graalpy-jvm-<version>-<os>-<arch>.tar.gz`.
To try GraalPy with a full GraalVM, including support for Java embedding and interoperability with other languages, you can use the bundled releases from [www.graalvm.org](https://www.graalvm.org/downloads/).
91
+
#### Windows
48
92
49
-
### Windows
93
+
There is a GraalPy preview build for Windows that you can [download](https://github.com/oracle/graalpython/releases/).
94
+
It supports installation of pure Python packages via `pip`. Native extensions are a work in progress.
50
95
51
-
There is a preview binary build of Windows that you can download via [www.graalvm.org](https://www.graalvm.org/downloads/).
52
96
The Windows build has several known issues:
53
97
54
98
- JLine treats Windows a dumb terminal, no autocomplete and limited editing capabilities in the REPL
55
99
- Interactive help() in the REPL doesn't work
56
-
- Oracle GraalPy builds cannot create venvs or install packages, use community GraalPy builds to do those things.
57
100
- Inside venvs:
58
101
- graalpy.cmd and graalpy.exe are broken
59
102
- pip.exe cannot be used directly
@@ -127,13 +170,35 @@ These can be viewed using the following command:
127
170
graalpy --help --help:tools --help:languages
128
171
```
129
172
130
-
## Native Image and JVM Runtime
173
+
## Interoperability with Java
174
+
175
+
The best way to embed GraalPy is to use the [GraalVM SDK Polyglot API](https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/package-summary.html).
176
+
177
+
As of GraalVM for JDK 21, all necessary artifacts can be downloaded directly from Maven Central.
178
+
All artifacts relevant to embedders can be found in the Maven dependency group [`org.graalvm.polyglot`](https://central.sonatype.com/namespace/org.graalvm.polyglot).
179
+
180
+
To embed GraalPy into a Java host application, add GraalPy as a Maven dependency or explicitly put the JAR on the module path. Below is the Maven configuration for a Python embedding:
181
+
```xml
182
+
<dependency>
183
+
<groupId>org.graalvm.polyglot</groupId>
184
+
<artifactId>polyglot</artifactId>
185
+
<version>23.1.0</version>
186
+
</dependency>
187
+
<dependency>
188
+
<groupId>org.graalvm.polyglot</groupId>
189
+
<artifactId>python</artifactId>
190
+
<version>23.1.0</version>
191
+
<scope>runtime</scope>
192
+
<type>pom</type>
193
+
</dependency>
194
+
```
195
+
196
+
The `<scope>runtime</scope>` parameter is only necessary if you need the runtime dependency.
131
197
132
-
By default, GraalVM runs GraalPy from a binary, compiled ahead-of-time with [Native Image](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/README.md), yielding faster startup time and lower footprint.
133
-
Although the ahead-of-time compiled binary includes the Python and LLVM interpreters, to interoperate with
134
-
other languages you must supply the `--jvm` option.
135
-
This instructs the launcher to run on the JVM instead of in Native Image mode.
136
-
Thus, you will notice a longer startup time.
198
+
Depending on which supported JDK you run embedded GraalPy, the level of optimizations varies, as described [here](https://www.graalvm.org/reference-manual/embed-languages/#runtime-optimization-support).
199
+
200
+
Learn more in a dedicated [GraalPy Interoperability guide](Interoperability.md). See also the [Embedding Languages documentation](https://www.graalvm.org/reference-manual/embed-languages/) on how a guest language like Python can possibly interract with Java.
0 commit comments