jbang-python: Java in your Python

less than 1 minute read

Happy to announce jbang-python - a pypi package which brings your Java to your Python project or notebook.

python jbang

jbang-python supports running any kind java code that JBang supports.

Wether that is a script from the AppStore, a Maven GAV, a jar or simply a java file stored in your project.


In your requirements.txt add:


or install it using pip install jbang

Then in your python code you can do:

import jbang
output = jbang.exec('--java 21', 'properties@jbangdev', 'java').stdout
output = jbang.exec('hello.java').stdout

With a hello.java that contains:

//DEPS com.github.lalyos:jfiglet:0.0.8

import com.github.lalyos.jfiglet.FigletFont;

class hello {

    public static void main(String... args) throws Exception {
               "Hello " + ((args.length>0)?args[0]:"jbang")));  ;;

When you run this it will automatically install JBang and Java if necessary and then run the requested alias and java code.

Besides using it in your python code locally you can also use it from Jupyter Notebooks.

The jbang-python package is available on pypi and the source code is available on https://github.com/jbangdev/jbang-python.

Have fun!




Leave a comment