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.

Example

In your requirements.txt add:

jbang-python

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
print(output)
output = jbang.exec('hello.java').stdout
print(output)

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 {
        System.out.println(FigletFont.convertOneLine(
               "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!

Tags:

Categories:

Updated:

Leave a comment