python-google-sheets 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. python_google_sheets-0.1.2/PKG-INFO +53 -0
  2. python_google_sheets-0.1.2/README.md +37 -0
  3. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/google_sheets.py +20 -7
  4. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/pyproject.toml +2 -2
  5. python_google_sheets-0.1.2/python_google_sheets.egg-info/PKG-INFO +53 -0
  6. python_google_sheets-0.1.0/PKG-INFO +0 -20
  7. python_google_sheets-0.1.0/README.md +0 -4
  8. python_google_sheets-0.1.0/python_google_sheets.egg-info/PKG-INFO +0 -20
  9. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/LICENSE +0 -0
  10. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/__init__.py +0 -0
  11. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/api_request.py +0 -0
  12. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/spreadsheet_requests/__init__.py +0 -0
  13. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/spreadsheet_requests/conditional_format_rule.py +0 -0
  14. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/spreadsheet_requests/dimension.py +0 -0
  15. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/spreadsheet_requests/general_models.py +0 -0
  16. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/spreadsheet_requests/merge_cells.py +0 -0
  17. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/spreadsheet_requests/spreadsheet.py +0 -0
  18. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/spreadsheet_requests/update_cells.py +0 -0
  19. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/spreadsheet_requests/update_sheet_properties.py +0 -0
  20. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/styles.py +0 -0
  21. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/google_sheets/utils.py +0 -0
  22. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/python_google_sheets.egg-info/SOURCES.txt +0 -0
  23. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/python_google_sheets.egg-info/dependency_links.txt +0 -0
  24. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/python_google_sheets.egg-info/requires.txt +0 -0
  25. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/python_google_sheets.egg-info/top_level.txt +0 -0
  26. {python_google_sheets-0.1.0 → python_google_sheets-0.1.2}/setup.cfg +0 -0
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-google-sheets
3
+ Version: 0.1.2
4
+ Summary: The most efficient Python wrapper for Google Sheets API
5
+ Author-email: Timofey Egorov <timegorr@gmail.com>
6
+ License-Expression: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: google-auth
13
+ Requires-Dist: google-api-python-client
14
+ Requires-Dist: pydantic>=2.0.0
15
+ Dynamic: license-file
16
+
17
+ # Google Sheets API Python wrapper
18
+
19
+ Built for developers who want to interact with Google Sheets API in a little more simple way while maintaining peak efficiency.
20
+
21
+ ### Installation
22
+ ```bash
23
+ pip install python-google-sheets
24
+ ```
25
+
26
+ ### Usage
27
+ ```python
28
+ from google_sheets import GoogleSheets, ApiRequest, CellFormat, TextFormat, TextRotation, Color_
29
+
30
+ SPREADSHEET_ID = 'your_spreadsheet_id'
31
+ SHEET_ID = 0
32
+ service = GoogleSheets.build_service(path_to_creds='your_service_account_creds.json') # 'service_account.json' is used by default
33
+
34
+ # Update data
35
+ api_requests = [
36
+ ApiRequest.update_cells(SHEET_ID, range_='A1:B2', values=[['Bold', 'Italic'], ['Underlined', 'Rotated']]),
37
+ ApiRequest.update_cells(SHEET_ID, range_='A1:B2', cell_formats=[
38
+ [CellFormat(text_format=TextFormat(bold=True)), CellFormat(text_format=TextFormat(italic=True))],
39
+ [CellFormat(text_format=TextFormat(underline=True)), CellFormat(text_rotation=TextRotation(angle=10))],
40
+ ]),
41
+ ApiRequest.update_cells(SHEET_ID, range_='A4:C4', values=['Row', 'of', 'data']),
42
+ ApiRequest.update_cells(SHEET_ID, range_='B6:B8', values=['Column', 'of', 'data']),
43
+ ApiRequest.update_cells(SHEET_ID, range_='A10:C10', values=['This', 'text', 'is colored'], cell_formats=[
44
+ CellFormat(background_color_style=Color_.Basic.YELLOW),
45
+ CellFormat(background_color_style=Color_.Basic.DARK_ORANGE_2),
46
+ CellFormat(background_color_style=Color_.Basic.PLACE_2_10),
47
+ ])
48
+ ]
49
+ GoogleSheets.update_spreadsheet(SPREADSHEET_ID, api_requests=api_requests, service=service)
50
+
51
+ # Obtain data
52
+ values = GoogleSheets.get_spreadsheet_range_values(SPREADSHEET_ID, sheet=SHEET_ID, ranges=['A1:C10'])
53
+ ```
@@ -0,0 +1,37 @@
1
+ # Google Sheets API Python wrapper
2
+
3
+ Built for developers who want to interact with Google Sheets API in a little more simple way while maintaining peak efficiency.
4
+
5
+ ### Installation
6
+ ```bash
7
+ pip install python-google-sheets
8
+ ```
9
+
10
+ ### Usage
11
+ ```python
12
+ from google_sheets import GoogleSheets, ApiRequest, CellFormat, TextFormat, TextRotation, Color_
13
+
14
+ SPREADSHEET_ID = 'your_spreadsheet_id'
15
+ SHEET_ID = 0
16
+ service = GoogleSheets.build_service(path_to_creds='your_service_account_creds.json') # 'service_account.json' is used by default
17
+
18
+ # Update data
19
+ api_requests = [
20
+ ApiRequest.update_cells(SHEET_ID, range_='A1:B2', values=[['Bold', 'Italic'], ['Underlined', 'Rotated']]),
21
+ ApiRequest.update_cells(SHEET_ID, range_='A1:B2', cell_formats=[
22
+ [CellFormat(text_format=TextFormat(bold=True)), CellFormat(text_format=TextFormat(italic=True))],
23
+ [CellFormat(text_format=TextFormat(underline=True)), CellFormat(text_rotation=TextRotation(angle=10))],
24
+ ]),
25
+ ApiRequest.update_cells(SHEET_ID, range_='A4:C4', values=['Row', 'of', 'data']),
26
+ ApiRequest.update_cells(SHEET_ID, range_='B6:B8', values=['Column', 'of', 'data']),
27
+ ApiRequest.update_cells(SHEET_ID, range_='A10:C10', values=['This', 'text', 'is colored'], cell_formats=[
28
+ CellFormat(background_color_style=Color_.Basic.YELLOW),
29
+ CellFormat(background_color_style=Color_.Basic.DARK_ORANGE_2),
30
+ CellFormat(background_color_style=Color_.Basic.PLACE_2_10),
31
+ ])
32
+ ]
33
+ GoogleSheets.update_spreadsheet(SPREADSHEET_ID, api_requests=api_requests, service=service)
34
+
35
+ # Obtain data
36
+ values = GoogleSheets.get_spreadsheet_range_values(SPREADSHEET_ID, sheet=SHEET_ID, ranges=['A1:C10'])
37
+ ```
@@ -1,20 +1,17 @@
1
- from typing import TYPE_CHECKING
2
-
3
1
  from google.oauth2.service_account import Credentials
4
2
  from googleapiclient.discovery import build
5
3
  from googleapiclient.errors import HttpError
6
4
 
7
5
  from .spreadsheet_requests import Spreadsheet, SheetProperties
8
6
 
9
- if TYPE_CHECKING:
10
- from googleapiclient.discovery import Resource # noqa
7
+ SimpleType = str | int | float | bool
11
8
 
12
9
  DEFAULT_PATH_TO_CREDS = 'service_account.json'
13
10
 
14
11
 
15
12
  class GoogleSheets:
16
13
  @staticmethod
17
- def build_service(path_to_creds: str = DEFAULT_PATH_TO_CREDS) -> 'Resource':
14
+ def build_service(path_to_creds: str = DEFAULT_PATH_TO_CREDS):
18
15
  SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
19
16
  try:
20
17
  credentials = Credentials.from_service_account_file(path_to_creds, scopes=SCOPES)
@@ -125,7 +122,7 @@ class GoogleSheets:
125
122
  return Spreadsheet.model_validate(service.spreadsheets().get(spreadsheetId=spreadsheet_id).execute(num_retries=5))
126
123
 
127
124
  @staticmethod
128
- def get_spreadsheet_range_values(spreadsheet_id: str, ranges: list[str], service=None) -> list[list[str] | list[list[str]]]:
125
+ def get_spreadsheet_range_values(spreadsheet_id: str, sheet: str | int, ranges: list[str], service=None) -> list[list[SimpleType] | list[list[SimpleType]]]:
129
126
  """
130
127
  Reads values from the specified ranges of the table.
131
128
  IMPORTANT: If the last cells in the range are empty, they will be omitted. If all cells are empty, an empty
@@ -134,6 +131,7 @@ class GoogleSheets:
134
131
 
135
132
  Args:
136
133
  spreadsheet_id (str): ID of the table
134
+ sheet (str | int): Name or ID of the sheet
137
135
  ranges (list[str]): List of ranges to read in A1 notation
138
136
  service (googleapiclient.discovery.Resource): Google Sheets service object
139
137
 
@@ -143,8 +141,23 @@ class GoogleSheets:
143
141
  if service is None:
144
142
  service = GoogleSheets.build_service()
145
143
 
144
+ if isinstance(sheet, int):
145
+ ss = GoogleSheets.get_spreadsheet(spreadsheet_id, service)
146
+ try:
147
+ sheet_name = next(sht.properties.title for sht in ss.sheets if sht.properties.sheet_id == sheet)
148
+ except StopIteration:
149
+ return []
150
+ else:
151
+ sheet_name = sheet
152
+ ranges = [f'{sheet_name}!{range_}' for range_ in ranges]
153
+
146
154
  try:
147
- response = service.spreadsheets().values().batchGet(spreadsheetId=spreadsheet_id, ranges=ranges).execute(num_retries=5)
155
+ response = service.spreadsheets().values().batchGet(
156
+ spreadsheetId=spreadsheet_id,
157
+ ranges=ranges,
158
+ valueRenderOption='UNFORMATTED_VALUE',
159
+ dateTimeRenderOption='FORMATTED_STRING'
160
+ ).execute(num_retries=5)
148
161
  except HttpError as e:
149
162
  raise e
150
163
  else:
@@ -4,9 +4,9 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python-google-sheets"
7
- description = "The most efficient Google Sheets API wrapper in Python"
7
+ description = "The most efficient Python wrapper for Google Sheets API"
8
8
  authors = [{ name = "Timofey Egorov", email = "timegorr@gmail.com" }]
9
- version = "0.1.0"
9
+ version = "0.1.2"
10
10
  readme = "README.md"
11
11
  requires-python = ">=3.11"
12
12
  classifiers = [
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-google-sheets
3
+ Version: 0.1.2
4
+ Summary: The most efficient Python wrapper for Google Sheets API
5
+ Author-email: Timofey Egorov <timegorr@gmail.com>
6
+ License-Expression: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: google-auth
13
+ Requires-Dist: google-api-python-client
14
+ Requires-Dist: pydantic>=2.0.0
15
+ Dynamic: license-file
16
+
17
+ # Google Sheets API Python wrapper
18
+
19
+ Built for developers who want to interact with Google Sheets API in a little more simple way while maintaining peak efficiency.
20
+
21
+ ### Installation
22
+ ```bash
23
+ pip install python-google-sheets
24
+ ```
25
+
26
+ ### Usage
27
+ ```python
28
+ from google_sheets import GoogleSheets, ApiRequest, CellFormat, TextFormat, TextRotation, Color_
29
+
30
+ SPREADSHEET_ID = 'your_spreadsheet_id'
31
+ SHEET_ID = 0
32
+ service = GoogleSheets.build_service(path_to_creds='your_service_account_creds.json') # 'service_account.json' is used by default
33
+
34
+ # Update data
35
+ api_requests = [
36
+ ApiRequest.update_cells(SHEET_ID, range_='A1:B2', values=[['Bold', 'Italic'], ['Underlined', 'Rotated']]),
37
+ ApiRequest.update_cells(SHEET_ID, range_='A1:B2', cell_formats=[
38
+ [CellFormat(text_format=TextFormat(bold=True)), CellFormat(text_format=TextFormat(italic=True))],
39
+ [CellFormat(text_format=TextFormat(underline=True)), CellFormat(text_rotation=TextRotation(angle=10))],
40
+ ]),
41
+ ApiRequest.update_cells(SHEET_ID, range_='A4:C4', values=['Row', 'of', 'data']),
42
+ ApiRequest.update_cells(SHEET_ID, range_='B6:B8', values=['Column', 'of', 'data']),
43
+ ApiRequest.update_cells(SHEET_ID, range_='A10:C10', values=['This', 'text', 'is colored'], cell_formats=[
44
+ CellFormat(background_color_style=Color_.Basic.YELLOW),
45
+ CellFormat(background_color_style=Color_.Basic.DARK_ORANGE_2),
46
+ CellFormat(background_color_style=Color_.Basic.PLACE_2_10),
47
+ ])
48
+ ]
49
+ GoogleSheets.update_spreadsheet(SPREADSHEET_ID, api_requests=api_requests, service=service)
50
+
51
+ # Obtain data
52
+ values = GoogleSheets.get_spreadsheet_range_values(SPREADSHEET_ID, sheet=SHEET_ID, ranges=['A1:C10'])
53
+ ```
@@ -1,20 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: python-google-sheets
3
- Version: 0.1.0
4
- Summary: The most efficient Google Sheets API wrapper in Python
5
- Author-email: Timofey Egorov <timegorr@gmail.com>
6
- License-Expression: MIT
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: Operating System :: OS Independent
9
- Requires-Python: >=3.11
10
- Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
- Requires-Dist: google-auth
13
- Requires-Dist: google-api-python-client
14
- Requires-Dist: pydantic>=2.0.0
15
- Dynamic: license-file
16
-
17
- ### Установка
18
- ```bash
19
- pip install git+https://github.com/Timofey28/google-sheets.git
20
- ```
@@ -1,4 +0,0 @@
1
- ### Установка
2
- ```bash
3
- pip install git+https://github.com/Timofey28/google-sheets.git
4
- ```
@@ -1,20 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: python-google-sheets
3
- Version: 0.1.0
4
- Summary: The most efficient Google Sheets API wrapper in Python
5
- Author-email: Timofey Egorov <timegorr@gmail.com>
6
- License-Expression: MIT
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: Operating System :: OS Independent
9
- Requires-Python: >=3.11
10
- Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
- Requires-Dist: google-auth
13
- Requires-Dist: google-api-python-client
14
- Requires-Dist: pydantic>=2.0.0
15
- Dynamic: license-file
16
-
17
- ### Установка
18
- ```bash
19
- pip install git+https://github.com/Timofey28/google-sheets.git
20
- ```