Jay
Jay

Reputation: 2107

Python sync with mySQL for local application?

There have been many questions along these lines but I'm struggling to apply them to my scenario. Any help would be be greatly appreciated!

We currently have a functioning mySQL database hosted on a website, data is entered from a website and via PHP it is put into the database.

At the same time we want to now create a python application that works offline. It should carry out all the same functions as the web version and run totally locally, this means it needs a copy of the entire database to run locally and when changes are made to such local database they are synced next time there is an internet connection available.

First off I have no idea what the best method would be to run such a database offline. I was considering just setting up a localhost, however this needs to be distributable to many machines. Hence setting up a localhost via an installer of some sort may be impractical no?

Secondly synchronization? Not a clue on how to go about this!

Any help would be very very very appreciated.

Thank you!

Upvotes: 2

Views: 3570

Answers (3)

ctdeveloper
ctdeveloper

Reputation: 290

For binding Python to MySql you could use HTSQL:

http://htsql.org

You can then also query your MySQL DB via http requests, either from AJAX calls or server-side e.g. cURL (and of course still have the option of writing standard SQL queries).

There is a JQuery plugin called HTRAF that handles the client side AJAX calls to the HTSQL server.

The HTSQL server runs on localhost as well.

What OS would you be using?

Upvotes: 1

user895378
user895378

Reputation:

How high-performance does your local application need to be? Also, how reliable is the locally available internet connection? If you don't need extremely high performance, why not just leave the data in the remote MySQL server?

If you're sure you need access to local data I'd look at MySQL's built-in replication for synchronization. It's really simple to setup/use and you could use it to maintain a local read-only copy of the remote database for quick data access. You'd simply build into your application the ability to perform write queries on the remote server and do read queries against the local DB. The lag time between the two servers is generally very low ... like on the order of milliseconds ... but you do still have to contend with network congestion preventing a local slave database from being perfectly in-sync with the master instantaneously.

As for the python side of things, google mysql-python because you'll need a python mysql binding to work with a MySQL database. Finally, I'd highly recommend SQLalchemy as an ORM with python because it'll make your life a heck of a lot easier.

I would say an ideal solution, however, would be to set up a remote REST API web service and use that in place of directly accessing the database. Of course, you may not have the in-house capabilities, the time or the inclination to do that ... which is also okay :)

Upvotes: 0

canadadry
canadadry

Reputation: 8443

Are you planning to run mysql on your local python offline apps ? I would suggest something like sqlite. As for keeping things in sync, it also depends on the type of data that needs to be synchronized. One question that needs to be answered:

Are the data generated by these python apps something that is opague ? If yes (i.e. it doesn't have any relations to other entities), then you can queue the data locally and push it up to the centrally hosted website.

Upvotes: 0

Related Questions