How does a mobile app interact with a python script?

Viewed 407

I have no idea how one might "connect" backend to front end and where you may store/host each entity.

Say I have a python script/program that has various functions that when called return certain information (currently working in the terminal) and I want to display said information on a native iOS or Android app. The python script manipulates data and outputs pandas data frames and other text and numeric information.

Once the shell of the app has been build etc, how would one go about making a button on the app call a function from a python script for example?

I currently imagine that both entities would be hosted separately, say the python code on AWS, and the app makes a request to the server for a particular function (no idea how?) and the python script sends a response (in what form? JSON?) and the app code interprets it and displays it... Hope this isn't to vague but I've no experience with apps or hosting code etc...

1 Answers

I suggest putting your Python code into an AWS Lambda function, and exposing it as an HTTP API via Amazon API Gateway.

Next, you'll create a simple Android app in Kotlin with Android Studio. Your Android app will call the HTTP API to get results from the Python script (the Python script is running in AWS.)

You can used AWS' Amplify Android project to automate most of this. The documentation below will guide you to create simple Lambda function, and to bootstrap the communication from an Android project. Once you have the Lambda, update it so that it invokes your Python code.

https://docs.amplify.aws/lib/restapi/getting-started/q/platform/android

Related