| 1 |  |
| 2 | |
| 3 | |
| 4 | jpy - a Python-Java Bridge |
| 5 | ========================== |
| 6 | |
| 7 | jpy is a **bi-directional** Python-Java bridge which you can use to embed Java |
| 8 | code in Python programs or the other way round. It has been designed |
| 9 | particularly with regard to maximum data transfer speed between the two |
| 10 | languages. It comes with a number of outstanding features: |
| 11 | |
| 12 | * Fully translates Java class hierarchies to Python |
| 13 | * Transparently handles Java method overloading |
| 14 | * Support of Java multi-threading |
| 15 | * Fast and memory-efficient support of primitive Java array parameters via |
| 16 | [Python buffers](http://docs.python.org/3.3/c-api/buffer.html) |
| 17 | (e.g. [Numpy arrays](http://docs.scipy.org/doc/numpy/reference/arrays.html)) |
| 18 | * Support of Java methods that modify primitive Java array parameters (mutable |
| 19 | parameters) |
| 20 | * Java arrays translate into Python sequence objects |
| 21 | * Java API for accessing Python objects (`jpy.jar`) |
| 22 | |
| 23 | jpy has been tested with Python 3.9–3.14 and OpenJDK 11+ on Linux, Windows, and macOS. |
| 24 | |
| 25 | The initial development of jpy was driven by the need to write Python |
| 26 | extensions to an established scientific imaging application programmed in |
| 27 | Java, namely the [SNAP](http://step.esa.int/) toolbox, the SeNtinel |
| 28 | Application Platform project, funded by the [European Space |
| 29 | Agency](http://www.esa.int/ESA) (ESA). (jpy is bundled with the SNAP |
| 30 | distribution.) Current development and maintenance is funded by [Deephaven](https://deephaven.io). |
| 31 | |
| 32 | Writing such Python plug-ins for a Java application usually requires a |
| 33 | bi-directional communication between Python and Java since the Python |
| 34 | extension code must be able to call back into the Java APIs. |
| 35 | |
| 36 | For more information please have a look into jpy's |
| 37 | |
| 38 | * [documentation](http://jpy.readthedocs.org/en/latest/) |
| 39 | * [source repository](https://github.com/jpy-consortium/jpy) |
| 40 | * [issue tracker](https://github.com/jpy-consortium/jpy/issues?state=open) |
| 41 | |
| 42 | How to build wheels for Linux and Mac |
| 43 | ------------------------------------- |
| 44 | |
| 45 | Install a JDK 11. Set `JDK_HOME` or |
| 46 | `JPY_JDK_HOME` to point to your JDK installation and run the build script: |
| 47 | |
| 48 | $ export JDK_HOME=<your-jdk-dir> |
| 49 | $ export JAVA_HOME=$JDK_HOME |
| 50 | $ pip install setuptools wheel |
| 51 | $ python setup.py build maven bdist_wheel |
| 52 | |
| 53 | On success, the wheel is found in the `dist` directory. |
| 54 | |
| 55 | To deploy the `jpy.jar` (if you don't know why you need this step, this is not |
| 56 | for you):: |
| 57 | |
| 58 | $ mvn clean deploy -DskipTests=true |
| 59 | |
| 60 | How to build a wheel for Windows |
| 61 | -------------------------------- |
| 62 | |
| 63 | Set `JDK_HOME` or `JPY_JDK_HOME` to point to your JDK installation. You'll |
| 64 | need Windows SDK 7.1 or Visual Studio C++ to build the sources. With Windows |
| 65 | SDK 7.1:: |
| 66 | |
| 67 | > SET VS90COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\ |
| 68 | > SET DISTUTILS_USE_SDK=1 |
| 69 | > C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\setenv /x64 /release |
| 70 | > SET JDK_HOME=<your-jdk-dir> |
| 71 | > pip install setuptools wheel |
| 72 | > python setup.py build maven bdist_wheel |
| 73 | |
| 74 | With Visual Studio 14 and higher it is much easier:: |
| 75 | |
| 76 | > SET VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\ |
| 77 | > SET JDK_HOME=<your-jdk-dir> |
| 78 | > pip install setuptools wheel |
| 79 | > python setup.py build maven bdist_wheel |
| 80 | |
| 81 | On success, the wheel can be found in the `dist` directory. |
| 82 | |
| 83 | How to install from sources |
| 84 | --------------------------- |
| 85 | |
| 86 | TBD |
| 87 | |
| 88 | Releasing jpy |
| 89 | ------------- |
| 90 | |
| 91 | The target reader of this section is a jpy developer wishing to release a new |
| 92 | jpy version. Note: You need to have Sphinx installed to update the |
| 93 | documentation. |
| 94 | |
| 95 | 1. Make sure all Java *and* Python units tests run green |
| 96 | 2. Remove the `-SNAPSHOT` qualifier from versions names in both the Maven |
| 97 | `pom.xml` and `setup.py` files, and update the version numbers and copyright |
| 98 | years in `jpyutil.py` and `doc/conf.py`. |
| 99 | 3. Generate Java API doc by running `mvn javadoc:javadoc` which will update |
| 100 | directory `doc/_static` |
| 101 | 4. Update documentation, `cd doc` and run `make html` |
| 102 | 5. http://peterdowns.com/posts/first-time-with-pypi.html |
| 103 | |
| 104 | |
| 105 | Running Tests |
| 106 | ---------------- |
| 107 | |
| 108 | Run: `python setup.py build test` |
| 109 | |
| 110 | Code Of Conduct |
| 111 | --------------- |
| 112 | |
| 113 | This project has adopted the [Contributor Covenant Code of Conduct](https://www.contributor-covenant.org/version/2/0/code_of_conduct/). |
| 114 | For more information see the [Code of Conduct](CODE_OF_CONDUCT.md) or contact [[email protected]](mailto:[email protected]) |
| 115 | with any additional questions or comments. |
| 116 | |
| 117 | Contributing |
| 118 | ------------ |
| 119 | |
| 120 | For instructions on contributing, see [CONTRIBUTING.md](CONTRIBUTING.md). |
| 121 | |
| 122 | |
| 123 | Notes |
| 124 | ----- |
| 125 | |
| 126 | Some of the details on this README are out of date. Efforts to improve them will be made in the future. |