{"id":13579325,"url":"https://github.com/kivy/pyjnius","last_synced_at":"2025-05-13T16:07:52.609Z","repository":{"id":4278365,"uuid":"5407062","full_name":"kivy/pyjnius","owner":"kivy","description":"Access Java classes from Python","archived":false,"fork":false,"pushed_at":"2025-04-18T22:14:40.000Z","size":930,"stargazers_count":1431,"open_issues_count":93,"forks_count":256,"subscribers_count":85,"default_branch":"master","last_synced_at":"2025-04-19T09:11:04.348Z","etag":null,"topics":["java","jni","jni-android","jni-wrapper","python"],"latest_commit_sha":null,"homepage":"https://pyjnius.readthedocs.org","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kivy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2012-08-14T01:39:07.000Z","updated_at":"2025-04-16T06:28:58.000Z","dependencies_parsed_at":"2023-10-04T22:34:39.043Z","dependency_job_id":"582d9c0a-6587-48cc-96e4-773af6f0bcc2","html_url":"https://github.com/kivy/pyjnius","commit_stats":{"total_commits":605,"total_committers":90,"mean_commits":6.722222222222222,"dds":0.8082644628099174,"last_synced_commit":"17563c6f7a4c63ff0a4d01482217e350cddfbab5"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kivy%2Fpyjnius","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kivy%2Fpyjnius/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kivy%2Fpyjnius/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kivy%2Fpyjnius/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kivy","download_url":"https://codeload.github.com/kivy/pyjnius/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514759,"owners_count":21443208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jni","jni-android","jni-wrapper","python"],"created_at":"2024-08-01T15:01:38.381Z","updated_at":"2025-04-23T20:52:47.308Z","avatar_url":"https://github.com/kivy.png","language":"Python","funding_links":["https://opencollective.com/kivy)!","https://opencollective.com/kivy"],"categories":["Python"],"sub_categories":[],"readme":"PyJNIus\n=======\n\nPyJNIus is a [Python](https://www.python.org/) library for accessing \n[Java](https://www.java.com/) classes using the \n[Java Native Interface](https://docs.oracle.com/javase/8/docs/technotes/guides/jni/)\n(JNI). \n\nPyJNIus is managed by the [Kivy Team](https://kivy.org/about.html) and can be\nused with [python-for-android](https://github.com/kivy/python-for-android). \n\nIt can also be used independently of Kivy, on desktop and mobile platforms. \n\n\u003e [!WARNING]\n\u003e The [PyPI](https://pypi.org/) package name is now \n[pyjnius](https://pypi.org/project/pyjnius/) instead of `jnius`.\n\n\n[![Backers on Open Collective](https://opencollective.com/kivy/backers/badge.svg)](#backers)\n[![Sponsors on Open Collective](https://opencollective.com/kivy/sponsors/badge.svg)](#sponsors)\n[![GitHub contributors](https://img.shields.io/github/contributors-anon/kivy/pyjnius)](https://github.com/kivy/pyjnius/graphs/contributors)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)\n\n![PyPI - Version](https://img.shields.io/pypi/v/pyjnius)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyjnius)\n\n[![Tests](https://github.com/kivy/pyjnius/workflows/Continuous%20Integration/badge.svg)](https://github.com/kivy/pyjnius/actions)\n[![Tests (x86)](https://github.com/kivy/pyjnius/workflows/Continuous%20Integration%20(x86)/badge.svg)](https://github.com/kivy/pyjnius/actions)\n[![Builds](https://github.com/kivy/pyjnius/workflows/Continuous%20Delivery/badge.svg)](https://github.com/kivy/pyjnius/actions)\n\n\nInstallation\n------------\n\n```\npip install pyjnius\n```\n\nQuick overview\n--------------\n\n```python\n    \u003e\u003e\u003e from jnius import autoclass\n    \u003e\u003e\u003e autoclass('java.lang.System').out.println('Hello world')\n    Hello world\n    \n    \u003e\u003e\u003e Stack = autoclass('java.util.Stack')\n    \u003e\u003e\u003e stack = Stack()\n    \u003e\u003e\u003e stack.push('hello')\n    \u003e\u003e\u003e stack.push('world')\n    \u003e\u003e\u003e print(stack.pop())\n    world\n    \u003e\u003e\u003e print(stack.pop())\n    hello\n```\n\nUsage with python-for-android\n-----------------------------\n\n* Get [python-for-android](http://github.com/kivy/python-for-android)\n* Compile a distribution with kivy (PyJNIus will be automatically added)\n\nThen, you can do this kind of thing:\n\n```python\nfrom time import sleep\nfrom jnius import autoclass\n\nHardware = autoclass('org.renpy.android.Hardware')\nprint('DPI is', Hardware.getDPI())\n\nHardware.accelerometerEnable(True)\nfor x in range(20):\n    print(Hardware.accelerometerReading())\n    sleep(0.1)\n```\n\nIt will output something like:\n\n```\nI/python  ( 5983): Android kivy bootstrap done. __name__ is __main__\nI/python  ( 5983): Run user program, change dir and execute main.py\nI/python  ( 5983): DPI is 160\nI/python  ( 5983): [0.0, 0.0, 0.0]\nI/python  ( 5983): [-0.0095768067985773087, 9.3852710723876953, 2.2218191623687744]\nI/python  ( 5983): [-0.0095768067985773087, 9.3948478698730469, 2.2218191623687744]\nI/python  ( 5983): [-0.0095768067985773087, 9.3948478698730469, 2.2026655673980713]\nI/python  ( 5983): [-0.028730420395731926, 9.4044246673583984, 2.2122423648834229]\nI/python  ( 5983): [-0.019153613597154617, 9.3852710723876953, 2.2026655673980713]\nI/python  ( 5983): [-0.028730420395731926, 9.3852710723876953, 2.2122423648834229]\nI/python  ( 5983): [-0.0095768067985773087, 9.3852710723876953, 2.1835119724273682]\nI/python  ( 5983): [-0.0095768067985773087, 9.3756942749023438, 2.1835119724273682]\nI/python  ( 5983): [0.019153613597154617, 9.3948478698730469, 2.2122423648834229]\nI/python  ( 5983): [0.038307227194309235, 9.3852710723876953, 2.2218191623687744]\nI/python  ( 5983): [-0.028730420395731926, 9.3948478698730469, 2.2026655673980713]\nI/python  ( 5983): [-0.028730420395731926, 9.3852710723876953, 2.2122423648834229]\nI/python  ( 5983): [-0.038307227194309235, 9.3756942749023438, 2.2026655673980713]\nI/python  ( 5983): [0.3926490843296051, 9.3086557388305664, 1.3311761617660522]\nI/python  ( 5983): [-0.10534487664699554, 9.4331550598144531, 2.1068975925445557]\nI/python  ( 5983): [0.26815059781074524, 9.3469638824462891, 2.3463177680969238]\nI/python  ( 5983): [-0.1149216815829277, 9.3852710723876953, 2.31758713722229]\nI/python  ( 5983): [-0.038307227194309235, 9.41400146484375, 1.8674772977828979]\nI/python  ( 5983): [0.13407529890537262, 9.4235782623291016, 2.2026655673980713]\n```\n\nAdvanced example\n----------------\n\nWhen you use `autoclass`, it will discover all the methods and fields of the\nclass and resolve them. You may want to declare and use only what you\nneed. The previous example can be done manually as follows:\n\n```python\nfrom time import sleep\nfrom jnius import MetaJavaClass, JavaClass, JavaMethod, JavaStaticMethod\n\nclass Hardware(JavaClass):\n    __metaclass__ = MetaJavaClass\n    __javaclass__ = 'org/renpy/android/Hardware'\n    vibrate = JavaStaticMethod('(D)V')\n    accelerometerEnable = JavaStaticMethod('(Z)V')\n    accelerometerReading = JavaStaticMethod('()[F')\n    getDPI = JavaStaticMethod('()I')\n\n# use that new class!\nprint('DPI is', Hardware.getDPI())\n\nHardware.accelerometerEnable()\nfor x in range(20):\n    print(Hardware.accelerometerReading())\n    sleep(0.1)\n```\n\nYou can use the `signatures` method of `JavaMethod` and `JavaMultipleMethod`, to inspect the discovered signatures of a method of an object\n\n```python\n\u003e\u003e\u003e String = autoclass('java.lang.String')\n\u003e\u003e\u003e dir(String)\n['CASE_INSENSITIVE_ORDER', '__class__', '_JavaClass__cls_storage', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__javaclass__', '__javaconstructor__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__pyx_vtable__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'charAt', 'checkBounds', 'clone', 'codePointAt', 'codePointBefore', 'codePointCount', 'compareTo', 'compareToIgnoreCase', 'concat', 'contains', 'contentEquals', 'copyValueOf', 'empty', 'endsWith', 'equals', 'equalsIgnoreCase', 'finalize', 'format', 'getBytes', 'getChars', 'getClass', 'hashCode', 'indexOf', 'indexOfSupplementary', 'intern', 'isEmpty', 'join', 'lastIndexOf', 'lastIndexOfSupplementary', 'length', 'matches', 'nonSyncContentEquals', 'notify', 'notifyAll', 'offsetByCodePoints', 'regionMatches', 'registerNatives', 'replace', 'replaceAll', 'replaceFirst', 'split', 'startsWith', 'subSequence', 'substring', 'toCharArray', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'valueOf', 'wait']\n\u003e\u003e\u003e String.format.signatures()\n[(['java/util/Locale', 'java/lang/String', 'java/lang/Object...'], 'java/lang/String'), (['java/lang/String', 'java/lang/Object...'], 'java/lang/String')]\n```\nEach pair contains the list of accepted arguments types, and the returned type.\n\nTroubleshooting\n---------------\n\nMake sure a Java Development Kit (JDK) is installed on your operating system if\nyou want to use PyJNIus on desktop. OpenJDK is known to work, and the Oracle\nJava JDK should work as well.\n\nOn Windows, make sure `JAVA_HOME` points to your Java installation, so PyJNIus\ncan locate the `jvm.dll` file allowing it to start Java. This shouldn't be\nnecessary on macOS and Linux, but in case PyJNIus fails to find it, setting\n`JAVA_HOME` should help.\n\n## License\n\nPyJNIus is [MIT licensed](LICENSE), actively developed by a great\ncommunity and is supported by many projects managed by the \n[Kivy Organization](https://www.kivy.org/about.html).\n\n## Documentation\n\n[Documentation for this repository](https://pyjnius.readthedocs.io/).\n\n## Support\n\nAre you having trouble using PyJNIus or any of its related projects in the Kivy\necosystem?\nIs there an error you don’t understand? Are you trying to figure out how to use \nit? We have volunteers who can help!\n\nThe best channels to contact us for support are listed in the latest \n[Contact Us](https://github.com/kivy/pyjnius/blob/master/CONTACT.md) document.\n\n## Contributing\n\nPyJNIus is part of the [Kivy](https://kivy.org) ecosystem - a large group of\nproducts used by many thousands of developers for free, but it\nis built entirely by the contributions of volunteers. We welcome (and rely on) \nusers who want to give back to the community by contributing to the project.\n\nContributions can come in many forms. See the latest \n[Contribution Guidelines](https://github.com/kivy/pyjnius/blob/master/CONTRIBUTING.md)\nfor how you can help us.\n\n## Code of Conduct\n\nIn the interest of fostering an open and welcoming community, we as \ncontributors and maintainers need to ensure participation in our project and \nour sister projects is a harassment-free and positive experience for everyone. \nIt is vital that all interaction is conducted in a manner conveying respect, \nopen-mindedness and gratitude.\n\nPlease consult the [latest Code of Conduct](https://github.com/kivy/pyjnius/blob/master/CODE_OF_CONDUCT.md).\n\n## Contributors\n\nThis project exists thanks to \n[all the people who contribute](https://github.com/kivy/pyjnius/graphs/contributors).\n[[Become a contributor](CONTRIBUTING.md)].\n\n\u003cimg src=\"https://contrib.nn.ci/api?repo=kivy/pyjnius\u0026pages=5\u0026no_bot=true\u0026radius=22\u0026cols=18\"\u003e\n\n## Backers\n\nThank you to [all of our backers](https://opencollective.com/kivy)! \n🙏 [[Become a backer](https://opencollective.com/kivy#backer)]\n\n\u003cimg src=\"https://opencollective.com/kivy/backers.svg?width=890\u0026avatarHeight=44\u0026button=false\"\u003e\n\n## Sponsors\n\nSpecial thanks to \n[all of our sponsors, past and present](https://opencollective.com/kivy).\nSupport this project by \n[[becoming a sponsor](https://opencollective.com/kivy#sponsor)].\n\nHere are our top current sponsors. Please click through to see their websites,\nand support them as they support us. \n\n\u003c!--- See https://github.com/orgs/kivy/discussions/15 for explanation of this code. --\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/0/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/0/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/1/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/1/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/2/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/2/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/3/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/3/avatar.svg\"\u003e\u003c/a\u003e\n\n\u003ca href=\"https://opencollective.com/kivy/sponsor/4/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/4/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/5/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/5/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/6/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/6/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/7/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/7/avatar.svg\"\u003e\u003c/a\u003e\n\n\u003ca href=\"https://opencollective.com/kivy/sponsor/8/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/8/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/9/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/9/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/10/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/10/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/11/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/11/avatar.svg\"\u003e\u003c/a\u003e\n\n\u003ca href=\"https://opencollective.com/kivy/sponsor/12/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/12/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/13/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/13/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/14/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/14/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/kivy/sponsor/15/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/kivy/sponsor/15/avatar.svg\"\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkivy%2Fpyjnius","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkivy%2Fpyjnius","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkivy%2Fpyjnius/lists"}