Code Monkey home page Code Monkey logo

graalpy-jbang's Introduction

Use GraalPy in a Java embedding with JBang

This repository makes it easy to create a JBang app that uses GraalPy & Java.

See our example graalpy.java for a template. You can use PIP comments to add packages. Native image builds should just work. Modify the main method to suit your use case, the other two classes in the file are just helpers that you should be able to ignore.

Simple example to get started

//DEPS org.graalvm.python:python-language:23.1.0
//DEPS org.graalvm.python:python-resources:23.1.0
//DEPS org.graalvm.python:python-launcher:23.1.0
//DEPS https://github.com/timfel/graalpy-jbang/tree/main#:SNAPSHOT
//PIP termcolor
public class graalpy {
public static void main(String[] args) {
try (Context context = VirtualGraalPyContext.getContext()) {
switch (args.length) {
case 0:
context.eval("python", "import site; site._script()");
break;
case 1:
context.eval("python", args[0]);
break;
default:
throw new IllegalArgumentException("The main() helper only takes 0-1 arguments.");
}
} catch (PolyglotException e) {
if (e.isExit()) {
System.exit(e.getExitStatus());
} else {
throw e;
}
}
}
}

More interesting example "application"

JBang❤️Pygal

graalpy-jbang's People

Contributors

timfel avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.