python-google-sheets 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl

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.
@@ -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:
@@ -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,6 +1,6 @@
1
1
  google_sheets/__init__.py,sha256=n82JQthRRM_04DvQ55MI3-zESTmTsjxim39hwv-5d8M,518
2
2
  google_sheets/api_request.py,sha256=nQPci0yTZvjKHUrOFPqvCQD8QkDBuqO166zp_Rvk-uI,17409
3
- google_sheets/google_sheets.py,sha256=GjjQQI4yw8DljHFOxB9GEkHHk5DGvrECtaFzzFFEDsc,7299
3
+ google_sheets/google_sheets.py,sha256=pds74uJR8qHsowTb1OnqtchIAsQENMVXwWsYN2kBLks,7878
4
4
  google_sheets/styles.py,sha256=301ddWLfpZQzr7eKFAvqmVD5n8tEGtrG2cs6N2RpUUo,12682
5
5
  google_sheets/utils.py,sha256=3HCCwrd_poMeEAJgamxN2NsyKYCIAsMcC-ZwCMU_pMU,1590
6
6
  google_sheets/spreadsheet_requests/__init__.py,sha256=pwkZTskPq4WLjI4uJiZ8C5OPCBU-grmjoSSu114jdjM,1191
@@ -11,8 +11,8 @@ google_sheets/spreadsheet_requests/merge_cells.py,sha256=Y7ChGjmb07jCCG1aP2Ws126
11
11
  google_sheets/spreadsheet_requests/spreadsheet.py,sha256=ZW9nzNR9hjibuNVsAJI8jssjjKCKeEuGhduh6ZkHjh4,3496
12
12
  google_sheets/spreadsheet_requests/update_cells.py,sha256=ncxmBpUQU19wHc-kBMa5K2NAVgJQMW4npyS5h5jqNA0,9117
13
13
  google_sheets/spreadsheet_requests/update_sheet_properties.py,sha256=TKFZHq6Du6wFMZgcf7YAavn_JrIsbxWqQqWKJiqgRMQ,1837
14
- python_google_sheets-0.1.0.dist-info/licenses/LICENSE,sha256=2PFWLbALHdUFzFd2QtLQvu7Ku4M6IO53Ns6b892nVvg,1090
15
- python_google_sheets-0.1.0.dist-info/METADATA,sha256=j1k_pi1AfvxOw3QTvWW96vyXhEjpVhgbKCS0H89tNyk,622
16
- python_google_sheets-0.1.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
17
- python_google_sheets-0.1.0.dist-info/top_level.txt,sha256=AEiUl4h4VXrqsRO0AiL9C7ArYqmDhVuz--b035K3r34,14
18
- python_google_sheets-0.1.0.dist-info/RECORD,,
14
+ python_google_sheets-0.1.2.dist-info/licenses/LICENSE,sha256=2PFWLbALHdUFzFd2QtLQvu7Ku4M6IO53Ns6b892nVvg,1090
15
+ python_google_sheets-0.1.2.dist-info/METADATA,sha256=p2tW9oNM75gDNia2vEReNt8SP5t4aUrwC_oqSqKBTYA,2233
16
+ python_google_sheets-0.1.2.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
17
+ python_google_sheets-0.1.2.dist-info/top_level.txt,sha256=AEiUl4h4VXrqsRO0AiL9C7ArYqmDhVuz--b035K3r34,14
18
+ python_google_sheets-0.1.2.dist-info/RECORD,,
@@ -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
- ```