# Python in java for java servlet

**URL:** <https://community.deeplearning.ai/t/python-in-java-for-java-servlet/231053>\
**Category:** AI Discussions\
**Created:** [November 15, 2022, 5:12pm UTC](https://community.deeplearning.ai/t/python-in-java-for-java-servlet/231053 "2022-11-15T17:12:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![saurabh\_nale](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@saurabh\_nale](https://community.deeplearning.ai/u/saurabh_nale)\
**Post date:** [November 15, 2022, 5:12pm UTC](https://community.deeplearning.ai/t/python-in-java-for-java-servlet/231053/1 "2022-11-15T17:12:58Z")

</div>

So currently i’m working on a project for which i am using java servlets and stuck on to how to use python in java so i can make predictions using regression plz help me through it…

---

<div class="post-metadata">

**Author:** ![Juan\_Olano](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/juan_olano/32/27125_2.png) [@Juan\_Olano](https://community.deeplearning.ai/u/Juan_Olano)\
**Post date:** [November 15, 2022, 5:20pm UTC](https://community.deeplearning.ai/t/python-in-java-for-java-servlet/231053/2 "2022-11-15T17:20:58Z")

</div>

Hi @saurabh_nale ,

Welcome to the community!

Regarding your question… I don’t think you can use “Python in Java” but you can “call Python FROM Java”. And for that, there are many methods. Just do a quick google on “how to call python from java” and you’ll get a lot of answers.

I hope this helps!

Juan.

---

<div class="post-metadata">

**Author:** ![saurabh\_nale](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@saurabh\_nale](https://community.deeplearning.ai/u/saurabh_nale)\
**Post date:** [November 15, 2022, 6:34pm UTC](https://community.deeplearning.ai/t/python-in-java-for-java-servlet/231053/3 "2022-11-15T18:34:38Z")

</div>

Thanks for reply, can you suggest one simple method through which i can call functions of python from java this will be very helpful for me.

---

<div class="post-metadata">

**Author:** ![Juan\_Olano](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/juan_olano/32/27125_2.png) [@Juan\_Olano](https://community.deeplearning.ai/u/Juan_Olano)\
**Post date:** [November 15, 2022, 6:40pm UTC](https://community.deeplearning.ai/t/python-in-java-for-java-servlet/231053/4 "2022-11-15T18:40:59Z")

</div>

Unfortunately I don’t have experience on that, so I could not provide a recommendation.

---

<div class="post-metadata">

**Author:** ![Juan\_Olano](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/juan_olano/32/27125_2.png) [@Juan\_Olano](https://community.deeplearning.ai/u/Juan_Olano)\
**Post date:** [November 15, 2022, 7:02pm UTC](https://community.deeplearning.ai/t/python-in-java-for-java-servlet/231053/5 "2022-11-15T19:02:50Z")

</div>

One idea that comes to mind:

I have some experience with FastAPI. Basically you can create a REST service with FastAPI, and the FastAPI wraps the Python functions.

Then, from your Java application, you can do REST calls to your Python model via the services exposed by the FastAPI.

---

<div class="post-metadata">

**Author:** ![AbdElRhaman\_Fakhry](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/abdelrhaman_fakhry/32/174426_2.png) [@AbdElRhaman\_Fakhry](https://community.deeplearning.ai/u/AbdElRhaman_Fakhry)\
**Post date:** [November 15, 2022, 7:03pm UTC](https://community.deeplearning.ai/t/python-in-java-for-java-servlet/231053/6 "2022-11-15T19:03:10Z")

</div>

HI @saurabh_nale

I think these 2 articles will help you  
this calling Java from python

> <https://stackoverflow.com/questions/3652554/calling-java-from-python>

> **[How to Call Python From Java | Baeldung](https://www.baeldung.com/java-working-with-python)**
>
> Learn the most common ways of calling Python code from Java.

this calling python from Java

> <https://stackoverflow.com/questions/8898765/calling-python-in-java>

but my advice is not make your code so complicated …so choice one language and do all project with that and I recommend python as it is an open source language and it has so many libraries and built in models had been implemented with the lowest cost and lowest time in run

please feel free to ask any questions,  
Thanks,  
Abdelrahman

---

<div class="post-metadata">

**Author:** ![saurabh\_nale](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@saurabh\_nale](https://community.deeplearning.ai/u/saurabh_nale)\
**Post date:** [November 16, 2022, 2:25am UTC](https://community.deeplearning.ai/t/python-in-java-for-java-servlet/231053/7 "2022-11-16T02:25:37Z")

</div>

Thanks you are best​👍👍

---

<div class="post-metadata">

**Author:** ![saurabh\_nale](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@saurabh\_nale](https://community.deeplearning.ai/u/saurabh_nale)\
**Post date:** [November 16, 2022, 2:26am UTC](https://community.deeplearning.ai/t/python-in-java-for-java-servlet/231053/8 "2022-11-16T02:26:19Z")

</div>

Thanks for help i appreciate it
