A comprehensive Python-to-Java bridge enabling seamless integration between Python and Java virtual machines
npx @tessl/cli install tessl/pypi-jpype1@1.6.00
# JPype1
1
2
A comprehensive Python-to-Java bridge enabling seamless integration between Python and Java virtual machines through native-level interfacing. JPype1 allows Python applications to access Java libraries, execute Java code, and manipulate Java objects directly within Python environments without requiring code re-implementation.
3
4
## Package Information
5
6
- **Package Name**: JPype1
7
- **Language**: Python
8
- **Installation**: `pip install JPype1`
9
- **Java Compatibility**: Java 8, 9, 11+
10
- **Platform Support**: Windows, macOS, Linux
11
12
## Core Imports
13
14
```python
15
import jpype
16
```
17
18
Common import patterns:
19
20
```python
21
# For JVM lifecycle management
22
from jpype import startJVM, shutdownJVM, isJVMStarted
23
24
# For Java class and object access
25
from jpype import JClass, JObject, java, javax
26
27
# For type bridging
28
from jpype import JString, JArray, JInt, JDouble
29
```
30
31
## Basic Usage
32
33
```python
34
import jpype
35
from jpype import java, javax
36
37
# Start the JVM
38
jpype.startJVM()
39
40
# Access Java classes through java/javax packages
41
String = java.lang.String
42
System = java.lang.System
43
ArrayList = java.util.ArrayList
44
45
# Create and use Java objects
46
hello = String("Hello from Java!")
47
print(hello.length()) # Call Java method
48
print(hello.toUpperCase())
49
50
# Work with collections
51
list_obj = ArrayList()
52
list_obj.add("Python")
53
list_obj.add("Java")
54
print(f"List size: {list_obj.size()}")
55
56
# Access system properties
57
System.out.println("Hello from Python via Java!")
58
java_version = System.getProperty("java.version")
59
print(f"Java version: {java_version}")
60
61
# Always shutdown when done
62
jpype.shutdownJVM()
63
```
64
65
## Architecture
66
67
JPype1 bridges Python and Java through a native shared-memory architecture:
68
69
- **JVM Integration**: Direct native-level interfacing with Java Virtual Machine
70
- **Object Bridging**: Transparent conversion between Python and Java objects
71
- **Type System**: Comprehensive mapping between Python and Java primitive types
72
- **Memory Management**: Shared memory approach for optimal performance
73
- **Bidirectional Communication**: Python calling Java and Java calling Python
74
75
The design enables access to the entirety of both CPython and Java ecosystems while maintaining high performance through native integration rather than serialization or process boundaries.
76
77
## Capabilities
78
79
### JVM Lifecycle Management
80
81
Core functionality for starting, configuring, and managing the Java Virtual Machine from within Python applications. Includes JVM discovery, startup configuration, and shutdown procedures.
82
83
```python { .api }
84
def startJVM(*jvmargs, **kwargs): ...
85
def shutdownJVM(): ...
86
def isJVMStarted() -> bool: ...
87
def getJVMVersion() -> tuple: ...
88
def getDefaultJVMPath() -> str: ...
89
```
90
91
[JVM Management](./jvm-management.md)
92
93
### Java Class and Object Access
94
95
Access and manipulation of Java classes, objects, and packages through Python interfaces. Provides structured access to Java APIs and seamless object interoperability.
96
97
```python { .api }
98
class JClass: ...
99
class JObject: ...
100
class JPackage: ...
101
def JInterface: ...
102
java: JPackage # Global java.* package access
103
javax: JPackage # Global javax.* package access
104
```
105
106
[Class and Object Access](./class-object-access.md)
107
108
### Type System and Conversion
109
110
Comprehensive type bridging between Python and Java type systems, including primitive types, arrays, strings, and custom type conversions.
111
112
```python { .api }
113
class JString: ...
114
class JArray: ...
115
class JBoolean: ...
116
class JByte: ...
117
class JChar: ...
118
class JShort: ...
119
class JInt: ...
120
class JLong: ...
121
class JFloat: ...
122
class JDouble: ...
123
```
124
125
[Type System](./type-system.md)
126
127
### Interface Implementation and Proxying
128
129
Create Python implementations of Java interfaces and proxy objects for bidirectional communication between Python and Java code.
130
131
```python { .api }
132
class JImplements: ...
133
class JProxy: ...
134
def JOverride: ...
135
```
136
137
[Interface Implementation](./interface-implementation.md)
138
139
### Exception Handling
140
141
Handle Java exceptions within Python and bridge between Python and Java exception systems.
142
143
```python { .api }
144
class JException(Exception): ...
145
```
146
147
[Exception Handling](./exception-handling.md)
148
149
### Classpath and Import Management
150
151
Manage Java classpath, configure import paths, and customize class loading behavior for Python-Java integration.
152
153
```python { .api }
154
def addClassPath(path): ...
155
def getClassPath(env=True) -> list: ...
156
```
157
158
[Classpath Management](./classpath-management.md)
159
160
### Advanced Features
161
162
Specialized functionality including threading support, GUI integration, NIO buffer support, customization framework, and database API integration.
163
164
```python { .api }
165
def synchronized(obj): ...
166
def attachThreadToJVM(): ...
167
def detachThreadFromJVM(): ...
168
def convertToDirectBuffer(obj): ...
169
```
170
171
[Advanced Features](./advanced-features.md)