Skip to content

Commit cd9a6ba

Browse files
Merge pull request #27 from masani1989/gsheet-conn-fix
Fix for Gsheets connection based on streamlit changes
2 parents 6d50cc1 + 1e09c42 commit cd9a6ba

File tree

11 files changed

+132
-155
lines changed

11 files changed

+132
-155
lines changed

.github/workflows/lint_and_test.yaml renamed to .github/workflows/test.yaml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,16 @@ jobs:
1414
python-version: ["3.9", "3.10", "3.11"]
1515

1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1818
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v4
19+
uses: actions/setup-python@v5
2020
with:
2121
python-version: ${{ matrix.python-version }}
2222
cache: "pip"
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip
2626
pip install -r test-requirements.txt
27-
- name: Lint with ruff
28-
run: |
29-
# stop the build if there are Python syntax errors or undefined names
30-
ruff --select=E9,F63,F7,F82 --target-version=py39 .
31-
# default set of ruff rules with GitHub Annotations
32-
ruff --target-version=py39 .
33-
- name: Check types with mypy
34-
run: |
35-
mypy --ignore-missing-imports .
3627
- name: Test with pytest
3728
run: |
3829
pytest

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
repos:
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: "v0.5.6"
5+
hooks:
6+
- id: ruff
7+
args: [--fix]
8+
- id: ruff-format
9+
args: [--config=pyproject.toml]
10+
11+
- repo: https://github.com/pre-commit/mirrors-mypy
12+
rev: v1.11.1
13+
hooks:
14+
- id: mypy
15+
language_version: python3.8
16+
17+
- repo: https://github.com/pre-commit/pre-commit-hooks
18+
rev: v4.6.0
19+
hooks:
20+
- id: end-of-file-fixer

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Streamlit GSheetsConnection
22

3-
Connect to public or private Google Sheets from your Streamlit app. Powered by `st.experimental_connection()` and [gspread](https://github.com/burnash/gspread).
3+
Connect to public or private Google Sheets from your Streamlit app. Powered by `st.connection()` and [gspread](https://github.com/burnash/gspread).
44

55
GSheets Connection works in two modes:
66

@@ -26,7 +26,7 @@ from streamlit_gsheets import GSheetsConnection
2626

2727
url = "https://docs.google.com/spreadsheets/d/1JDy9md2VZPz4JbYtRPJLs81_3jUK47nx6GYQjgU8qNY/edit?usp=sharing"
2828

29-
conn = st.experimental_connection("gsheets", type=GSheetsConnection)
29+
conn = st.connection("gsheets", type=GSheetsConnection)
3030

3131
data = conn.read(spreadsheet=url, usecols=[0, 1])
3232
st.dataframe(data)
@@ -99,7 +99,7 @@ from streamlit_gsheets import GSheetsConnection
9999

100100
st.title("Read Google Sheet as DataFrame")
101101

102-
conn = st.experimental_connection("gsheets", type=GSheetsConnection)
102+
conn = st.connection("gsheets", type=GSheetsConnection)
103103
df = conn.read(worksheet="Example 1")
104104

105105
st.dataframe(df)

examples/Public_Sheet_Example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
from streamlit_gsheets import GSheetsConnection
1313

14-
conn = st.experimental_connection("gsheets", type=GSheetsConnection)
14+
conn = st.connection("gsheets", type=GSheetsConnection)
1515

1616
df = conn.read(spreadsheet=url, usecols=[0, 1])
1717
st.dataframe(df)
1818

1919
st.write("#### 2. Query public Google Worksheet using SQL")
2020
st.info(
2121
"Mutation SQL queries are in-memory only and do not results in the Worksheet update.",
22-
icon="ℹ️",
22+
icon="ℹ️", # noqa: RUF001
2323
)
2424
st.warning(
2525
"""You can query only one Worksheet in provided public Spreadsheet,
@@ -34,7 +34,7 @@
3434

3535
from streamlit_gsheets import GSheetsConnection
3636

37-
conn = st.experimental_connection("gsheets", type=GSheetsConnection)
37+
conn = st.connection("gsheets", type=GSheetsConnection)
3838

3939
df = conn.query('select births from "Example 2" limit 10', spreadsheet=url)
4040
st.dataframe(df)

examples/pages/Service_Account_Example.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from streamlit_gsheets import GSheetsConnection
1111

12-
conn = st.experimental_connection("gsheets", type=GSheetsConnection)
12+
conn = st.connection("gsheets", type=GSheetsConnection)
1313
st.write(conn)
1414
st.help(conn)
1515

@@ -36,7 +36,7 @@
3636
and enable it.
3737
3. [Using Service
3838
Account](https://docs.gspread.org/en/v5.7.1/oauth2.html#for-bots-using-service-account)
39-
* Enable API Access for a Project if you havent done it yet.
39+
* Enable API Access for a Project if you haven't done it yet.
4040
* Go to “APIs & Services > Credentials” and choose “Create credentials > Service
4141
account key”.
4242
* Fill out the form
@@ -58,12 +58,12 @@
5858
...
5959
}}
6060
```
61-
Remember the path to the downloaded credentials file. Also, in the next step youll need
61+
Remember the path to the downloaded credentials file. Also, in the next step you'll need
6262
the value of client_email from this file.
6363
6464
* **:red[Very important!]** Go to your
6565
spreadsheet and share it with a client_email from the step above. Just like you do with
66-
any other Google account. If you dont do this, youll get a
66+
any other Google account. If you don't do this, you'll get a
6767
`gspread.exceptions.SpreadsheetNotFound` exception when trying to access this
6868
spreadsheet from your application or a script.
6969
@@ -105,7 +105,7 @@
105105
from streamlit_gsheets import GSheetsConnection
106106

107107
# Create GSheets connection
108-
conn = st.experimental_connection("gsheets", type=GSheetsConnection)
108+
conn = st.connection("gsheets", type=GSheetsConnection)
109109

110110
# Demo Births DataFrame
111111
df = psql.load_births()
@@ -118,7 +118,7 @@
118118
data=df,
119119
)
120120
st.cache_data.clear()
121-
st.experimental_rerun()
121+
st.rerun()
122122

123123
# Display our Spreadsheet as st.dataframe
124124
st.dataframe(df.head(10))
@@ -127,7 +127,7 @@
127127
st.write("#### 4. Read Google WorkSheet as DataFrame")
128128
st.info(
129129
"If the sheet has been deleted, press 'Create new worksheet' button above.",
130-
icon="ℹ️",
130+
icon="ℹ️", # noqa: RUF001
131131
)
132132

133133
with st.echo():
@@ -136,7 +136,7 @@
136136
from streamlit_gsheets import GSheetsConnection
137137

138138
# Create GSheets connection
139-
conn = st.experimental_connection("gsheets", type=GSheetsConnection)
139+
conn = st.connection("gsheets", type=GSheetsConnection)
140140

141141
# Read Google WorkSheet as DataFrame
142142
df = conn.read(
@@ -157,7 +157,7 @@
157157
from streamlit_gsheets import GSheetsConnection
158158

159159
# Create GSheets connection
160-
conn = st.experimental_connection("gsheets", type=GSheetsConnection)
160+
conn = st.connection("gsheets", type=GSheetsConnection)
161161

162162
# Demo Meat DataFrame
163163
df = psql.load_meat()
@@ -170,15 +170,15 @@
170170
data=df,
171171
)
172172
st.cache_data.clear()
173-
st.experimental_rerun()
173+
st.rerun()
174174

175175
# Display our Spreadsheet as st.dataframe
176176
st.dataframe(df.head(10))
177177

178178
st.write("#### 6. Query Google WorkSheet with SQL and get results as DataFrame")
179179
st.info(
180180
"Mutation SQL queries are in-memory only and do not results in the Worksheet update.",
181-
icon="ℹ️",
181+
icon="ℹ️", # noqa: RUF001
182182
)
183183

184184

@@ -188,7 +188,7 @@
188188
from streamlit_gsheets import GSheetsConnection
189189

190190
# Create GSheets connection
191-
conn = st.experimental_connection("gsheets", type=GSheetsConnection)
191+
conn = st.connection("gsheets", type=GSheetsConnection)
192192

193193
# make sure worksheet name is in double quota "", in our case it's "Example 1"
194194
# DuckDB SQL dialect is supported
@@ -206,15 +206,15 @@
206206
from streamlit_gsheets import GSheetsConnection
207207

208208
# Create GSheets connection
209-
conn = st.experimental_connection("gsheets", type=GSheetsConnection)
209+
conn = st.connection("gsheets", type=GSheetsConnection)
210210

211211
# click button to update worksheet
212212
# This is behind a button to avoid exceeding Google API Quota
213213
if st.button("Clear worksheet"):
214214
conn.clear(worksheet="Example 1")
215215
st.info("Worksheet Example 1 Cleared!")
216216
st.cache_data.clear()
217-
st.experimental_rerun()
217+
st.rerun()
218218

219219
# click button to delete worksheet using the underlying gspread API
220220
# This is behind a button to avoid exceeding Google API Quota
@@ -223,4 +223,4 @@
223223
worksheet = spreadsheet.worksheet("Example 1")
224224
spreadsheet.del_worksheet(worksheet)
225225
st.cache_data.clear()
226-
st.experimental_rerun()
226+
st.rerun()

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[mypy]
2-
ignore_missing_imports = True
2+
ignore_missing_imports = True

pyproject.toml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
[tool.ruff]
2-
line-length=125
2+
exclude = [".git", ".vscode", ".pytest_cache", ".mypy_cache", ".env"]
3+
line-length = 125
4+
5+
[tool.ruff.lint]
6+
ignore = ["B008", "ISC001", "E501", "W191"]
7+
select = [
8+
"B",
9+
"E",
10+
"F",
11+
"W",
12+
"I",
13+
"N",
14+
"C4",
15+
"EXE",
16+
"ISC",
17+
"ICN",
18+
"PIE",
19+
"PT",
20+
"RET",
21+
"SIM",
22+
"ERA",
23+
"PLC",
24+
"RUF",
25+
"ARG",
26+
]

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
from pathlib import Path
2+
13
import setuptools
24

3-
VERSION = "0.0.4" # PEP-440
5+
VERSION = "0.1.0" # PEP-440
46

57
NAME = "st-gsheets-connection"
68

79
INSTALL_REQUIRES = [
8-
"streamlit>=1.22.0",
10+
"streamlit>=1.32.0",
911
"gspread>=5.8.0, <6",
1012
"gspread-pandas>=3.2.2",
1113
"gspread-dataframe>=3.3.0",
1214
"gspread-formatting>=1.1.2",
13-
"pandas>=1.3.0, <2",
1415
"duckdb>=0.8.1",
1516
"sql-metadata>=2.7.0",
1617
"validators>=0.22.0",
@@ -42,6 +43,6 @@
4243
# Requirements
4344
install_requires=INSTALL_REQUIRES,
4445
packages=["streamlit_gsheets"],
45-
long_description=open("README.md").read(),
46+
long_description=Path("README.md").read_text(),
4647
long_description_content_type="text/markdown",
4748
)

0 commit comments

Comments
 (0)