Skip to content

Commit e65e20a

Browse files
author
Richard O'Dwyer
committed
Docs
1 parent 246a0bf commit e65e20a

File tree

3 files changed

+108
-8
lines changed

3 files changed

+108
-8
lines changed

Diff for: README.md

+101-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,102 @@
11
# sheet2api-python
2-
Google/Excel Sheets API Python
2+
3+
Google/Excel Sheets API Python Client. For use with https://sheet.com/
4+
5+
## Installation
6+
7+
```bash
8+
pip install sheet2api
9+
```
10+
11+
## Usage Examples
12+
13+
Before we can do anything we need to create an instance of the API client.
14+
15+
```python
16+
from sheet2api import SheetAPIClient
17+
18+
client = SheetAPIClient(api_url='https://sheet2api.com/v1/FgI6zV8qT222/my-api/')
19+
# If your API has authentication enabled
20+
client = SheetAPIClient(
21+
api_url='https://sheet2api.com/v1/FgI6zV8qT222/my-api/',
22+
username='api_username_here', password='api_password_here'
23+
)
24+
```
25+
26+
### Get all rows
27+
28+
Returns all rows within the **first** Sheet of your Spreadsheet.
29+
30+
```python
31+
client.get_rows()
32+
33+
# Returns a list of dicts
34+
[{
35+
'name': 'Bob',
36+
'age': 22
37+
}, {
38+
'name': 'Richard',
39+
'age': 19
40+
}, {
41+
'name': 'Bob Jones',
42+
'age': 99
43+
}]
44+
```
45+
46+
To return rows from a specific Sheet.
47+
48+
49+
```python
50+
client.get_rows(sheet='Sheet1')
51+
```
52+
53+
### Get all rows matching a query
54+
55+
Returns all rows matching a query.
56+
57+
```python
58+
client.get_rows(query={'name': 'Bob'})
59+
```
60+
61+
62+
### Create a new row
63+
64+
```python
65+
client.create_row(sheet='Sheet1', row={'name': 'Jane','age': 18,})
66+
```
67+
68+
### Update all rows which match a query
69+
70+
This will update the entire row for the matches, if you fail to specificy all column values in the replacement `row`, those cells will be filled with an empty value.
71+
72+
```python
73+
client.update_rows(
74+
sheet='Sheet1,
75+
query={'name': 'Philip'},
76+
row={
77+
'name': 'Phil',
78+
'age': 99999
79+
},
80+
)
81+
```
82+
83+
Partially update rows matching a query.
84+
85+
This will only update the columns which you provide replacement values for in the `row` dict parameter. All other columns will be left unchanged.
86+
87+
```python
88+
client.update_rows(
89+
sheet='Sheet1,
90+
query={'name': 'Philip'},
91+
row={
92+
'age': 99999
93+
},
94+
)
95+
```
96+
97+
98+
### Delete all rows matching a query
99+
100+
```python
101+
client.delete_rows(sheet='Sheet1', query={'name': 'Satan'})
102+
```

Diff for: sheet2api/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, *, api_url, username=None, password=None):
1313
if username:
1414
self._auth = HTTPBasicAuth(username, password)
1515

16-
def read_rows(self, *, sheet=None, query=None):
16+
def get_rows(self, *, sheet=None, query=None):
1717
url = self._url(sheet=sheet)
1818
logger.info('Reading rows from sheet %s within %s...', sheet, url)
1919
resp = self._request('get', url, params=query)

Diff for: tests/tests.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TestReadRows:
3030
def test_returns_all_rows_in_spreadsheet(self, client_fixture, request):
3131
client = request.getfixturevalue(client_fixture)
3232

33-
rows = client.read_rows()
33+
rows = client.get_rows()
3434

3535
assert rows == [{
3636
'name': 'Bob',
@@ -44,7 +44,7 @@ def test_returns_all_rows_in_spreadsheet(self, client_fixture, request):
4444
}]
4545

4646
def test_returns_all_rows_for_a_specific_sheet(self, client):
47-
rows = client.read_rows(sheet='Address')
47+
rows = client.get_rows(sheet='Address')
4848

4949
assert rows == [{
5050
'name': 'Bob',
@@ -55,7 +55,7 @@ def test_returns_all_rows_for_a_specific_sheet(self, client):
5555
}]
5656

5757
def test_returns_filtered_rows_when_query_is_passed(self, client):
58-
rows = client.read_rows(query={'name': 'Bob'})
58+
rows = client.get_rows(query={'name': 'Bob'})
5959

6060
assert rows == [{'name': 'Bob', 'age': 22}]
6161

@@ -77,7 +77,7 @@ def fin():
7777
added_row = client.create_row(sheet=sheet, row=row)
7878

7979
assert added_row == row
80-
assert client.read_rows(sheet=sheet) == [row] + [{
80+
assert client.get_rows(sheet=sheet) == [row] + [{
8181
'name': 'Bob',
8282
'age': 22
8383
}, {
@@ -114,7 +114,7 @@ def fin():
114114
)
115115

116116
assert updates_made == [{'name': name, 'age': 99999}]
117-
assert client.read_rows(sheet=sheet) == [{
117+
assert client.get_rows(sheet=sheet) == [{
118118
'name': name,
119119
'age': 99999
120120
}, {
@@ -152,7 +152,7 @@ def fin():
152152
)
153153

154154
assert updates_made == [{'name': name}]
155-
assert client.read_rows(sheet=sheet) == [{
155+
assert client.get_rows(sheet=sheet) == [{
156156
'name': name,
157157
'age': 18
158158
}, {

0 commit comments

Comments
 (0)