| Jython | |
|---|---|
| Family | JVM-hosted |
| First appeared | January 17, 2001 |
| Stable release | |
| Implementation language | Python, Java |
| Platform | Java virtual machine |
| OS | cross-platform |
| License | Python Software Foundation (for older releases see License terms) |
| Website | www |
Jython, named JPython until 1999, is an implementation of the programming language Python designed to run on the Java virtual machine of the Java platform. It is free and open-source software released with a Python Software Foundation License.
Jython programs can import and use any Java class. Except for some standard modules, Jython programs use Java classes instead of Python module. Jython includes almost all of the modules in a standard Python language distribution, lacking only some of the modules implemented originally in C, and can call Java classes, such as the Java Class Library. For example, a user interface in Jython could be written with Swing, Abstract Window Toolkit (AWT), or Standard Widget Toolkit (SWT). Jython compiles Python source code to Java bytecode (an intermediate representation) either on demand or statically.
from java.io import FileWriter
from java.lang import System
from java.util import Date
# Write out the current date and the system info
message = "Run on " + str(Date()) + " by Java " + System.getProperty("java.version")
FileWriter("sys_info.txt").append(message).close()
print message
Because Jython maps threads directly onto Java threads, it avoids the global interpreter lock which standard Python uses.
Jython cannot make use of Java's type system or generics. Jython uses the primitive wrapper classes primarily for unboxing Java API return types back to Jython internal types.
| Jython internal type | Coerced Java type |
|---|---|
org.python.core.PyNone |
null |
org.python.core.PyObject |
java.lang.Object |
org.python.core.PyInteger |
int, java.lang.Integer |
org.python.core.PyFloat |
double, java.lang.Double |
org.python.core.PyUnicode |
java.lang.String |
org.python.core.PyList |
java.lang.List |
org.python.core.PyDictionary |
java.lang.Map |
Jython was initially created in late 1997 to replace C with Java for performance-intensive code accessed by Python programs. It moved to SourceForge in October 2000. The Python Software Foundation awarded a grant in January 2005. Jython 2.5 was released in June 2009.
The most recent release is Jython 2.7.4. It was released on August 18, 2024 and is compatible with Python 2.7.
Python 3 compatible changes are planned in Jython 3 Roadmap.
Although Jython implements the Python language specification, it has some differences and incompatibilities with CPython, which is the reference implementation of Python.
From version 2.2 on, Jython (including the standard library) is released under the Python Software Foundation License (v2). Older versions are covered by the Jython 2.0, 2.1 license and the JPython 1.1.x Software License.
The command line interface interpreter is available under an Apache software license.