A Python library for Google Sheets with high-level API, automatic type inference, and efficient caching.
Project description
SmartSpread
A Python library for Google Sheets that extends gspread with a high-level API, automatic type inference, and efficient caching.
Features
- Simple API: Intuitive interface for spreadsheet and tab operations
- Multiple Data Formats: Work with DataFrames, list of dicts, or list of lists
- Automatic Type Inference: Smart conversion of numeric, string, and None values
- Efficient Caching: Minimizes API calls to stay within rate limits
- Pandas Integration: Seamless DataFrame read/write operations
- Row Operations: Update or insert rows based on column patterns
Installation
pip install smartspread
Quick Start
Authentication
- Create a Google Cloud Project
- Enable the Google Sheets API
- Create a service account and download credentials JSON
- Share your spreadsheet with the service account email
Basic Usage
from smartspread import SmartSpread
# Initialize with credentials
spread = SmartSpread(
sheet_identifier="your-spreadsheet-id-or-name",
key_file="path/to/credentials.json"
)
# Get or create a tab
tab = spread.tab("MyTab")
# Read data as DataFrame
df = tab.read_data()
# Modify data
tab.data["new_column"] = "value"
# Write back to Google Sheets
tab.write_data(overwrite_tab=True)
Update Rows by Pattern
# Update existing row or insert new one
tab.update_row_by_column_pattern(
column="ID",
value=123,
updates={"Status": "completed", "Updated": "2024-01-01"}
)
tab.write_data(overwrite_tab=True)
Filter Data
# Filter rows by pattern
filtered = tab.filter_rows_by_column("Name", "Alice")
print(filtered)
Work with Different Formats
# DataFrame format (default)
tab_df = spread.tab("Sheet1", data_format="DataFrame")
df = tab_df.data # pandas DataFrame
# List of dicts format
tab_dict = spread.tab("Sheet2", data_format="dict")
data = tab_dict.data # [{"col1": "val1", ...}, ...]
# List of lists format
tab_list = spread.tab("Sheet3", data_format="list")
data = tab_list.data # [["header1", "header2"], ["val1", "val2"], ...]
Refresh Data
# Reload data after external changes
tab.refresh()
# Refresh spreadsheet metadata
spread.refresh()
API Reference
SmartSpread
SmartSpread(sheet_identifier, key_file=None, service_account_data=None, user_email=None)spread.tab(tab_name, data_format="DataFrame", keep_number_formatting=False)- Get or create tabspread.tab_names- List all tab namesspread.tab_exists(tab_name)- Check if tab existsspread.url- Get spreadsheet URLspread.grant_access(email, role="owner")- Grant access to userspread.refresh()- Clear cache and reload metadata
SmartTab
tab.read_data()- Read data from Google Sheetstab.write_data(overwrite_tab=False, as_table=False)- Write data to Google Sheetstab.update_row_by_column_pattern(column, value, updates)- Update or insert rowtab.filter_rows_by_column(column, pattern)- Filter rows by patterntab.refresh()- Reload data from Google Sheetstab.data- Access the data (DataFrame, list of dicts, or list of lists)
Notes
- Google Sheets API has rate limits (60 requests/minute for free tier)
- SmartSpread uses caching to minimize API calls
- Empty cells are represented as
Nonein DataFrames - Integer columns use nullable
Int64dtype to preserveNonevalues
Changelog
v1.1.2 (2024)
- Changed: Package renamed to
smartspread(no underscore) for cleaner imports - Added: Backwards compatibility for
from smart_spread import ...with deprecation warning
v1.1.1 (2024)
- Fixed: JSON serialization error when using
data_format="list"with nullable Int64 columns containingpd.NAvalues
License
MIT License - see LICENSE file for details.
Links
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
smartspread-1.1.2.tar.gz
(12.7 kB
view details)
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 smartspread-1.1.2.tar.gz.
File metadata
- Download URL: smartspread-1.1.2.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
494771d4cf51b361e35f8afb3f88dac2c52943614544eb97d95e160c343641b6
|
|
| MD5 |
be654ab669635012452abe154588fc0d
|
|
| BLAKE2b-256 |
7f029274911b930c57473dc17275af27d71dfe34afd2da98c1fdcfaa1b271118
|
File details
Details for the file smartspread-1.1.2-py3-none-any.whl.
File metadata
- Download URL: smartspread-1.1.2-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc8710a9ac8b5e51976385868db2217f32f3ef5253fe6b22c7bbb5d9ee4159b9
|
|
| MD5 |
fcf8fb8646c6d549fe1d35a346fb483f
|
|
| BLAKE2b-256 |
3ceb39f2b6291fad494ab932f12a8f520dd2bf84c4d3dc4f97066bbc5502ddc1
|