Blog post

Calling a Python Function From Java

By Raj Bala | February 07, 2020 | 0 Comments

I spend a great deal of time thinking about serverless computing and what it means to application development, operations, etc.

But one of the most understated aspects from the perspective of a software developer is that I can mix and match programming languages and frameworks like never before.

Writing a Java application, but you want to take advantage of Python’s rich data science libraries? Invoke those Python capabilities using your choice of functions as a service (FaaS) platform!

The way you do this when using Python on AWS Lambda is like this:

response = client.invoke(

MyJavaFunction is another Lambda function that could be Java, Go, Ruby or whatever the platform supports. The Payload parameter is the other important part. Typically, I use byte-encoded JSON payloads that are minimal in size. The called function gets an event parameter with the byte-encoded JSON.

Want to do something similar on Azure? It’s called a Durable Function.

Ultimately, this is the benefit of single-purpose microservices. You can use the right tool for the right job rather than being constrained to one language, one framework or even one database.

The Gartner Blog Network provides an opportunity for Gartner analysts to test ideas and move research forward. Because the content posted by Gartner analysts on this site does not undergo our standard editorial review, all comments or opinions expressed hereunder are those of the individual contributors and do not represent the views of Gartner, Inc. or its management.

Leave a Comment