A Python library for using Google Sheets as a database because I felt a need to make it.
Project description
GSheetsDB
A Python library for using Google Sheets as a database. This library provides a simple interface to perform database-like operations on Google Sheets.
Features
- Simple CRUD operations (Create, Read, Update, Delete)
- Easy to use API
- Type hints for better IDE support
- Comprehensive error handling
- Flexible querying options
Installation
pip install py-gsheets-db
Prerequisites
Before using the library, you need to:
-
Set up Google Sheets API:
- Go to Google Cloud Console
- Create a new project
- Enable Google Sheets API
- Create service account credentials
- Download the credentials JSON file
-
Create a Google Sheet and get its ID (from the URL)
-
Share your Google Sheet with the service account email (found in your credentials JSON)
Usage
from py_gsheets_db import GSheetsDB
# Initialize the database
db = GSheetsDB(
credentials_path='path/to/credentials.json',
spreadsheet_id='your-spreadsheet-id'
)
# Create a new table
db.create_table('users', ['id', 'name', 'email'])
# Insert data
db.insert('users', {
'id': '1',
'name': 'John Doe',
'email': 'john@example.com'
})
# Select data
all_users = db.select('users')
specific_columns = db.select('users', columns=['name', 'email'])
# Update data
db.update(
'users',
where={'id': '1'},
values={'name': 'John Smith'}
)
# Delete data
db.delete('users', where={'id': '1'})
API Reference
GSheetsDB
__init__(credentials_path: str, spreadsheet_id: str)
Initialize the Google Sheets database connection.
create_table(table_name: str, columns: List[str]) -> bool
Create a new worksheet (table) in the spreadsheet.
insert(table_name: str, data: Dict[str, Any]) -> bool
Insert a new row into the specified table.
select(table_name: str, columns: Optional[List[str]] = None) -> List[Dict[str, Any]]
Select data from the specified table.
update(table_name: str, where: Dict[str, Any], values: Dict[str, Any]) -> bool
Update rows in the specified table that match the where condition.
delete(table_name: str, where: Dict[str, Any]) -> bool
Delete rows from the specified table that match the where condition.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_gsheets_db-0.1.0.tar.gz.
File metadata
- Download URL: py_gsheets_db-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12d99c899c0fb80c26f5f8a7ff1c1804f6bfbd37b74e952976cda0d548e082b6
|
|
| MD5 |
1631e0264c1bc57fd6ac0f9a4a1c1faa
|
|
| BLAKE2b-256 |
b347767c86df96255fdbe27b99478f0ceffc67f627659cbaf4cee21cc43d0d69
|
File details
Details for the file py_gsheets_db-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_gsheets_db-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccca298e00c1189a49235156ea5b0fca938cf83cc2ce9c913d975ae8cb431413
|
|
| MD5 |
41fbe85b1ab0614e23b4ea941d276425
|
|
| BLAKE2b-256 |
a86bda39787297301da880ee8ce7629d8648cb9c0fedcd350cd406478e4d3768
|