Home Wiki Blog Forum GEXF.net

Gephi forums

Community support

Tips to use the Gephi Toolkit with other JVM languages

Automated tasks on server

Tips to use the Gephi Toolkit with other JVM languages

Postby jbilcke » 04 Aug 2010 19:39

Hi, I am starting a topic for people who would like to discuss the use of the Gephi Toolkit from JVM language XYZ.

The Gephi Toolkit let you call all the Gephi Core features from languages running inside the Java Virtual Machine (JVM).

Such languages include Java of course, but also scripting, functional and/or dynamic languages like Groovy, Scala, Clojure, Jython or JRuby.

However, be aware that some of these languages relies on homemade standard libraries (Jython, by example, is "battery included")
so generated bytecode (.class) might need to be bundled with such library (by example, jythonlib.jar, 17Mb), adding some weight to the final package.

Also, for languages like Jython or JRuby, you cannot directly call original Python or Ruby extensions written in native code, because well, they are for the native Python/Ruby virtual machines (maybe a sick JNA/JNI expert hack some tricks, but we love Java portability, don't we).

If all these constrains don't stop you ;) here are some tips for the languages I gave a try:


The best option so far for develoment only, is to use Netbeans IDE 6.9, and install the Python/Jython plugin. This is the most easy. You will have only to add the gephi-tookit.jar to the Java Class Path (I'll update this post to add some screenshots tonight).

Another good option for development without Netbeans, and the best for production, is to install Jython on your system.
It seems to be installed by default on some systems like Ubuntu, at version 2.2.x.
This correspond to Python 2.2x API. This may be enough for you, but I still recommend to use the most recent stable version (eg. 2.5.x) if possible (for speed, memory, stability fixes).

An option which should work in theory, would be to package the jython library (JAR) with your script, and run it with java -jar jythonlib.jar myscript.py --args.
I tried to do this, basic jython scripts work with this technique, but in my case it cannot find the Gephi Toolkit for an obscure reason (even when I add it to the class path using --classpath XYZ or -J -cp XYZ).

Here is a template for Netbeans-based Jython projects:

Code: Select all
# -*- coding: utf-8 -*-

# note: this is a simple example. a real jython script should handle args,
# exceptions..

__author__="Julian Bilcke"
__date__ ="$Aug 4, 2010 12:20:31 AM$"

# all the major API are exposed under the "gephi" module
# plus the major Controller (more to come soon, see the gephi..py module!)
from gephi import ProjectController

pc = ProjectController()

print "creating a new project.."

print "getting current workspace"
workspace = pc.getCurrentWorkspace()
print "workspace:",dir(workspace)

As you can see, this can actually be very concise since a lot of the work is done at run time, and type conversion is done automagically by Jython (you didn't imported or declared workspace here, don't you?)

For this small script which don't do a lot for the moment, I wrote a small gephi.py wrapper around the gephi toolkit for my own purposes, but you could extend it with more pythonic features, lambdas, introspections and so on.

Other languages

I invite you to try on your preferred JVM scripting language, if you have some tips I will add them to the list :)
“All things are meaningless accidents, works of chance unless your marveling gaze, as it probes, connects and orders, makes them divine.” — Wilhelm Willms
User avatar
Gephi Core Developer
Posts: 41
Joined: 10 Dec 2009 18:48
Location: Paris, France

Re: Tips to use the Gephi Toolkit with other JVM languages

Postby psychemedia » 18 Dec 2011 15:29

Java and Jython are completely alien to me... so I appreciate this is a really naive question... but I'll ask it anyway...

Assuming I have jython installed on my machine, how do I enter a Jython session that includes the gephi-toolkit.jar?
Posts: 18
Joined: 15 Apr 2010 18:50

Return to Toolkit

Who is online

Users browsing this forum: No registered users and 0 guests