ninia/jep logo

ninia/jep

Free

Embed Python in Java

FreeFree tier
Type
Open Source

About ninia/jep

Jep (Java Embedded Python) is an open-source library that embeds the CPython interpreter in Java applications using JNI. It enables Java programs to call and execute Python code, access CPython extension modules, and leverage Python for scripting without recompiling Java. Jep supports multiple, simultaneous sub-interpreters (sandboxed or shared), provides an interactive console similar to CPython's, and offers Numpy support for Java primitive arrays. It requires Python 3.10+ and Java 1.8+.

Key Features

Embeds CPython in Java through JNI for native performance
Supports multiple, simultaneous, sandboxed sub-interpreters or shared interpreters
Interactive Jep console similar to Python's interactive shell
Numpy support for Java primitive arrays
Access to mature CPython extension modules and Python libraries
Script established Java code without recompilation
Cross-platform deployment (both Java and Python environments)

Pros & Cons

Pros
  • Native CPython interpreter can be significantly faster than alternative Python-in-Java solutions
  • Access to a vast collection of mature and well-documented Python modules
  • Enables interactive scripting of Java without recompilation
  • Supports multiple independent sub-interpreters for isolation
  • Cross-platform: works on any OS that supports JVM and CPython
  • Open source with permissive license
Cons
  • Requires separate CPython installation and native JNI binding (not a pure Java solution)
  • Building from source needs JDK, Python, setuptools, and numpy to be installed
  • May add deployment complexity compared to all-Java alternatives like Jython
  • Dependency on CPython version (currently Python >= 3.10)

Best For

Scripting Java applications with Python for rapid prototyping or custom logicUsing Python's extensive ecosystem (e.g., NumPy, SciPy) within Java projectsEmbedding Python as a scripting engine for configurability and automation in Java applicationsSandboxed execution of untrusted Python code in Java environmentsMigrating or integrating existing CPython codebases with Java systems

FAQ

What is Jep?
Jep (Java Embedded Python) is a library that embeds CPython in Java using JNI, allowing Java programs to run Python code and access Python modules directly.
How do I install Jep?
Install via pip with 'pip install jep' or download the source and run 'pip install .'. Building requires JDK and Python to be installed beforehand.
What are the dependencies for Jep?
Jep requires Python 3.10 or later, Java 1.8 or later, and optionally NumPy 1.7+ for array support.
Does Jep support multiple Python interpreters?
Yes, Jep supports multiple, simultaneous, mostly sandboxed sub-interpreters, as well as shared interpreters.
Is Jep open source?
Yes, Jep is open source and hosted on GitHub under the ninia organization.