PyGenericSpreadSheet API Documentation
googlesheet
Created on 2022-04-18
@author: wf
GoogleSheet
Bases: object
GoogleSheet Handling
Source code in spreadsheet/googlesheet.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
__init__(url, readonly=True, max_retries=5, max_wait=60.0)
Initializes an instance of GoogleSheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str
|
URL to the Google Sheet. |
required |
readonly |
bool
|
If True, uses read-only scopes, otherwise uses full access scopes. |
True
|
Source code in spreadsheet/googlesheet.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
asListOfDicts(sheet_name)
Converts a sheet to a list of dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_name |
str
|
The name of the sheet to convert. |
required |
Returns:
| Type | Description |
|---|---|
List
|
A list of dictionaries, each representing a row in the sheet. |
Source code in spreadsheet/googlesheet.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
fixRows(lod)
fix Rows by filtering unnamed columns and trimming column names
Source code in spreadsheet/googlesheet.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
get_credentials()
Check for Google API credentials in the home directory or the GOOGLE_API_KEY environment variable
Source code in spreadsheet/googlesheet.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
open(sheet_names=None)
Opens the Google Sheet and loads the data from specified sheet names into a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_names |
list
|
Optional list of sheet names to open. Opens all sheets if None. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary with sheet names as keys and lists of dictionaries (rows) as values. |
Source code in spreadsheet/googlesheet.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
safe_api_call(func, *args, **kwargs)
Safe wrapper for API calls with exponential backoff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func |
The API function to call. |
required | |
*args |
Arguments for the API function. |
()
|
|
**kwargs |
Keyword arguments for the API function. |
{}
|
Returns:
| Type | Description |
|---|---|
|
The result of the API function call. |
Source code in spreadsheet/googlesheet.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
toSparql(url, sheetName, entityName, pkColumn, mappingSheetName='WikidataMapping', lang='en', debug=False)
classmethod
get a sparql query for the given google sheet
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str
|
the url of the sheet |
required |
sheetName |
str
|
the name of the sheet with the description |
required |
entityName |
str
|
the name of the entity as defined in the Wikidata mapping |
required |
pkColumn |
str
|
the column to use as a "primary key" |
required |
mappingSheetName |
str
|
the name of the sheet with the Wikidata mappings |
'WikidataMapping'
|
lang |
str
|
the language to use (if any) |
'en'
|
debug |
bool
|
if True switch on debugging |
False
|
Returns:
| Type | Description |
|---|---|
(WikibaseQuery, str)
|
WikibaseQuery |
Source code in spreadsheet/googlesheet.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
toWikibaseQuery(url, sheetName='WikidataMapping', debug=False)
classmethod
create a dict of wikibaseQueries from the given google sheets row descriptions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url(str) |
the url of the sheet |
required | |
sheetName(str) |
the name of the sheet with the description |
required | |
debug(bool) |
if True switch on debugging |
required |
Source code in spreadsheet/googlesheet.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
spreadsheet
CSVSpreadSheet
Bases: SpreadSheet
CSV Spreadsheet packaging as ZIP file of CSV files
Source code in spreadsheet/spreadsheet.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
toBytesIO()
Converts the document into an BytesIO stream
Returns:
| Type | Description |
|---|---|
BytesIO
|
BytesIO Stream of the document |
Source code in spreadsheet/spreadsheet.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
ExcelDocument
Bases: SpreadSheet
Provides methods to convert LoDs to an excel document and vice versa
Source code in spreadsheet/spreadsheet.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
__init__(name, engine=None, spreadSheetType=SpreadSheetType.EXCEL)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name(str) |
name of the document |
required |
Source code in spreadsheet/spreadsheet.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
toBytesIO()
Converts the document into an BytesIO stream
Returns:
| Type | Description |
|---|---|
BytesIO
|
BytesIO Stream of the document |
Source code in spreadsheet/spreadsheet.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
Format
potential Formats
Source code in spreadsheet/spreadsheet.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
OdsDocument
Bases: ExcelDocument
OpenDocument Spreadsheet that can store multiple tables. Provides functions to traverse between LoD and ODS document
Source code in spreadsheet/spreadsheet.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
__init__(name)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name(str) |
name of the document |
required |
Source code in spreadsheet/spreadsheet.py
495 496 497 498 499 500 501 502 | |
SpreadSheet
i am onlinespreadsheet
Source code in spreadsheet/spreadsheet.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
__init__(name, spreadSheetType)
constructor
Source code in spreadsheet/spreadsheet.py
91 92 93 94 95 96 97 98 | |
addTable(name, lod, headers=None)
add the given data as table to the document
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name(str) |
name of the table |
required | |
lod |
list
|
data that should be added to the document as table |
required |
headers(dict) |
Mapping from dict key to the new headers. Also functions as restriction. If not defined dict key are used as headers |
required |
Source code in spreadsheet/spreadsheet.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
create(spreadSheetType, name)
classmethod
create a SpreadSheet of the given types
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spreadSheetType(SpreadSheetType) |
the type of onlinespreadsheet to create |
required | |
name(str) |
the name of the onlinespreadsheet |
required |
Source code in spreadsheet/spreadsheet.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
fixLodTypes(lod, samples, typeConversionMap=None)
staticmethod
Fixes the types of the values of the given lod by converting it to the type corresponding to the given sampeles
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lod(list) |
List of dicts to be type fixed |
required | |
samples(list) |
list of samples specifying the value types |
required | |
typeConversionMap(dict) |
Map from type to corresponding conversion function. If None default conversions for string values are used. |
required |
Source code in spreadsheet/spreadsheet.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
getTable(name)
returns the data corresponding to the given table name Args: name: name of the table
Returns:
| Type | Description |
|---|---|
|
LoD |
Source code in spreadsheet/spreadsheet.py
171 172 173 174 175 176 177 178 179 180 181 | |
hasTable(name)
Checks if table under given name exists
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name(str) |
name of the Table |
required |
Retruns
True if table exists otherwise False
Source code in spreadsheet/spreadsheet.py
202 203 204 205 206 207 208 209 210 211 212 | |
load(document)
classmethod
Tries to load the given document as SpreadSheet Args: document: onlinespreadsheet document to load
Returns:
| Type | Description |
|---|---|
|
SpreadSheet |
Source code in spreadsheet/spreadsheet.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
loadFromFile(file, samples=None)
Load SpreadSheet from given file or file object
Source code in spreadsheet/spreadsheet.py
243 244 245 246 247 248 249 250 251 252 253 | |
saveToFile(fileName=None, dir_name=None)
saves SpreadSheet to file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fileName(str) |
name of the file if None SpreadSheet name is used |
required | |
dir_name(str) |
name of directory to store the file |
required |
Returns:
| Type | Description |
|---|---|
|
Nothing |
Source code in spreadsheet/spreadsheet.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
toBytesIO()
Converts the document into an BytesIO stream
Returns:
| Type | Description |
|---|---|
BytesIO
|
BytesIO Stream of the document |
Source code in spreadsheet/spreadsheet.py
234 235 236 237 238 239 240 241 | |
SpreadSheetType
Bases: Enum
Entities of openresearch. Used to specify for a fixer the domain of operation.
Source code in spreadsheet/spreadsheet.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
tableediting
Created on 2021-12-08
@author: wf
TableEditing
Bases: object
table Editing
enhancement onlinespreadsheet editing call validation
Source code in spreadsheet/tableediting.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
__init__(lods=None)
Constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lods(dict) |
a dict of list of dicts that represents the content of a Spreadsheet |
required |
Source code in spreadsheet/tableediting.py
18 19 20 21 22 23 24 25 26 27 28 29 | |
addEnhancer(callback)
add the given enhancer callback to my callbacks
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback(func) |
the callback function to add |
required |
Source code in spreadsheet/tableediting.py
56 57 58 59 60 61 62 63 | |
addLoD(name, lod)
add the given list of dicts with the given name to my lods
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name(str) |
the name |
required | |
lod(list) |
the list of dicts to add |
required |
Source code in spreadsheet/tableediting.py
46 47 48 49 50 51 52 53 54 | |
enhance()
enhance/enrich my list of dicts with the set callbacks
Source code in spreadsheet/tableediting.py
65 66 67 68 69 70 | |
toSpreadSheet(spreadSheetType, name)
convert me to the given spreadSheetType
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spreadSheetType(SpreadSheetType) |
the type of onlinespreadsheet to create |
required | |
name(str) |
the name of the onlinespreadsheet |
required |
Source code in spreadsheet/tableediting.py
31 32 33 34 35 36 37 38 39 40 41 | |
version
Created on 2022-04-21
@author: wf
Version
Bases: object
Version handling for pyGenericSpreadSheet
Source code in spreadsheet/version.py
9 10 11 12 13 14 15 16 17 18 | |