4

I have a question about sqlite3. If I were to host a database online, how would I access it through python's sqlite3 module?

E.g. Assume I had a database hosted at "www.example.com/database.db". Would it be as simple as just forming a connection with sqlite3.connect ("www.example.com/database.db") or is there more I need to add so that the string is interpreted as a url and not a filename?

0

2 Answers 2

3

SQLite3 is embedded-only database so it does not have network connection capabilities. You will need to somehow mount the remote filesystem.

With that being said, SQLite3 is not meant for this. Use PostgreSQL or MySQL (or anything else) for such purposes.

Sign up to request clarification or add additional context in comments.

Comments

0

You can download the database and then read it but you can't connect to a SQLite Database. First create the downloader:

def download_file(path):
r = requests.get(path)
filename = path.split("/")[-1]
fullname = str(os.getcwd())+"/"+filename
 
with open(fullname, 'wb') as f:
    f.write(r.content)
    print ("DB downloaded")

Then download the database:

download_file("www.example.com/database.db")

and finally open, read, etc...
https://www.tutorialspoint.com/sqlite/sqlite_python.htm

to delete the database: (first import os module)

os.system("rm /path/to/database.db")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.