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

Asked

Viewed 850 times

4

Good afternoon to you all! I am a student of Computer Science, but I haven’t had the opportunity to have a deeper experience with programming, involving the necessary integrations in applications and systems, and I would love to have a notion on top of what I will need.

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

My question is: how do I access my application in Python (or make the calls), return them and the like? For the integration Python<->DB already analyzed some possibilities and I will probably use the lib pymysql, but I could not find something like this for the side of Android<->Python (for example, the user got 3 questions right, I send this whole to my Python application and in it are called the respective functions for the calculations).

I read a little about "web services", is it necessary something like this for what I wish? Any recommendation of materials or sites 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 wish to explore the parties jointly and individually.

I request, if possible, some specific example of this procedure, something like "Android - tool X - server - tool Y - database", ie, the way it all connects, quoting tools, so that from this example I can look for similar tools and find the one that best suits me. I believe that a graphic example would clarify my doubts.

1 answer

1


Yes - As you may have already understood, your Python application will be on a cloud server. Several frameworks for android allow you to make an application that will fetch results in the cloud through web-services. Frameworks for creating "Html5" applications like Ionic and Electron, allow direct use of web-services, as well as the combination of technologies like Angular or React that allow other ways to write 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) - in it is configured a route for your Python application, which by the way of rule must respond using the "WSGI" standard. On the other hand, you write your Python application responding WSGI, and don’t have to worry about production settings during development.

Perhaps one of the simplest ways to create a set of Python webservices is to use the Flask framework - although any of the most popular web framworks will do (Django, Bottle, Web2py, Pyramid): these frameworks will contain a number of utilities and services so that you don’t have to re-invent the wheel for zillions of things - like maintaining independence between requests, maintaining a pool of connections with the database,obtain and validate form data or HTTP requests, prevent cross-site-scripting (XSS) attacks, and this list could grow considerably.

Here is a blog post that gives the path of the stones to do with Flask: https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask

(as you can see, writing an example running here, including the configuration instructions for development would be the equivalent of a book chapter).

My last recommendation is nay try to use SQL directly - you will have much more flexibility and ease to create new templates in your application if you use a ORM -"Object Relational Mapper". The most commonly used for Python is Sqlalchemy - and it is easy to find same integration instructions with all python frameworks. Unless you choose to use Django as a framework, in this case it uses its own ORM which is very practical too.

  • Actually I didn’t understand no hahahaha The way I saw it was to use a computer in my home as a server, not in the cloud. I really have no idea of either, and I don’t know what the simplest alternative is. That being said, what is the best alternative (in terms of ease) of server? Host my server-side on a cloud service or use my own computer?

  • use your switch to develop, and put in the cloud for when it’s for your friends/end users to use. There are some free options for low usage - look for "pythonanywhere" and "Heroku", for example.

  • Got it! In my case, it’s a college project, so I don’t have any plans to make it available to anyone, so I could just use the computer for now, right? I believe I have already had contact with the "Heroku", I will give a studied, thank you!

  • One cool thing, and if you succeed is a "case" for online is to create an Android Html5 application with Electron or other, using "Brython"; Brython is a Python implementation made whole in Javascript, to run right in the Browser. Technically it’s a javascript project that lets you program direct front-end in Python. But no one has yet documented the steps to create a Python app using it directly. (hence in this case, there is the "Internal)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.