Skip to main content

Launch Java code from Python and the CLI, installation-free.

Project description

build status Documentation

jgo: painless Java environments and execution

Summary

jgo launches Java applications directly from Maven coordinates—no installation required. Specify a Maven artifact identifier and an optional main class, and jgo resolves dependencies, materializes the environment including the version of Java needed, and runs your program.

# Run Jython REPL (latest version)
jgo org.python:jython-standalone

# Run with specific version
jgo org.python:jython-standalone:2.7.3

Features

  • Zero-configuration execution: Automatic Java download and version management thanks to cjdk integration
  • Pure Python dependency resolver: No Maven installation required to resolve dependency graphs
  • Reproducible environments: jgo.toml project files with lock files (like package.json + package-lock.json)
  • Three-layer architecture: Independently useful layers for Maven resolution, environment building, and execution
  • Powerful Python API: Fine-grained control over dependency resolution and execution
  • Intelligent module handling: Full support of the Java module system (JPMS), including intelligent classification of dependencies on module-path or class-path as appropriate

Quick Start

CLI Usage

# Run Jython REPL
jgo org.python:jython-standalone

# Run with arguments
jgo org.python:jython-standalone -- -- script.py --verbose

# Multiple artifacts with main class (use @ separator)
jgo org.scijava:scijava-common+org.scijava:scripting-jython@ScriptREPL

# Force update from remote repos
jgo -u org.python:jython-standalone

# Use specific Java version
jgo --java-version 17 net.imagej:imagej

# Print classpath without running
jgo info classpath org.python:jython-standalone

# Preview commands without executing (--dry-run)
jgo --dry-run run org.scijava:parsington         # See java command
jgo --dry-run init org.python:jython-standalone  # Preview jgo.toml

Python API

import jgo

# Simple one-liner
jgo.run("org.python:jython-standalone:2.7.3", app_args=["script.py"])

# Build environment without running
env = jgo.build("org.python:jython-standalone")
print(env.classpath)  # List of JAR paths

# Resolve dependencies
components = jgo.resolve("org.python:jython-standalone")
for comp in components:
    print(f"{comp.groupId}:{comp.artifactId}:{comp.version}")

Project Mode with jgo.toml

Create reproducible environments:

# jgo.toml
[environment]
name = "my-java-app"

[repositories]
scijava.public = "https://maven.scijava.org/content/groups/public"

[dependencies]
coordinates = ["net.imagej:imagej:2.15.0"]

[entrypoints]
default = "main"
main = "net.imagej.Main"

[settings]
cache_dir = ".jgo"  # Local environment like .venv
# Run from current directory
jgo sync

# Creates .jgo/ with jars/ and jgo.lock.toml

Installation

Installing jgo with uv
uv tool install "jgo[cli]"
Installing jgo with pip
pip install "jgo[cli]"
Installing jgo with conda
conda install -c conda-forge jgo
Installing jgo from source
git clone https://github.com/apposed/jgo
uv tool install --with-editable "jgo[cli]" jgo

When installed in this fashion, changes to the jgo source code will be immediately reflected when running jgo from the command line.

Using jgo as a library dependency
uv add jgo

or

pixi add jgo

Not sure which to use? Read this.

The cli extra (jgo[cli]) is only needed when using the jgo command-line tool, not when using jgo as a Python library.

Examples

Program Command
Jython REPL jgo org.python:jython-standalone
JRuby eval echo "puts 'Hello Ruby'" | jgo org.jruby:jruby-complete@jruby.Main
Groovy REPL jgo org.codehaus.groovy:groovy-groovysh+commons-cli:commons-cli:1.3.1@shell.Main

Note the usage of the + syntax as needed to append elements to the classpath.

If you add scijava.public = https://maven.scijava.org/content/groups/public to the [repositories] section of your settings file (see the configuration docs), you can also try:

Program Command
SciJava REPL with JRuby jgo org.scijava:scijava-common+org.scijava:scripting-jruby@ScriptREPL
SciJava REPL with Jython jgo org.scijava:scijava-common+org.scijava:scripting-jython@ScriptREPL
SciJava REPL with Groovy jgo org.scijava:scijava-common+org.scijava:scripting-groovy@ScriptREPL
SciJava REPL with Clojure jgo org.scijava:scijava-common+org.scijava:scripting-clojure@ScriptREPL
SciJava REPL with JavaScript jgo org.scijava:scijava-common+org.scijava:scripting-javascript@ScriptREPL

FAQ

  • Is it fast? Endpoints are synthesized in a local cache under ~/.cache/jgo. So invoking the same endpoint a second time is really quick.
  • What does "no installation" mean? Classpath elements are hard-linked into ~/.cache/jgo from ~/.m2/repository rather than copied, so the cache folder has a tiny footprint even if you execute lots of different endpoints.
  • What if an endpoint has a new version? Pass the -u flag to jgo to rebuild the endpoint. Note that unlike mvn, jgo does not check for updates otherwise.

Documentation

Full documentation is available at jgo.apposed.org:

Use help(jgo) in Python for detailed API documentation.

Development

Code style

jgo uses ruff for linting and formatting:

make lint

Testing

# Run all tests
make test

# Run specific test file
bin/test.sh tests/test_maven_basic.py

# Run with coverage
uv run pytest --cov=src/jgo tests/

Alternatives

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jgo-3.0.0.tar.gz (234.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jgo-3.0.0-py3-none-any.whl (178.6 kB view details)

Uploaded Python 3

File details

Details for the file jgo-3.0.0.tar.gz.

File metadata

  • Download URL: jgo-3.0.0.tar.gz
  • Upload date:
  • Size: 234.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jgo-3.0.0.tar.gz
Algorithm Hash digest
SHA256 75ca0ce33ba0218ff9ef62aef7cd78269b86c03f4e1f051180e4e7254bd7e5a0
MD5 f4d5b81a41a01f3cdc554b4a58cbe42b
BLAKE2b-256 45178d271ba2c93cd31c25da1a259216c3cfd0e6086ebde8bc9731085db99e22

See more details on using hashes here.

File details

Details for the file jgo-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: jgo-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 178.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jgo-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b1a09be7ee2d9e98950a63e9963236630346127a2a00c28ebf78a9438da51f4
MD5 25b7bb7cac7c7214ddc98e3f023e85ad
BLAKE2b-256 a65259cba9fa9df6910bd0c0ecd22eb509297be8e0da203f6918d61d43b0316c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page