Skip to content

Commit c739206

Browse files
committed
[GR-71336] Python standalone applications
PullRequest: graalpython/4100
2 parents a604814 + c8023f0 commit c739206

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Python Standalone Applications
22

3-
GraalPy enables you to create a Python application or library as a native application or JAR file with no external dependencies.
4-
The [Truffle framework](https://github.com/oracle/graal/tree/master/truffle) on which GraalPy is built virtualizes all filesystem accesses, including those to the standard library and installed pure Python packages.
5-
Packages that include native code can still circumvent this, however!
3+
GraalPy enables you to package your Python applications or libraries into native executables or JAR files with no external dependencies. This means users can run your application without installing Python or any packages.
64

7-
GraalPy includes a module named `standalone` to create a Python binary for Linux, macOS, and Windows.
8-
The modules bundles all your application's resources into a single file.
5+
GraalPy uses the [Truffle framework](https://github.com/oracle/graal/tree/master/truffle) to bundle your Python code, dependencies, and the Python runtime into standalone executables. Truffle's filesystem virtualization allows everything to work from a single file, though packages with native C extensions may have limitations.
96

10-
> Prerequisite: GraalPy distribution beginning with version 23.1.0. See [GraalPy releases](https://github.com/oracle/graalpython/releases).
7+
GraalPy includes a module named `standalone` to create a Python binary for Linux, macOS, and Windows. The module bundles all your application's resources into a single file.
118

12-
For example, if you want to produce a native executable from a Python file named _my\_script.py_ along with packages you have installed in a virtual environment named _my\_venv_, run the following command:
9+
> **Prerequisite:** GraalPy 23.1.0 or later. [Download here](https://github.com/oracle/graalpython/releases) or verify your version with `graalpy --version`.
10+
11+
## Quickstart of Python Standalone Applications
12+
13+
To create an native executable from a Python file with its dependencies, use this command:
1314

1415
```bash
1516
graalpy -m standalone native \
@@ -18,10 +19,15 @@ graalpy -m standalone native \
1819
--venv my_env
1920
```
2021

21-
It produces a native _my_binary_ file which includes your Python code, the GraalPy runtime, and the Python standard library in a single, self-contained executable.
22+
Where:
23+
24+
* `--module my_script.py` states the main Python file that contains your application's entry point
25+
* `--output my_binary` states the name for your standalone executable (no file extension needed)
26+
* `--venv my_env` states the path to virtual environment with installed packages (you can omit this if there are no dependencies)
27+
28+
This produces a native _my_binary_ file which includes your Python code, the GraalPy runtime, and the Python standard library in a single, self-contained executable.
2229
Use `graalpy -m standalone native --help` for further options.
2330

2431
### Security Considerations of Python Standalone Applications
2532

26-
Creating a native executable or a JAR file that includes Python code could be seen as a mild form of obfuscation, but it does not protect your source code.
27-
Python source code is not stored verbatim into the executable (only the GraalPy bytecode is stored), but bytecode is easy to convert back into Python source code.
33+
Standalone executables do not protect your source code. Your Python code becomes bytecode, and bytecode can be easily decompiled back to readable Python code.

0 commit comments

Comments
 (0)