Snapshot of kivy/pyjnius: 1.5k★, Python, Backend. Access Java classes from Python
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
PyJNIus is a Python library for accessing
Java classes using the
Java Native Interface
(JNI).
PyJNIus is managed by the Kivy Team and can be
used with python-for-android.
It can also be used independently of Kivy, on desktop and mobile platforms.
[!WARNING]
The PyPI package name is now
pyjnius instead of jnius.
Installation
pip install pyjnius
Quick overview
>>> from jnius import autoclass
>>> autoclass('java.lang.System').out.println('Hello world')
Hello world
>>> Stack = autoclass('java.util.Stack')
>>> stack = Stack()
>>> stack.push('hello')
>>> stack.push('world')
>>> print(stack.pop())
world
>>> print(stack.pop())
hello
Usage with python-for-android
Get python-for-android
Compile a distribution with kivy (PyJNIus will be automatically added)
Then, you can do this kind of thing:
from time import sleep
from jnius import autoclass
Hardware = autoclass('org.renpy.android.Hardware')
print('DPI is', Hardware.getDPI())
Hardware.accelerometerEnable(True)
for x in range(20):
print(Hardware.accelerometerReading())
sleep(0.1)
When you use autoclass, it will discover all the methods and fields of the
class and resolve them. You may want to declare and use only what you
need. The previous example can be done manually as follows:
from time import sleep
from jnius import MetaJavaClass, JavaClass, JavaMethod, JavaStaticMethod
class Hardware(JavaClass, metaclass=MetaJavaClass):
__javaclass__ = 'org/renpy/android/Hardware'
vibrate = JavaStaticMethod('(D)V')
accelerometerEnable = JavaStaticMethod('(Z)V')
accelerometerReading = JavaStaticMethod('()[F')
getDPI = JavaStaticMethod('()I')
# use that new class!
print('DPI is', Hardware.getDPI())
Hardware.accelerometerEnable(True)
for x in range(20):
print(Hardware.accelerometerReading())
sleep(0.1)
You can use the signatures method of JavaMethod and JavaMultipleMethod, to inspect the discovered signatures of a method of an object
Each pair contains the list of accepted arguments types, and the returned type.
Troubleshooting
Make sure a Java Runtime Environment (JRE) is installed if you want to use
PyJNIus on desktop. A Java Development Kit (JDK) is required when building
PyJNIus from source. OpenJDK is known to work, and Oracle Java should
work as well. See the installation documentation
for details.
On Windows, make sure JAVA_HOME points to your Java installation, so PyJNIus
can locate the jvm.dll file allowing it to start Java. This shouldn't be
necessary on macOS and Linux, but in case PyJNIus fails to find it, setting
JAVA_HOME should help.
License
PyJNIus is MIT licensed, actively developed by a great
community and is supported by many projects managed by the
Kivy Organization.
Documentation
Documentation for this repository.
Support
Are you having trouble using PyJNIus or any of its related projects in the Kivy
ecosystem?
Is there an error you don’t understand? Are you trying to figure out how to use
it? We have volunteers who can help!
The best channels to contact us for support are listed in the latest
Contact Us document.
Contributing
PyJNIus is part of the Kivy ecosystem - a large group of
products used by many thousands of developers for free, but it
is built entirely by the contributions of volunteers. We welcome (and rely on)
users who want to give back to the community by contributing to the project.
Contributions can come in many forms. See the latest
Contribution Guidelines
for how you can help us.
Code of Conduct
In the interest of fostering an open and welcoming community, we as
contributors and maintainers need to ensure participation in our project and
our sister projects is a harassment-free and positive experience for everyone.
It is vital that all interaction is conducted in a manner conveying respect,
open-mindedness and gratitude.
Please consult the latest Code of Conduct.
Contributors
This project exists thanks to
all the people who contribute.
[Become a contributor].
Backers
Thank you to all of our backers!
🙏 [Become a backer]
Sponsors
Special thanks to
all of our sponsors, past and present.
Support this project by
[becoming a sponsor].
Here are our top current sponsors. Please click through to see their websites,
and support them as they support us.
The most recent commit recorded on kivy/pyjnius was 3 months ago, based on the GitHub push timestamp. The repository has 328 forks — one of the better signals of community interest.
How does kivy/pyjnius compare to other Backend projects?
kivy/pyjnius is tracked by TopGit in the Backend category, with 1.5k GitHub stars and written in Python. Browse the Backend topic page on TopGit to compare it against similar projects by stars and activity.
How many stars does kivy/pyjnius have?
kivy/pyjnius has 1.5k GitHub stars — refresh the page for the live number, or check github.com/kivy/pyjnius. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What is kivy/pyjnius?
kivy/pyjnius (kivy/pyjnius) is a Python project on GitHub. From the project's own README: Access Java classes from Python
What language is kivy/pyjnius written in?
kivy/pyjnius is written primarily in Python. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is kivy/pyjnius associated with?
GitHub's repository topics for kivy/pyjnius: "java", "jni", "jni-android", "jni-wrapper", "python". TopGit's editorial category is Backend.
Why is kivy/pyjnius categorized under Backend?
TopGit places kivy/pyjnius in the Backend category based on its GitHub topics and description (tagged: "java", "jni", "jni-android"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Still deciding about pyjnius?
One click hands the question to an AI along with this page — see what it says about pyjnius.