Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

With the openLCA API, you can automate workflows, read and write data, run calculations, analyse results, or even build your own user interface on top of openLCA. To enable this, openLCA exposes an inter-process communication (IPC) protocol that works with any programming language (including Python, JavaScript, .NET, Go, or Java1) and can be served either directly by the desktop application or by a server running only the openLCA back-end.

This documentation covers the available API methods in detail with many examples. You can modify and try the interactive JavaScript examples right inside this manual. Simply start the IPC server in openLCA (see below) and click the Run button beneath an example. Your browser may prompt you for permission to access the local openLCA server, but everything runs locally on your machine, no data is sent to external servers.

// list the impact assessment methods of the active database
const methods = await call("data/get/descriptors", { "@type": "ImpactMethod" });
console.log(`found ${methods.length} impact assessment methods:`);
for (const method of methods) {
  console.log(`- ${method.name}`);
}

The example uses the small helper function call for sending requests to the IPC server, see running the JavaScript examples below.

Starting an IPC server

In the openLCA desktop application, you can start an IPC server for the currently active database from the tools menu: Tools > Developer tools > IPC Server. This brings up the following dialog where you can start and stop the server:

For headless stand-alone servers, please see the appendix stand-alone servers.

Available protocols and client libraries

Typically, you will use a client library such as olca-ipc.py to call the API. Under the hood, openLCA supports three protocols built on the same service back-end and the openLCA Schema as data format:

  • JSON-RPC over HTTP (default IPC server) – lightweight and easy to use anywhere, including directly in a browser.

  • gRPC – great when you already use gRPC or want generated client code from the service definitions.

  • REST (via openLCA web-services) – JSON over HTTP, well suited for web applications.

The table below lists some available client libraries and demo projects by language and protocol:

LanguageTypeProtocol
olca-ipc.pyPythonClient libraryJSON-RPC, REST
olca-ipc.tsJavaScript/TypeScriptClient libraryJSON-RPC, REST
ProtoLCA-DemoC#DemogRPC
protolca-js-exampleJavaScript/NodeClient librarygRPC
olcarpc.pyPythonClient librarygRPC

Running the JavaScript examples

The JavaScript examples in this documentation can be edited and executed directly in the browser with the Run button below an example (or with Ctrl+Enter in the example). For this, an IPC server needs to run on port 8080 (in openLCA: Tools > Developer tools > IPC Server).

Some examples use the following helper function call for the JSON-RPC calls. It is available in the runnable examples of this documentation; when you use such an example outside of this documentation, you need to add this function:

async function call(method, params) {
  const resp = await fetch("http://localhost:8080", {
    method: "POST",
    body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
  });
  const r = await resp.json();
  if (r.error) {
    throw new Error(r.error.message);
  }
  return r.result;
}


  1. Because openLCA runs on the JVM, languages like Java, Kotlin, Scala, or Clojure can use the headless openLCA Java API directly as standard libraries instead of going through an IPC server (this is also how openLCA’s built-in Python (powered by Jython) editor accesses openLCA). ↩