How to integrate an Android application with a server in Python + DB?

4

Good afternoon everyone! I am a Computer Science student, but I have not yet had the opportunity to have a deeper experience with programming, involving the necessary integrations in applications and systems, and I would love to get a sense of what I'm going to need.

In summary, I have a project in which I intend to develop an Android application, which will act almost as a front, sending the data to my Python server, which will store them in the respective database, perform Machine Learning algorithms on that data, and will return it to my application, bringing it to the front (displaying on screen). Basically it will be an application of questions and answers like quizzes.

My question is: how will I, through my application, access my Python application (or make the calls), return them, and the like? For Python integration < - > DB I have already looked at some possibilities and will probably use lib pymysql, however I could not find something like that for the < - > Python side (eg the user hit 3 questions, I submit this integer for my Python application and the respective functions for the calculations are called in it.)

I read a bit about "web services", do I need something like that for what I want? Any recommendation of materials or websites where I can study this further is very welcome!

Thank you in advance.

Edit 1: Initially, I would just like to create a basic connection, with the good old login screen, that is, I want to create an authentication performed by my server-side (Python + DB). From this, I want to explore the parts together and individually.

I ask, if possible, any specific example of this procedure, something like "Android - X tool - server - tool Y - database", that is, the way it all connects, citing tools, so that from From this example I can look for similar tools and find the one that best suit me. I think a graphic example would elucidate my doubts a lot.

    
asked by anonymous 28.01.2018 / 20:07

1 answer

0

Yes - as you may have already understood, your Python application will stay on a server in the cloud. Several android frameworks allow you to make an application that will fetch results in the cloud through web-services. Frameworks for creating "html5" applications such as Ionic and Electron allow the direct use of web-services, as well as the combination of technologies such as Angular or React that allow other ways of writing the application.

On the Python side, what you will get is a server (it can be a Virtual Private Server, or a hosting service like Heroku or redhatOpenShift) - it is configured a route for your Python application, which rule must respond using the "WSGI" pattern. On the other hand, you write your Python application responding to WSGI, and you do not have to worry about production settings during development.

Perhaps one of the simplest ways to create a set of webservices in Python is by using the Flask framework - although any of the more popular framworks webs will serve (Django, Bottle, Web2py, Pyramid): these frameworks will contain a series of utilities and services so you do not have to re-invent the wheel for zillions of things - how to maintain independence between requests, maintain a pool of database connections, obtain and validate forms data or HTTP requests, avoid attacks of cross-site-scripting, (XSS), and this list could grow a lot.

Here is a blog post that gives the way of stones to do with Flask: link

(As you can see, writing an example working here, including the setup instructions for development would be the equivalent of a book chapter.)

The last recommendation I give is not to try to use SQL directly - you will have much more flexibility and ease to create new templates in your application if you use an Object Relational Mapper. The most commonly used for Python is SQLAlchemy - and it is easy to find integration instructions for it with all python frameworks. Unless you choose to use Django as a framework, in that case it uses an ORM of its own that is very practical as well.

    
29.01.2018 / 16:44