daselement_api.api
Documentation for the API
API works for both Python 2 & 3
Available in version 1.2+
Install
Download folder: daselement_api
In the background the CLI version of _das element_ is exectued.
Please link the correct executable das-element-cli in the file daselement_api/manager.py
from daselement_api import api as de
libraries = de.get_libraries()
for library, library_config_data in libraries.items():
print(library)
print(library_config_data)
The library information is taken from the config file that is set for the current workstation.
Either defined in the ~/.das-element/setup.ini
file or by the environment variable DASELEMENT_CONFIG_PATH
1# __ __ __ 2# ____/ /___ ______ ___ / /__ ____ ___ ___ ____ / /_ 3# / __ / __ `/ ___/ / _ \/ / _ \/ __ `__ \/ _ \/ __ \/ __/ 4# / /_/ / /_/ (__ ) / __/ / __/ / / / / / __/ / / / /_ 5# \__,_/\__,_/____/ \___/_/\___/_/ /_/ /_/\___/_/ /_/\__/ 6# 7# Copyright (c) 2023 das element 8''' 9## Documentation for the API 10 11API works for both Python 2 & 3 12 13Available in version **1.2+** 14 15 16--- 17 18### Install 19 20[Download](https://github.com/das-element/python-api) folder: `daselement_api` 21 22In the background the CLI version of _das element_ is exectued. 23Please link the correct executable **das-element-cli** in the file **daselement_api/manager.py** 24 25``` 26from daselement_api import api as de 27libraries = de.get_libraries() 28for library, library_config_data in libraries.items(): 29 print(library) 30 print(library_config_data) 31``` 32 33--- 34 35The library information is taken from the config file that is set for the current workstation. 36Either defined in the `~/.das-element/setup.ini` file or by the environment variable `DASELEMENT_CONFIG_PATH` 37 38''' 39 40from .manager import execute_command, as_quoted_string, as_quoted_dict 41 42config = None 43''' 44Variabel to define a custom config file path (.conf) 45 46--- 47''' 48 49 50def get_libraries(): 51 ''' 52 Get all libraries data for current config. 53 54 **Returns**: 55 > - Dict[str, Dict]: *Key is the library file path (.lib) - Value is the library data* 56 57 **Example code**: 58 ``` 59 from daselement_api import api as de 60 61 libraries = de.get_libraries() 62 for library, library_config_data in libraries.items(): 63 print(library) 64 print(library_config_data) 65 ``` 66 ''' 67 command = ['--config', config] if config else [] 68 command += ['get-libraries'] 69 return execute_command(command) 70 71 72def get_library_template_mappings(library_path): 73 ''' 74 Get all template mappings data for library. 75 76 **Args**: 77 > - **library_path** (str): *File path to the library file (.lib)* 78 79 **Returns**: 80 > - List[Dict] 81 82 **Example code**: 83 ``` 84 from daselement_api import api as de 85 86 library_path = '/some/path/das-element.lib' 87 88 template_mappings = de.get_library_template_mappings(library_path) 89 for template_mapping in template_mappings: 90 print(template_mapping) 91 ``` 92 93 **Example result**: 94 `[{'key': 'copy & rename', 'value': {'extra': ['extra-job'], 'filmstrip': 'filmstrip', 'main': 'main', 'proxy': 'proxy mov', 'thumbnail': 'thumbnail'}}]` 95 ''' 96 command = ['--config', config] if config else [] 97 command += [ 98 'get-library-template-mappings', 99 as_quoted_string(library_path) 100 ] 101 return execute_command(command) 102 103 104def get_categories(library_path): 105 ''' 106 Get all categories from the database for the library. 107 108 **Args**: 109 > - **library_path** (str): *File path to the library file (.lib)* 110 111 **Returns**: 112 > - List[Dict] 113 114 **Example code**: 115 ``` 116 from daselement_api import api as de 117 118 library_path = '/some/path/das-element.lib' 119 120 categories = de.get_categories(library_path) 121 for category in categories: 122 print(category) 123 ``` 124 125 **Example result**: 126 `[{'id': 'Q235544', 'type': 'default', 'name': 'flame', 'child_count': 5, 'child_counter': 5, 'parents': [{'description': 'rapid oxidation of a material; phenomenon that emits light and heat', 'id': 'Q3196', 'name': 'fire', 'synonyms': [{'language': 'en', 'value': 'fire'}, {'language': 'en', 'value': 'fires'}], 'type': 'default'}], 'children': [{'id': 'Q327954', 'name': 'torch'}], 'synonyms': [{'language': 'en', 'value': 'flame'}]}]` 127 ''' 128 command = ['--config', config] if config else [] 129 command += ['get-categories', as_quoted_string(library_path)] 130 return execute_command(command) 131 132 133def get_category(library_path, category_value): 134 ''' 135 Get category entity from the database for the library. 136 137 **Args**: 138 > - **library_path** (str): *File path to the library file (.lib)* 139 > - **category_value** (str): *the ID ('Q3196') or name ('fire') of the category in the database* 140 141 **Returns**: 142 > - Dict[str, Union[str, int]]: *child_count: actual number of children - child_counter: increasing counter, even if children get deleted* 143 144 145 146 **Example code**: 147 ``` 148 from daselement_api import api as de 149 150 library_path = '/some/path/das-element.lib' 151 152 category_entity = de.get_category(library_path, 'Q3196') 153 category_entity = de.get_category(library_path, 'fire') 154 ``` 155 156 **Example result**: 157 `{"id": "Q3196", "type": "default", "name": "fire", "child_count": 130, "child_counter": 135}` 158 ''' 159 command = ['--config', config] if config else [] 160 command += [ 161 'get-category', 162 as_quoted_string(library_path), 163 as_quoted_string(category_value) 164 ] 165 return execute_command(command) 166 167 168def get_tags(library_path): 169 ''' 170 Get all tags from the database for the library. 171 172 **Args**: 173 > - **library_path** (str): *File path to the library file (.lib)* 174 175 **Returns**: 176 > - List[Dict] 177 178 **Example code**: 179 ``` 180 from daselement_api import api as de 181 182 library_path = '/some/path/das-element.lib' 183 184 tags = de.get_tags(library_path) 185 for tag in tags: 186 print(tag) 187 ``` 188 189 **Example result**: 190 `[{'id': 'Q235544', 'name': 'flame', 'type': 'default', 'elements_count': 3, 'synonyms': [{'language': 'en', 'value': 'flame'}]}]` 191 ''' 192 command = ['--config', config] if config else [] 193 command += ['get-tags', as_quoted_string(library_path)] 194 return execute_command(command) 195 196 197def get_tag(library_path, tag_value): 198 ''' 199 Get tag entity from the database for the library. 200 201 **Args**: 202 > - **library_path** (str): *File path to the library file (.lib)* 203 > - **tag_value** (str): *the ID ('Q3196') or name ('fire') of the tag in the database* 204 205 **Returns**: 206 > - Dict[str, Union[str, int]] 207 208 **Example code**: 209 ``` 210 from daselement_api import api as de 211 212 library_path = '/some/path/das-element.lib' 213 214 tag_entity = de.get_tag(library_path, 'Q3196') 215 tag_entity = de.get_tag(library_path, 'fire') 216 ``` 217 218 **Example result**: 219 `{"id": "Q3196", "name": "fire", "type": "default", "elements_count": 130}` 220 ''' 221 command = ['--config', config] if config else [] 222 command += [ 223 'get-tag', 224 as_quoted_string(library_path), 225 as_quoted_string(tag_value) 226 ] 227 return execute_command(command) 228 229 230def get_elements(library_path): 231 ''' 232 Get all elements from the database for the library. 233 234 **Args**: 235 > - **library_path** (str): *File path to the library file (.lib)* 236 237 **Returns**: 238 > - List[Dict] 239 240 **Example code**: 241 ``` 242 from daselement_api import api as de 243 244 library_path = '/some/path/das-element.lib' 245 246 elements = de.get_elements(library_path) 247 for element in elements: 248 print(element) 249 print(element.get('path')) 250 ``` 251 252 **Example result**: 253 `[{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}]` 254 ''' 255 command = ['--config', config] if config else [] 256 command += ['get-elements', as_quoted_string(library_path)] 257 return execute_command(command) 258 259 260def get_element_by_id(library_path, element_id): 261 ''' 262 Get element entity based on the **element ID** from the database for the library. 263 264 **Args**: 265 > - **library_path** (str): *File path to the library file (.lib)* 266 > - **element_id** (int): *Element ID in the database* 267 268 **Returns**: 269 > - Dict 270 271 **Example code**: 272 ``` 273 from daselement_api import api as de 274 275 library_path = '/some/path/das-element.lib' 276 element_id = 1 277 278 element = de.get_element_by_id(library_path, element_id) 279 print(element) 280 print(element.get('path')) 281 ``` 282 283 **Example result**: 284 `{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}` 285 ''' 286 command = ['--config', config] if config else [] 287 command += [ 288 'get-element-by-id', 289 as_quoted_string(library_path), element_id 290 ] 291 return execute_command(command) 292 293 294def get_element_by_uuid(element_uuid, library_path=None): 295 ''' 296 Get element entity based on the **element UUID** from the database for the library. 297 If no library path is provided, all libraries of the current config will be searched. 298 299 **Args**: 300 > - **library_path** (str): *[optional] File path to the library file (.lib)* 301 > - **element_uuid** (str): *Element UUID (unique ID) in the database* 302 303 **Returns**: 304 > - Dict 305 306 **Example code**: 307 ``` 308 from daselement_api import api as de 309 310 element_uuid = '9947c549c6014a3ca831983275884051' 311 library_path = '/some/path/das-element.lib' # optional 312 313 element = de.get_element_by_uuid(element_uuid, library_path=library_path) 314 315 # without the library path each linked library in the config file will searched 316 element = de.get_element_by_uuid(element_uuid) 317 318 print(element) 319 print(element.get('path')) 320 ``` 321 322 **Example result**: 323 `{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}` 324 ''' 325 command = ['--config', config] if config else [] 326 command += ['get-element-by-uuid', element_uuid] 327 if library_path: 328 command += ['--library', as_quoted_string(library_path)] 329 return execute_command(command) 330 331 332def get_element_by_name(library_path, element_name): 333 ''' 334 Get element entity based on the **element name** from the database for the library. 335 336 **Args**: 337 > - **library_path** (str): *File path to the library file (.lib)* 338 > - **element_name** (str): *Element name in the database* 339 340 **Returns**: 341 > - Dict 342 343 **Example code**: 344 ``` 345 from daselement_api import api as de 346 347 library_path = '/some/path/das-element.lib' 348 element_name = 'fire_00001' 349 350 element = de.get_element_by_name(library_path, element_name) 351 print(element) 352 print(element.get('path')) 353 ``` 354 355 **Example result**: 356 `{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}` 357 ''' 358 command = ['--config', config] if config else [] 359 command += [ 360 'get-element-by-name', 361 as_quoted_string(library_path), element_name 362 ] 363 return execute_command(command) 364 365 366def update(library_path, entity_type, entity_id, data): 367 ''' 368 Updates database entity with new data 369 370 371 **Args**: 372 > - **library_path** (str): *File path to the library file (.lib)* 373 > - **entity_type** (str): *Type of entity to update. Options: [Category, Element, Tag]* 374 > - **entity_id** (Union[str, int]): *the ID of the entity to update in the database* 375 > - **data** (Dict): *data to update. Dictionary with key/value pairs formated as JSON.* 376 *Example:* `"{\\\"rating\\\": 3}"` 377 378 **Returns**: 379 > - Dict: *Entity of the updated entity* 380 381 **Example code**: 382 ``` 383 from daselement_api import api as de 384 385 library_path = '/some/path/das-element.lib' 386 entity_type = 'Element' 387 entity_id = 23 388 new_data = {'category_id': 'Q327954', # or: 'category': 'torch', 389 'tags': ['flame', 'fire', 'torch', 'something custom tag']} 390 391 entity = de.update(library_path, entity_type, entity_id, new_data) 392 print(entity) 393 print(entity.get('rating')) 394 ``` 395 396 **Example result**: 397 `{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}, {"id": "something","name": "something custom tag", "type": "custom", "elements_count": 1}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}` 398 399 **Example command line command**: 400 ##### Windows 401 `das-element-cli.exe update C:\\mnt\\library\\das-element.lib element 1 "{\\\"rating\\\": 3}"` 402 ##### Linux/MacOS 403 `das-element-cli update /mnt/library/das-element.lib element 1 '{\"rating\": 3}'` 404 ''' 405 command = ['--config', config] if config else [] 406 command += [ 407 'update', 408 as_quoted_string(library_path), 409 as_quoted_string(entity_type), 410 as_quoted_string(entity_id), 411 as_quoted_dict(data) 412 ] 413 return execute_command(command) 414 415 416def delete_element(element_uuid, 417 delete_from_database=False, 418 delete_from_disk=False, 419 library_path=None): 420 ''' 421 Deletes an element entity based on the **element UUID**. 422 The options are to delete the element data from the database, delete the element files on disk or delete from both the database and files on disk. 423 424 **Args**: 425 > - **element_uuid** (str): *Element UUID (unique ID) in the database* 426 > - **delete_from_database** (bool): *[optional] delete data from the database* 427 > - **delete_from_disk** (bool): *[optional] delete all element files from disk* 428 > - **library_path** (str): *[optional] File path to the library file (.lib)* 429 430 **Returns**: 431 > - bool 432 433 **Example code**: 434 ``` 435 from daselement_api import api as de 436 437 element_uuid = '9947c549c6014a3ca831983275884051' 438 delete_from_database = True 439 delete_from_disk = True 440 library_path = '/some/path/das-element.lib' # optional 441 442 de.delete_element(element_uuid, delete_from_database, delete_from_disk, library_path=library_path) 443 444 ``` 445 446 **Example result**: 447 `true` 448 ''' 449 command = ['--config', config] if config else [] 450 command += [ 451 'delete-element', 452 element_uuid, 453 ] 454 if delete_from_database: 455 command += ['--database'] 456 if delete_from_disk: 457 command += ['--disk'] 458 if library_path: 459 command += ['--library', as_quoted_string(library_path)] 460 return execute_command(command) 461 462 463def ingest(library_path, mapping, path, category, tags=[]): 464 ''' 465 Ingest a new element to the library 466 467 Ingesting a file sequence requires the path to be in a [fileseq.FileSequence notation](https://github.com/justinfx/fileseq#filesequence) 468 Thank you to the developers of [fileseq](https://github.com/justinfx/fileseq)! 469 470 Example: `/some/folder/files.1001-1099#.exr` 471 472 473 **Args**: 474 > - **library_path** (str): *File path to the library file (.lib)* 475 > - **mapping** (str): *Name of the transcoding mapping used to ingest* 476 > - **path** (str): *File path to the new element* 477 > - **category** (str): *Category name of new element (can be WikiData-ID or human-readable text)* 478 > - **tags** (List[str]): *[optional] List of tags* 479 480 **Returns**: 481 > - Dict: *Element entity for the newly created element* 482 483 **Example code**: 484 ``` 485 from daselement_api import api as de 486 487 library_path = '/some/path/das-element.lib' 488 mapping = 'copy & rename' 489 path = '/some/folder/files.1001-1099#.exr' 490 category = 'Q235544' # or: 'flame' 491 tags = ['Q3196', 'foo', 'bar'] 492 493 entity = de.ingest(library_path, mapping, path, category, tags) 494 print(entity) 495 print(entity.get('path')) 496 ``` 497 498 **Example result**: 499 `{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}` 500 501 **Example command line command**: 502 `das-element-cli ingest --library /mnt/library/das-element.lib --mapping "copy & rename" --path /some/file/path.1001-1099#.exr --category Q235544 --tags Q3196,foo,bar` 503 ''' 504 command = ['--config', config] if config else [] 505 command += [ 506 'ingest', '--library', 507 as_quoted_string(library_path), '--mapping', 508 as_quoted_string(mapping), '--path', 509 as_quoted_string(path), '--category', 510 as_quoted_string(category), '--tags', 511 as_quoted_string(','.join(tags)) 512 ] 513 return execute_command(command) 514 515 516def predict(path, model=None, top=2, filmstrip_frames=36): 517 ''' 518 Predict the category for a give file path. 519 520 The give path can be a file or a directory. 521 If a directory is provided, all sub-directories will be searched for files and sequences. 522 523 524 **Args**: 525 526 > - **model** (str): [optional] *Define a custom model file path (.wit)* 527 > - **filmstrip_frames** (int): [optional] *Number of frames to validated for a movie file or sequence. The higher the number, the better the result might be, but it also takes longer* 528 > - **top** (int): [optional] *Return the top X predictions* 529 530 531 **Returns**: 532 > - Dict[str, List[Dict]]: *Key is the file path. The value a list of predicted categories* 533 534 535 **Example result**: 536 `{"/some/file/path.1001-1099#.exr": [{"tag": "flame", "description": "visible, gaseous part of a fire", "id": "Q235544", "value": "Q235544", "parents": [{"description": "rapid oxidation of a material; phenomenon that emits light and heat", "id": "Q3196", "name": "fire", "synonyms": [{"language": "en", "value": "fire"}, {"language": "en", "value": "fires"}}]}]}` 537 538 539 **Example command line command**: 540 `das-element-cli predict --top=2 /some/file/path` 541 542 ''' 543 command = ['predict', '--top', top, '--filmstrip_frames', filmstrip_frames] 544 545 if model: 546 command += ['--model', as_quoted_string(model)] 547 548 command += [path] 549 return execute_command(command) 550 551 552def get_paths_from_disk(path, as_sequence=True): 553 ''' 554 Recursivly searches for files and sequences in a given directory. Since version 1.2.5 555 556 The give path can be a file or a directory. 557 If a directory is provided, all sub-directories will be searched for files and sequences. 558 559 560 **Args**: 561 562 > - **as_sequence / as_single_files** (bool): [optional] defines if files with a sequential naming should be detected as a file sequence or individual files 563 564 565 **Returns**: 566 > - List[str]: *List of file paths found in the give directory* 567 568 569 **Example result**: 570 `["/some/file/path.1001-1099#.exr", "/other/path.mov"]` 571 572 573 **Example command line command**: 574 `das-element-cli get-paths-from-disk --as_sequence /some/file/path` 575 576 ''' 577 command = ['get-paths-from-disk'] 578 579 if as_sequence: 580 command += ['--as_sequence'] 581 else: 582 command += ['--as_single_files'] 583 584 command += [path] 585 return execute_command(command)
Variabel to define a custom config file path (.conf)
51def get_libraries(): 52 ''' 53 Get all libraries data for current config. 54 55 **Returns**: 56 > - Dict[str, Dict]: *Key is the library file path (.lib) - Value is the library data* 57 58 **Example code**: 59 ``` 60 from daselement_api import api as de 61 62 libraries = de.get_libraries() 63 for library, library_config_data in libraries.items(): 64 print(library) 65 print(library_config_data) 66 ``` 67 ''' 68 command = ['--config', config] if config else [] 69 command += ['get-libraries'] 70 return execute_command(command)
Get all libraries data for current config.
Returns:
- Dict[str, Dict]: Key is the library file path (.lib) - Value is the library data
Example code:
from daselement_api import api as de
libraries = de.get_libraries()
for library, library_config_data in libraries.items():
print(library)
print(library_config_data)
73def get_library_template_mappings(library_path): 74 ''' 75 Get all template mappings data for library. 76 77 **Args**: 78 > - **library_path** (str): *File path to the library file (.lib)* 79 80 **Returns**: 81 > - List[Dict] 82 83 **Example code**: 84 ``` 85 from daselement_api import api as de 86 87 library_path = '/some/path/das-element.lib' 88 89 template_mappings = de.get_library_template_mappings(library_path) 90 for template_mapping in template_mappings: 91 print(template_mapping) 92 ``` 93 94 **Example result**: 95 `[{'key': 'copy & rename', 'value': {'extra': ['extra-job'], 'filmstrip': 'filmstrip', 'main': 'main', 'proxy': 'proxy mov', 'thumbnail': 'thumbnail'}}]` 96 ''' 97 command = ['--config', config] if config else [] 98 command += [ 99 'get-library-template-mappings', 100 as_quoted_string(library_path) 101 ] 102 return execute_command(command)
Get all template mappings data for library.
Args:
- library_path (str): File path to the library file (.lib)
Returns:
- List[Dict]
Example code:
from daselement_api import api as de
library_path = '/some/path/das-element.lib'
template_mappings = de.get_library_template_mappings(library_path)
for template_mapping in template_mappings:
print(template_mapping)
Example result:
[{'key': 'copy & rename', 'value': {'extra': ['extra-job'], 'filmstrip': 'filmstrip', 'main': 'main', 'proxy': 'proxy mov', 'thumbnail': 'thumbnail'}}]
105def get_categories(library_path): 106 ''' 107 Get all categories from the database for the library. 108 109 **Args**: 110 > - **library_path** (str): *File path to the library file (.lib)* 111 112 **Returns**: 113 > - List[Dict] 114 115 **Example code**: 116 ``` 117 from daselement_api import api as de 118 119 library_path = '/some/path/das-element.lib' 120 121 categories = de.get_categories(library_path) 122 for category in categories: 123 print(category) 124 ``` 125 126 **Example result**: 127 `[{'id': 'Q235544', 'type': 'default', 'name': 'flame', 'child_count': 5, 'child_counter': 5, 'parents': [{'description': 'rapid oxidation of a material; phenomenon that emits light and heat', 'id': 'Q3196', 'name': 'fire', 'synonyms': [{'language': 'en', 'value': 'fire'}, {'language': 'en', 'value': 'fires'}], 'type': 'default'}], 'children': [{'id': 'Q327954', 'name': 'torch'}], 'synonyms': [{'language': 'en', 'value': 'flame'}]}]` 128 ''' 129 command = ['--config', config] if config else [] 130 command += ['get-categories', as_quoted_string(library_path)] 131 return execute_command(command)
Get all categories from the database for the library.
Args:
- library_path (str): File path to the library file (.lib)
Returns:
- List[Dict]
Example code:
from daselement_api import api as de
library_path = '/some/path/das-element.lib'
categories = de.get_categories(library_path)
for category in categories:
print(category)
Example result:
[{'id': 'Q235544', 'type': 'default', 'name': 'flame', 'child_count': 5, 'child_counter': 5, 'parents': [{'description': 'rapid oxidation of a material; phenomenon that emits light and heat', 'id': 'Q3196', 'name': 'fire', 'synonyms': [{'language': 'en', 'value': 'fire'}, {'language': 'en', 'value': 'fires'}], 'type': 'default'}], 'children': [{'id': 'Q327954', 'name': 'torch'}], 'synonyms': [{'language': 'en', 'value': 'flame'}]}]
134def get_category(library_path, category_value): 135 ''' 136 Get category entity from the database for the library. 137 138 **Args**: 139 > - **library_path** (str): *File path to the library file (.lib)* 140 > - **category_value** (str): *the ID ('Q3196') or name ('fire') of the category in the database* 141 142 **Returns**: 143 > - Dict[str, Union[str, int]]: *child_count: actual number of children - child_counter: increasing counter, even if children get deleted* 144 145 146 147 **Example code**: 148 ``` 149 from daselement_api import api as de 150 151 library_path = '/some/path/das-element.lib' 152 153 category_entity = de.get_category(library_path, 'Q3196') 154 category_entity = de.get_category(library_path, 'fire') 155 ``` 156 157 **Example result**: 158 `{"id": "Q3196", "type": "default", "name": "fire", "child_count": 130, "child_counter": 135}` 159 ''' 160 command = ['--config', config] if config else [] 161 command += [ 162 'get-category', 163 as_quoted_string(library_path), 164 as_quoted_string(category_value) 165 ] 166 return execute_command(command)
Get category entity from the database for the library.
Args:
- library_path (str): File path to the library file (.lib)
- category_value (str): the ID ('Q3196') or name ('fire') of the category in the database
Returns:
- Dict[str, Union[str, int]]: child_count: actual number of children - child_counter: increasing counter, even if children get deleted
Example code:
from daselement_api import api as de
library_path = '/some/path/das-element.lib'
category_entity = de.get_category(library_path, 'Q3196')
category_entity = de.get_category(library_path, 'fire')
Example result:
{"id": "Q3196", "type": "default", "name": "fire", "child_count": 130, "child_counter": 135}
198def get_tag(library_path, tag_value): 199 ''' 200 Get tag entity from the database for the library. 201 202 **Args**: 203 > - **library_path** (str): *File path to the library file (.lib)* 204 > - **tag_value** (str): *the ID ('Q3196') or name ('fire') of the tag in the database* 205 206 **Returns**: 207 > - Dict[str, Union[str, int]] 208 209 **Example code**: 210 ``` 211 from daselement_api import api as de 212 213 library_path = '/some/path/das-element.lib' 214 215 tag_entity = de.get_tag(library_path, 'Q3196') 216 tag_entity = de.get_tag(library_path, 'fire') 217 ``` 218 219 **Example result**: 220 `{"id": "Q3196", "name": "fire", "type": "default", "elements_count": 130}` 221 ''' 222 command = ['--config', config] if config else [] 223 command += [ 224 'get-tag', 225 as_quoted_string(library_path), 226 as_quoted_string(tag_value) 227 ] 228 return execute_command(command)
Get tag entity from the database for the library.
Args:
- library_path (str): File path to the library file (.lib)
- tag_value (str): the ID ('Q3196') or name ('fire') of the tag in the database
Returns:
- Dict[str, Union[str, int]]
Example code:
from daselement_api import api as de
library_path = '/some/path/das-element.lib'
tag_entity = de.get_tag(library_path, 'Q3196')
tag_entity = de.get_tag(library_path, 'fire')
Example result:
{"id": "Q3196", "name": "fire", "type": "default", "elements_count": 130}
231def get_elements(library_path): 232 ''' 233 Get all elements from the database for the library. 234 235 **Args**: 236 > - **library_path** (str): *File path to the library file (.lib)* 237 238 **Returns**: 239 > - List[Dict] 240 241 **Example code**: 242 ``` 243 from daselement_api import api as de 244 245 library_path = '/some/path/das-element.lib' 246 247 elements = de.get_elements(library_path) 248 for element in elements: 249 print(element) 250 print(element.get('path')) 251 ``` 252 253 **Example result**: 254 `[{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}]` 255 ''' 256 command = ['--config', config] if config else [] 257 command += ['get-elements', as_quoted_string(library_path)] 258 return execute_command(command)
Get all elements from the database for the library.
Args:
- library_path (str): File path to the library file (.lib)
Returns:
- List[Dict]
Example code:
from daselement_api import api as de
library_path = '/some/path/das-element.lib'
elements = de.get_elements(library_path)
for element in elements:
print(element)
print(element.get('path'))
Example result:
[{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}]
261def get_element_by_id(library_path, element_id): 262 ''' 263 Get element entity based on the **element ID** from the database for the library. 264 265 **Args**: 266 > - **library_path** (str): *File path to the library file (.lib)* 267 > - **element_id** (int): *Element ID in the database* 268 269 **Returns**: 270 > - Dict 271 272 **Example code**: 273 ``` 274 from daselement_api import api as de 275 276 library_path = '/some/path/das-element.lib' 277 element_id = 1 278 279 element = de.get_element_by_id(library_path, element_id) 280 print(element) 281 print(element.get('path')) 282 ``` 283 284 **Example result**: 285 `{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}` 286 ''' 287 command = ['--config', config] if config else [] 288 command += [ 289 'get-element-by-id', 290 as_quoted_string(library_path), element_id 291 ] 292 return execute_command(command)
Get element entity based on the element ID from the database for the library.
Args:
- library_path (str): File path to the library file (.lib)
- element_id (int): Element ID in the database
Returns:
- Dict
Example code:
from daselement_api import api as de
library_path = '/some/path/das-element.lib'
element_id = 1
element = de.get_element_by_id(library_path, element_id)
print(element)
print(element.get('path'))
Example result:
{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}
295def get_element_by_uuid(element_uuid, library_path=None): 296 ''' 297 Get element entity based on the **element UUID** from the database for the library. 298 If no library path is provided, all libraries of the current config will be searched. 299 300 **Args**: 301 > - **library_path** (str): *[optional] File path to the library file (.lib)* 302 > - **element_uuid** (str): *Element UUID (unique ID) in the database* 303 304 **Returns**: 305 > - Dict 306 307 **Example code**: 308 ``` 309 from daselement_api import api as de 310 311 element_uuid = '9947c549c6014a3ca831983275884051' 312 library_path = '/some/path/das-element.lib' # optional 313 314 element = de.get_element_by_uuid(element_uuid, library_path=library_path) 315 316 # without the library path each linked library in the config file will searched 317 element = de.get_element_by_uuid(element_uuid) 318 319 print(element) 320 print(element.get('path')) 321 ``` 322 323 **Example result**: 324 `{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}` 325 ''' 326 command = ['--config', config] if config else [] 327 command += ['get-element-by-uuid', element_uuid] 328 if library_path: 329 command += ['--library', as_quoted_string(library_path)] 330 return execute_command(command)
Get element entity based on the element UUID from the database for the library. If no library path is provided, all libraries of the current config will be searched.
Args:
- library_path (str): [optional] File path to the library file (.lib)
- element_uuid (str): Element UUID (unique ID) in the database
Returns:
- Dict
Example code:
from daselement_api import api as de
element_uuid = '9947c549c6014a3ca831983275884051'
library_path = '/some/path/das-element.lib' # optional
element = de.get_element_by_uuid(element_uuid, library_path=library_path)
# without the library path each linked library in the config file will searched
element = de.get_element_by_uuid(element_uuid)
print(element)
print(element.get('path'))
Example result:
{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}
333def get_element_by_name(library_path, element_name): 334 ''' 335 Get element entity based on the **element name** from the database for the library. 336 337 **Args**: 338 > - **library_path** (str): *File path to the library file (.lib)* 339 > - **element_name** (str): *Element name in the database* 340 341 **Returns**: 342 > - Dict 343 344 **Example code**: 345 ``` 346 from daselement_api import api as de 347 348 library_path = '/some/path/das-element.lib' 349 element_name = 'fire_00001' 350 351 element = de.get_element_by_name(library_path, element_name) 352 print(element) 353 print(element.get('path')) 354 ``` 355 356 **Example result**: 357 `{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}` 358 ''' 359 command = ['--config', config] if config else [] 360 command += [ 361 'get-element-by-name', 362 as_quoted_string(library_path), element_name 363 ] 364 return execute_command(command)
Get element entity based on the element name from the database for the library.
Args:
- library_path (str): File path to the library file (.lib)
- element_name (str): Element name in the database
Returns:
- Dict
Example code:
from daselement_api import api as de
library_path = '/some/path/das-element.lib'
element_name = 'fire_00001'
element = de.get_element_by_name(library_path, element_name)
print(element)
print(element.get('path'))
Example result:
{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}
367def update(library_path, entity_type, entity_id, data): 368 ''' 369 Updates database entity with new data 370 371 372 **Args**: 373 > - **library_path** (str): *File path to the library file (.lib)* 374 > - **entity_type** (str): *Type of entity to update. Options: [Category, Element, Tag]* 375 > - **entity_id** (Union[str, int]): *the ID of the entity to update in the database* 376 > - **data** (Dict): *data to update. Dictionary with key/value pairs formated as JSON.* 377 *Example:* `"{\\\"rating\\\": 3}"` 378 379 **Returns**: 380 > - Dict: *Entity of the updated entity* 381 382 **Example code**: 383 ``` 384 from daselement_api import api as de 385 386 library_path = '/some/path/das-element.lib' 387 entity_type = 'Element' 388 entity_id = 23 389 new_data = {'category_id': 'Q327954', # or: 'category': 'torch', 390 'tags': ['flame', 'fire', 'torch', 'something custom tag']} 391 392 entity = de.update(library_path, entity_type, entity_id, new_data) 393 print(entity) 394 print(entity.get('rating')) 395 ``` 396 397 **Example result**: 398 `{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}, {"id": "something","name": "something custom tag", "type": "custom", "elements_count": 1}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}` 399 400 **Example command line command**: 401 ##### Windows 402 `das-element-cli.exe update C:\\mnt\\library\\das-element.lib element 1 "{\\\"rating\\\": 3}"` 403 ##### Linux/MacOS 404 `das-element-cli update /mnt/library/das-element.lib element 1 '{\"rating\": 3}'` 405 ''' 406 command = ['--config', config] if config else [] 407 command += [ 408 'update', 409 as_quoted_string(library_path), 410 as_quoted_string(entity_type), 411 as_quoted_string(entity_id), 412 as_quoted_dict(data) 413 ] 414 return execute_command(command)
Updates database entity with new data
Args:
- library_path (str): File path to the library file (.lib)
- entity_type (str): Type of entity to update. Options: [Category, Element, Tag]
- entity_id (Union[str, int]): the ID of the entity to update in the database
- data (Dict): data to update. Dictionary with key/value pairs formated as JSON.
Example:"{\"rating\": 3}"
Returns:
- Dict: Entity of the updated entity
Example code:
from daselement_api import api as de
library_path = '/some/path/das-element.lib'
entity_type = 'Element'
entity_id = 23
new_data = {'category_id': 'Q327954', # or: 'category': 'torch',
'tags': ['flame', 'fire', 'torch', 'something custom tag']}
entity = de.update(library_path, entity_type, entity_id, new_data)
print(entity)
print(entity.get('rating'))
Example result:
{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}, {"id": "something","name": "something custom tag", "type": "custom", "elements_count": 1}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}
Example command line command:
Windows
das-element-cli.exe update C:\mnt\library\das-element.lib element 1 "{\"rating\": 3}"
Linux/MacOS
das-element-cli update /mnt/library/das-element.lib element 1 '{"rating": 3}'
417def delete_element(element_uuid, 418 delete_from_database=False, 419 delete_from_disk=False, 420 library_path=None): 421 ''' 422 Deletes an element entity based on the **element UUID**. 423 The options are to delete the element data from the database, delete the element files on disk or delete from both the database and files on disk. 424 425 **Args**: 426 > - **element_uuid** (str): *Element UUID (unique ID) in the database* 427 > - **delete_from_database** (bool): *[optional] delete data from the database* 428 > - **delete_from_disk** (bool): *[optional] delete all element files from disk* 429 > - **library_path** (str): *[optional] File path to the library file (.lib)* 430 431 **Returns**: 432 > - bool 433 434 **Example code**: 435 ``` 436 from daselement_api import api as de 437 438 element_uuid = '9947c549c6014a3ca831983275884051' 439 delete_from_database = True 440 delete_from_disk = True 441 library_path = '/some/path/das-element.lib' # optional 442 443 de.delete_element(element_uuid, delete_from_database, delete_from_disk, library_path=library_path) 444 445 ``` 446 447 **Example result**: 448 `true` 449 ''' 450 command = ['--config', config] if config else [] 451 command += [ 452 'delete-element', 453 element_uuid, 454 ] 455 if delete_from_database: 456 command += ['--database'] 457 if delete_from_disk: 458 command += ['--disk'] 459 if library_path: 460 command += ['--library', as_quoted_string(library_path)] 461 return execute_command(command)
Deletes an element entity based on the element UUID. The options are to delete the element data from the database, delete the element files on disk or delete from both the database and files on disk.
Args:
- element_uuid (str): Element UUID (unique ID) in the database
- delete_from_database (bool): [optional] delete data from the database
- delete_from_disk (bool): [optional] delete all element files from disk
- library_path (str): [optional] File path to the library file (.lib)
Returns:
- bool
Example code:
from daselement_api import api as de
element_uuid = '9947c549c6014a3ca831983275884051'
delete_from_database = True
delete_from_disk = True
library_path = '/some/path/das-element.lib' # optional
de.delete_element(element_uuid, delete_from_database, delete_from_disk, library_path=library_path)
Example result:
true
464def ingest(library_path, mapping, path, category, tags=[]): 465 ''' 466 Ingest a new element to the library 467 468 Ingesting a file sequence requires the path to be in a [fileseq.FileSequence notation](https://github.com/justinfx/fileseq#filesequence) 469 Thank you to the developers of [fileseq](https://github.com/justinfx/fileseq)! 470 471 Example: `/some/folder/files.1001-1099#.exr` 472 473 474 **Args**: 475 > - **library_path** (str): *File path to the library file (.lib)* 476 > - **mapping** (str): *Name of the transcoding mapping used to ingest* 477 > - **path** (str): *File path to the new element* 478 > - **category** (str): *Category name of new element (can be WikiData-ID or human-readable text)* 479 > - **tags** (List[str]): *[optional] List of tags* 480 481 **Returns**: 482 > - Dict: *Element entity for the newly created element* 483 484 **Example code**: 485 ``` 486 from daselement_api import api as de 487 488 library_path = '/some/path/das-element.lib' 489 mapping = 'copy & rename' 490 path = '/some/folder/files.1001-1099#.exr' 491 category = 'Q235544' # or: 'flame' 492 tags = ['Q3196', 'foo', 'bar'] 493 494 entity = de.ingest(library_path, mapping, path, category, tags) 495 print(entity) 496 print(entity.get('path')) 497 ``` 498 499 **Example result**: 500 `{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}` 501 502 **Example command line command**: 503 `das-element-cli ingest --library /mnt/library/das-element.lib --mapping "copy & rename" --path /some/file/path.1001-1099#.exr --category Q235544 --tags Q3196,foo,bar` 504 ''' 505 command = ['--config', config] if config else [] 506 command += [ 507 'ingest', '--library', 508 as_quoted_string(library_path), '--mapping', 509 as_quoted_string(mapping), '--path', 510 as_quoted_string(path), '--category', 511 as_quoted_string(category), '--tags', 512 as_quoted_string(','.join(tags)) 513 ] 514 return execute_command(command)
Ingest a new element to the library
Ingesting a file sequence requires the path to be in a fileseq.FileSequence notation
Thank you to the developers of fileseq!
Example: /some/folder/files.1001-1099#.exr
Args:
- library_path (str): File path to the library file (.lib)
- mapping (str): Name of the transcoding mapping used to ingest
- path (str): File path to the new element
- category (str): Category name of new element (can be WikiData-ID or human-readable text)
- tags (List[str]): [optional] List of tags
Returns:
- Dict: Element entity for the newly created element
Example code:
from daselement_api import api as de
library_path = '/some/path/das-element.lib'
mapping = 'copy & rename'
path = '/some/folder/files.1001-1099#.exr'
category = 'Q235544' # or: 'flame'
tags = ['Q3196', 'foo', 'bar']
entity = de.ingest(library_path, mapping, path, category, tags)
print(entity)
print(entity.get('path'))
Example result:
{"category": {"child_counter": 1,"description": "stick with a flaming end used as a source of light","id": "Q327954","name": "torch","type": "default"},"category_id": "Q327954","channel": 3,"colorspace": "sRGB","colorspace_source": "sRGB","created_at": "2022-05-16T08:26:52.854774","feature_id": 1,"frame_count": 1,"frame_first": 1,"frame_last": 1,"frame_rate": "","height": 5413,"id": 1,"media_type": "image","name": "fire_00001","number": "00001","path": "/mnt/library/fire/fire_00001/main_3342x5413_source/fire_00001.jpg","path_filmstrip": "/mnt/library/fire/fire_00001/filmstrip_11520x270_srgb/fire_00001.jpg","path_proxy": "/mnt/library/fire/fire_00001/proxy_1920x1080_srgb/fire_00001.mov","path_source": "/mnt/source/lication/some-image.jpg","path_thumbnail": "/mnt/library/fire/fire_00001/thumb_960x540_srgb/fire_00001.jpg","pixel_aspect": "1","popularity": "None","rating": "None","tags": [{"elements_count": 3,"id": "Q235544","name": "flame","type": "default"},{"elements_count": 56,"id": "Q3196","name": "fire","type": "default"},{"elements_count": 3,"id": "Q327954","name": "torch","type": "default"}],"uuid": "9947c549c6014a3ca831983275884051","width": 3342}
Example command line command:
das-element-cli ingest --library /mnt/library/das-element.lib --mapping "copy & rename" --path /some/file/path.1001-1099#.exr --category Q235544 --tags Q3196,foo,bar
517def predict(path, model=None, top=2, filmstrip_frames=36): 518 ''' 519 Predict the category for a give file path. 520 521 The give path can be a file or a directory. 522 If a directory is provided, all sub-directories will be searched for files and sequences. 523 524 525 **Args**: 526 527 > - **model** (str): [optional] *Define a custom model file path (.wit)* 528 > - **filmstrip_frames** (int): [optional] *Number of frames to validated for a movie file or sequence. The higher the number, the better the result might be, but it also takes longer* 529 > - **top** (int): [optional] *Return the top X predictions* 530 531 532 **Returns**: 533 > - Dict[str, List[Dict]]: *Key is the file path. The value a list of predicted categories* 534 535 536 **Example result**: 537 `{"/some/file/path.1001-1099#.exr": [{"tag": "flame", "description": "visible, gaseous part of a fire", "id": "Q235544", "value": "Q235544", "parents": [{"description": "rapid oxidation of a material; phenomenon that emits light and heat", "id": "Q3196", "name": "fire", "synonyms": [{"language": "en", "value": "fire"}, {"language": "en", "value": "fires"}}]}]}` 538 539 540 **Example command line command**: 541 `das-element-cli predict --top=2 /some/file/path` 542 543 ''' 544 command = ['predict', '--top', top, '--filmstrip_frames', filmstrip_frames] 545 546 if model: 547 command += ['--model', as_quoted_string(model)] 548 549 command += [path] 550 return execute_command(command)
Predict the category for a give file path.
The give path can be a file or a directory.
If a directory is provided, all sub-directories will be searched for files and sequences.
Args:
- model (str): [optional] Define a custom model file path (.wit)
- filmstrip_frames (int): [optional] Number of frames to validated for a movie file or sequence. The higher the number, the better the result might be, but it also takes longer
- top (int): [optional] Return the top X predictions
Returns:
- Dict[str, List[Dict]]: Key is the file path. The value a list of predicted categories
Example result:
{"/some/file/path.1001-1099#.exr": [{"tag": "flame", "description": "visible, gaseous part of a fire", "id": "Q235544", "value": "Q235544", "parents": [{"description": "rapid oxidation of a material; phenomenon that emits light and heat", "id": "Q3196", "name": "fire", "synonyms": [{"language": "en", "value": "fire"}, {"language": "en", "value": "fires"}}]}]}
Example command line command:
das-element-cli predict --top=2 /some/file/path
553def get_paths_from_disk(path, as_sequence=True): 554 ''' 555 Recursivly searches for files and sequences in a given directory. Since version 1.2.5 556 557 The give path can be a file or a directory. 558 If a directory is provided, all sub-directories will be searched for files and sequences. 559 560 561 **Args**: 562 563 > - **as_sequence / as_single_files** (bool): [optional] defines if files with a sequential naming should be detected as a file sequence or individual files 564 565 566 **Returns**: 567 > - List[str]: *List of file paths found in the give directory* 568 569 570 **Example result**: 571 `["/some/file/path.1001-1099#.exr", "/other/path.mov"]` 572 573 574 **Example command line command**: 575 `das-element-cli get-paths-from-disk --as_sequence /some/file/path` 576 577 ''' 578 command = ['get-paths-from-disk'] 579 580 if as_sequence: 581 command += ['--as_sequence'] 582 else: 583 command += ['--as_single_files'] 584 585 command += [path] 586 return execute_command(command)
Recursivly searches for files and sequences in a given directory. Since version 1.2.5
The give path can be a file or a directory.
If a directory is provided, all sub-directories will be searched for files and sequences.
Args:
- as_sequence / as_single_files (bool): [optional] defines if files with a sequential naming should be detected as a file sequence or individual files
Returns:
- List[str]: List of file paths found in the give directory
Example result:
["/some/file/path.1001-1099#.exr", "/other/path.mov"]
Example command line command:
das-element-cli get-paths-from-disk --as_sequence /some/file/path