Mapperkids Lee
Mapperkids Lee

Reputation: 155

How To Call Python script from AngularJS App

We using AngularJS as a frontend for our web application and some of the functions we are using python to do the calculation and get results back.

I would like to know is there any way to calling the python script directly in AngularJS? right now we are using $HTTP service to call PHP then in PHP using EXEC command to call the python, it is all working fine.

The problem is we notified there is about 5 seconds delay every time the python script call and I guess it is because of the overhead for the python interpreter and try to start it every time, we would like to eliminate that delay.

We are run on Redhat v 6.8 / AngualarJS 1.4x and Python 3.6 Anaconda3

Does anyone try something like that? any suggestions are welcome.

Thank you!

Upvotes: 1

Views: 15049

Answers (1)

Kavitha Madhavaraj
Kavitha Madhavaraj

Reputation: 592

You could write a python method that calls your calculation code and expose that method as a REST API.

You would need a library like Flask.

This tutorial explains how to do that : https://www.codementor.io/sagaragarwal94/building-a-basic-restful-api-in-python-58k02xsiq

This way you can directly call the python API.

Upvotes: 3

Related Questions