Export SQLite query results directly into Google Sheets using drt.
This will write the users table to your Google Sheet:
| id | name | department | |
|---|---|---|---|
| 1 | Alice | alice@example.com | Engineering |
| 2 | Bob | bob@example.com | Sales |
| 3 | Carol | carol@example.com | Marketing |
- Python 3.10+
- A Google Cloud service account with Sheets API enabled
- A Google Sheets spreadsheet shared with the service account email
- Create a service account in Google Cloud
- Enable the Google Sheets API
- Download the JSON key file
- Share your target Google Sheet with the service account email (Editor access)
pip install drt-core[sheets]python -c "
import sqlite3
conn = sqlite3.connect('database.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER,
name TEXT,
email TEXT,
department TEXT
)
''')
cursor.executemany('INSERT INTO users VALUES (?, ?, ?, ?)', [
(1, 'Alice', 'alice@example.com', 'Engineering'),
(2, 'Bob', 'bob@example.com', 'Sales'),
(3, 'Carol', 'carol@example.com', 'Marketing')
])
conn.commit()
conn.close()
"mkdir -p ~/.drt
cat > ~/.drt/profiles.yml << 'EOF'
local:
type: sqlite
database: ./database.db
EOFdatabase: ./database.dbis relative to where you rundrt- Use an absolute path if running from a different directory
drt run --dry-run # preview
drt run # write to Google Sheets
drt status # check resultmode: overwriteclears the sheet before writing (header + data)mode: appendadds rows without clearing