https://github.com/arnie97/import-java
Import Java packages into Python - Syntax sugar for PyJNIus or JavaBridge
https://github.com/arnie97/import-java
ffi ffi-bindings ffi-wrapper magic
Last synced: 9 months ago
JSON representation
Import Java packages into Python - Syntax sugar for PyJNIus or JavaBridge
- Host: GitHub
- URL: https://github.com/arnie97/import-java
- Owner: Arnie97
- License: mit
- Created: 2018-04-27T09:52:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-02T12:36:06.000Z (over 7 years ago)
- Last Synced: 2024-10-05T09:47:16.632Z (over 1 year ago)
- Topics: ffi, ffi-bindings, ffi-wrapper, magic
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 17
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# import-java
[](https://travis-ci.org/Arnie97/import-java)
[](https://codecov.io/gh/Arnie97/import-java)
[](https://pypi.org/project/import-java)
[](https://pypi.org/project/import-java)
[](LICENSE)
Import your Java packages seamlessly into CPython.
## Quick Start
We'll create a temporary file in Java and then read it in Python to illustrate the usage:
```python
>>> import java
>>> with java:
... from java.lang import String
... from java.nio.file import Files
...
>>> temp_path = Files.createTempFile('sample', '.tmp')
>>> sample_text = String('Greetings from Java')
>>> Files.write(temp_path, sample_text.getBytes())
>>> with open(temp_path.toString()) as f:
... print(repr(f.read()))
...
'Greetings from Java'
```
You can also use `_` as a short alias for `java.lang`:
```python
>>> with java:
... from _ import System
...
>>> System.getProperty('java.specification.version')
'1.8'
```
Wildcard imports (such as `from java.util import *`) are not supported yet.
## Dependencies
Either [PyJNIus](https://github.com/kivy/pyjnius) or [JavaBridge](https://github.com/LeeKamentsky/python-javabridge). PyJNIus is preferred, as [JavaBridge cannot disambiguate overloaded methods with the same number of parameters](https://github.com/LeeKamentsky/python-javabridge/issues/55).
## Installation
`$ pip install import-java`
## License
MIT.
## See also
* [pythonnet](https://github.com/pythonnet/pythonnet) - Import .NET CLR modules
* [hack-py-import](https://github.com/iblis17/hack-py-import) - Import your C libraries