How to access a SQLite database in google drive with python?

Viewed 732

The goal is to manipulate a SQLite database stored in google drive using jupyter notebook. I found a way to access the SQLite database in google drive using Google colaboratory, but I don't know how to do it in jupyter notebook.

With the following code, I was able to access google drive, but I cannot connect to the SQLite database.

How can I modify the code in the part "conn = sqlite3.connect(drive_path + db_name)"?

I would appreciate it if you could let me know.

#####################

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.

drive = GoogleDrive(gauth)



import sqlite3

drive_path = "/My Drive/database/"
db_name = "test.db"

conn = sqlite3.connect(drive_path + db_name)

cur = conn.cursor()
1 Answers

Do not know if my solution works for you. As you may have already known, since Sqlite is file-based only, the database file must be in a network shared folder. On my Mac, I mounted my Google drive as a folder in my local drive, and then access my google drive database file as a regular local file:

conn = sqlite3.connect('/Users/local/Google Drive (xxxx@gmail.com)/sample.db')
Related