How to connect to SQLite3 database in python remotely - python

I use SQLite3 in python because my school computers don't allow us to install anything to python so I used the pre installed SQLite3 module.
I'm working on a program whose back end relies on an SQLite3 database, however the databases are created and stored on their computer.
Is it possible for me to "Host" an SQLite3 database on let's say a server and allow my script to access them remotely (my script could edit the database from my school computer)?
By the way, I'm using python 3.X
EDIT
i made a database api that runs in python 3, its called TaliffDb
to install type pip3 install TaliffDB in your terminal. im working on a documentation, but please do comment if you have any questions

Write an API on the remote server, yes. This could be hosted by a web framework of your choice.
You won't get a direct network connection to a file

Related

Is there a way to connect Python to an external sqlite3 database

I haven't been able to find any documentation regarding whether it's possible to access SQLITE3 (using Python) when the SQLITE database is hosted externally:
I have my SQLITE3 database hosted on my VPS (alongside some other stuff that doesn't really matter) - rather than having it as a local file with my Python program.
Therefore, is it possible for me to connect to the SQLITE database which is hosted on my VPS, or will the SQLITE DB have to be hosted locally for me to be able to do this?
The reason I want it to be accessible from my VPS is because I want to be able to run the program on multiple computers and them all have the same access to the database- if this isn't possible, are there any other options which would allow me to do this?
If you want to have a database server with external, possibly remote, applications interacting a client-server protocol switch to PostgreSQL, MariaDB, etc.
see: How to connect to SQLite3 database server?

Questions about PostgreSQL version 12.2 and its compatibility with other operating systems

I will develop a commercial Python software with the PostgreSQL database, I will use PostgreSQL version 12.2. My first question is, to run the application database (will it be a desktop application) will I need to install something related to the database on the user's computer?
And my other question is, will I be able to run my application with this version of the database on another operating system?
I saw that on the download page of version 12.2 the database only has an installer for Mac OS X and Win 64bits, will my application be compatible with other operating systems besides those two I mentioned?
I'm new to programming, thanks in advance for the clarification. <3
The database API driver/provider (in the case of Python probably psycopg2) will have to be installed on the machine where the code runs that directly accesses the database.
In the case of a 2-tier architecture (the application is installed on the end-user machine and directly accesses the database) that driver will be installed on the end-user machine, where the Python program runs.
In the case of a 3-tier architecture (the end-user machine talks to a web server via HTTP, and the Python program that accesses the database runs in an application server on the web server machine) the driver will be installed on the application server.
There are modern architectures that are even more complicated (keyword "microservices") which few people understand well enough to use properly, but let's ignore them here for simplicity's sake. The same principle applies: whoever talks to the database directly will need to have the database driver installed.
If you install psycopg2, you will also need to install the PostgreSQL client shared library libpq on the same machine, because psycopg2 is linked with it and uses it.

connect my raspbery-pi to MySQL

Yesterday, I installed an apche web server and phpmyadmin on my raspberry-py. How can I connect my raspberry-pi to databases in phpmyadmin with python? Can I use MySQL? Thank, I hope you understand my question and sorry for my bad english.
Your question is quite unclear. But from my understanding, here is what you should try doing: (Note: I am assuming you want to connect your Pi to a database to collect data and store in an IoT based application)
Get a server. Any Basic server would do. I recommend DigitalOcean or AWS LightSail. They have usable servers for just $5 per month. I recommend Ubuntu 16.04 for ease of use.
SSH into the server with your terminal with the IP address you got when you created the server
Install Apache, MySQL, Python, PHPMyAdmin on the server.
Write your web application in any language/framework you want.
Deploy it and write a separate program to make HTTP calls to the said web server.
MySQL is the Database server. Python is the language that is used to execute any instructions. PHPMyAdmin is the interface to view MySQL Databases and Tables. Apache is the webserver that serves the application you have written to deal with requests.
I strongly recommend understanding the basics of Client-Server model of computing over HTTP.
Alternatively, you could also use the approach of Using a DataBase-as-a-service from any popular cloud service provider(Eg., AWS RDS), to make calls directly into the DB.

PostgreSQL multi user application

I want to know that if multi-users try to access same database for insert or retrieve data via my python program, do they all need to install PostgreSQL in their computers? How this process works?
If the database is located on another server, then no, clients don't have to install postgresql. They will need to install a postgresql adapter, like psycopg, so that python can communicate with the database, and most applications choose to use some type of ORM, like sqlalchemy, on top of the database adapter to make communication with the database more object-oriented and pythonic.
If you use psycopg2, it already comes with lipq DLL, the library used to communicate with PostgreSQL through TCP.
Actually, psycopg2 is a wrapper for libpq:
http://initd.org/psycopg/docs/
Therefore, you won't need to install PostgreSQL server binaries in the client workstations.

using mysql instead of sqlite3

im working on python application that requiring database connections..I had developed my application with sqlite3 but it start showing the error(the database is locked).. so I decided to use MySQL database instead.. and it is pretty good with no error..
the only one problem is that I need to ask every user using my application to install MySQL server on his pc (appserv for example) ..
so can I make mysql to be like sqlite3 apart of python lib. so I can produce a python script can be converted into exe file by the tool pyInstaller.exe and no need to install mysql server by users???
update:
after reviewing the code I found opened connection not closed correctly and work fine with sqllite3 ..thank you every body
It depends (more "depends" in the answer).
If you need to share the data between the users of your application - you need a mysql database server somewhere setup, your application would need to have an access to it. And, the performance can really depend on the network - depends on how heavily would the application use the database. The application itself would only need to know how to "speak" with the database server - python mysql driver, like MySQLdb or pymysql.
If you don't need to share the data between users - then sqlite may be an option. Or may be not - depends on what do you want to store there, what for and what do you need to do with the data.
So, more questions than answers, probably it was more suitable for a comment. At least, think about what I've said.
Also see:
https://stackoverflow.com/questions/1009438/which-database-should-i-use-for-my-desktop-application
Python Desktop Application Database
Python Framework for Desktop Database Application
Hope that helps.
If your application is a stand-alone system such that each user maintains their own private database then you have no alternative to install MySQL on each system that is running the application. You cannot bundle MySQL into your application such that it does not require a separate installation.
There is an embedded version of MySQL that you can build into your application (thanks, Carsten, in the comments, for pointing this out). More information is here: http://mysql-python.blogspot.com/. It may take some effort to get this working (on Windows you apparently need to build it from source code) and will take some more work to get it packaged up when you generate your executable, but this might be a MySQL solution for you.
I've just finished updating a web application using SQLite which had begun reporting Database is locked errors as the usage scaled up. By rewriting the database code with care I was able to produce a system that can handle moderate to heavy usage (in the context of a 15 person company) reliably still using SQLite -- you have to be careful to keep your connections around for the minimum time necessary and always call .close() on them. If your application is really single-user you should have no problem supporting it using SQLite -- and that's doubly true if it's single-threaded.

Categories

Resources