rest_api_client
This module regroup the client-side methods of the REST API.
_ply_face_to_array(data)
Link
Convert the PlyData
'face' data into an XYZ array of triangle coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
PlyData
|
The |
required |
Returns:
Type | Description |
---|---|
list
|
The XYZ array of triangle coordinates, returned as a list to be JSON serializable. |
Source code in plantdb/rest_api_client.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
|
_ply_vertex_to_array(data)
Link
Convert the PlyData
'vertex' data into an XYZ array of vertex coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
PlyData
|
The |
required |
Returns:
Type | Description |
---|---|
list
|
The XYZ array of vertex coordinates, returned as a list to be JSON serializable. |
Source code in plantdb/rest_api_client.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
|
archive_url(dataset_name, **kwargs)
Link
Generates a formatted URL for accessing the archive of a specific dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
Name of the dataset to access in the archive. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The hostname or IP address of the PlantDB REST API server. Defaults to |
port |
str or int
|
The port number of the PlantDB REST API server. Defaults to |
Returns:
Type | Description |
---|---|
str
|
Fully constructed URL for accessing the specified dataset archive. |
Examples:
>>> from plantdb.rest_api_client import archive_url
>>> archive_url('arabidopsis000')
'http://127.0.0.1:5000/archive/arabidopsis000'
>>> archive_url('../arabidopsis000')
'http://127.0.0.1:5000/archive/arabidopsis000'
>>> archive_url('arabidopsis+000')
ValueError: Invalid dataset name: 'arabidopsis+000'. Dataset names must be alphanumeric and can include underscores or dashes.
Source code in plantdb/rest_api_client.py
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 |
|
base_url(host=REST_API_URL, port=REST_API_PORT)
Link
Generates the URL for the PlantDB REST API using the specified host and port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host
|
str
|
The hostname or IP address of the PlantDB REST API server. Defaults to |
REST_API_URL
|
port
|
str or int
|
The port number of the PlantDB REST API server. Defaults to |
REST_API_PORT
|
Returns:
Type | Description |
---|---|
str
|
A properly formatted URL of the PlantDB REST API. |
Examples:
>>> from plantdb.rest_api_client import base_url
>>> base_url()
'http://127.0.0.1:5000'
Source code in plantdb/rest_api_client.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
download_scan_archive(dataset_name, out_dir=None, **kwargs)
Link
Downloads a scan archive file from a defined dataset based on the specified API parameters.
This function fetches a scan archive in stream mode from a remote API. The archive is expected to be in the form of a binary content stream. The success of the operation is determined by the HTTP response received from the API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the dataset from which the scan archive file is to be downloaded. |
required |
out_dir
|
str or Path
|
A path to the directory where to save the archive. |
None
|
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
timeout |
int
|
A timeout, in seconds, to suceed the download request. Defaults to |
Returns:
Type | Description |
---|---|
BytesIO or str
|
A |
Examples:
>>> from plantdb.rest_api_client import download_scan_archive
>>> download_scan_archive("arabidopsis000", out_dir='/tmp', host="127.0.0.1", port="5000")
Source code in plantdb/rest_api_client.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 |
|
get_angles_and_internodes_data(dataset_name, **api_kwargs)
Link
Return a dictionary with 'angles' and 'internodes' data for selected dataset, if it exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the dataset. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
Returns:
Type | Description |
---|---|
dict
|
A dictionary with 'angles' and 'internodes' data. |
Source code in plantdb/rest_api_client.py
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 |
|
get_images_from_task(dataset_name, task_name='images', size='orig', **api_kwargs)
Link
Get the list of images data for a given dataset and task name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the dataset to retrieve the images for. |
required |
task_name
|
str
|
The name of the task to retrieve the images from. Defaults to 'images'. |
'images'
|
size
|
(orig, large, thumb)
|
If an integer, use it as the size of the cached image to create and return.
Else, should be a string, defaulting to |
'orig'
|
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
Returns:
Type | Description |
---|---|
list of PIL.Image
|
The list of PIL.Image from the PlantDB REST API. |
Examples:
>>> from plantdb.rest_api_client import get_images_from_task
>>> images = get_images_from_task('real_plant', host='127.0.0.1', port='5000')
>>> print(len(images))
60
>>> img1 = images[0]
>>> print(img1.size)
(1440, 1080)
Source code in plantdb/rest_api_client.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
get_reconstruction_config(dataset_name, cfg_fname='pipeline.toml', **api_kwargs)
Link
Return the reconstruction configuration for selected dataset, if it exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the dataset. |
required |
cfg_fname
|
str
|
The name of the configuration file. |
'pipeline.toml'
|
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
Returns:
Type | Description |
---|---|
dict
|
The configuration dictionary. |
Source code in plantdb/rest_api_client.py
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 |
|
get_scan_config(dataset_name, cfg_fname='scan.toml', **api_kwargs)
Link
Return the scan configuration for selected dataset, if it exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the dataset. |
required |
cfg_fname
|
str
|
The name of the configuration file. |
'scan.toml'
|
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
Returns:
Type | Description |
---|---|
dict
|
The configuration dictionary. |
Source code in plantdb/rest_api_client.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 |
|
get_scan_data(scan_id, host=REST_API_URL, port=REST_API_PORT)
Link
Retrieve the data dictionary for a given scan dataset from the PlantDB REST API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan_id
|
str
|
The name of the scan dataset to be retrieved. |
required |
host
|
str
|
The IP address of the PlantDB REST API. Defaults to |
REST_API_URL
|
port
|
str or int
|
The port of the PlantDB REST API. Defaults to |
REST_API_PORT
|
Returns:
Type | Description |
---|---|
dict
|
The data dictionary for the given scan dataset. |
Examples:
>>> from plantdb.rest_api_client import get_scan_data
>>> # This example requires the PlantDB REST API to be active (`fsdb_rest_api --test` from plantdb library)
>>> scan_data = get_scan_data('real_plant')
>>> print(scan_data['id'])
real_plant
>>> print(scan_data['hasColmap'])
False
Source code in plantdb/rest_api_client.py
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 |
|
get_scan_image(scan_id, fileset_id, file_id, size='orig', host=REST_API_URL, port=REST_API_PORT)
Link
Get the image for a scan dataset and task fileset served by the PlantDB REST API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan_id
|
str
|
The name of the scan dataset to be retrieved. |
required |
fileset_id
|
str
|
The name of the fileset containing the image to be retrieved. |
required |
file_id
|
str
|
The name of the image file to be retrieved. |
required |
size
|
(orig, large, thumb)
|
If an integer, use it as the size of the cached image to create and return.
Else, should be a string, defaulting to |
'orig'
|
host
|
str
|
The IP address of the PlantDB REST API. Defaults to |
REST_API_URL
|
port
|
str or int
|
The port of the PlantDB REST API. Defaults to |
REST_API_PORT
|
Returns:
Type | Description |
---|---|
Response
|
The URL to an image of a scan dataset and task fileset. |
Source code in plantdb/rest_api_client.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
|
get_scans_info(host=REST_API_URL, port=REST_API_PORT)
Link
Retrieve the information dictionary for all scans from the PlantDB REST API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host
|
str
|
The IP address of the PlantDB REST API. Defaults to |
REST_API_URL
|
port
|
str or int
|
The port of the PlantDB REST API. Defaults to |
REST_API_PORT
|
Returns:
Type | Description |
---|---|
dict
|
The scans information dictionary. |
Examples:
>>> from plantdb.rest_api_client import get_scans_info
>>> # This example requires the PlantDB REST API to be active (`fsdb_rest_api --test` from plantdb library)
>>> get_scans_info()
Source code in plantdb/rest_api_client.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
get_task_data(dataset_name, task, filename=None, api_data=None, **api_kwargs)
Link
Get the data corresponding to a dataset/task/filename
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the dataset. |
required |
task
|
str
|
The name of the task. |
required |
filename
|
str
|
The name of the file to load.
If not specified defaults to the main file returned by the task as defined in |
None
|
api_data
|
dict
|
The dictionary of information for the dataset as returned by the REST API. If not specified, fetch it from the REST API. |
None
|
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
Returns:
Type | Description |
---|---|
any
|
The parsed data. |
See Also
plantdb.rest_api.filesUri_task_mapping plantdb.rest_api_client.parse_task_requests_data
Source code in plantdb/rest_api_client.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
|
get_tasks_fileset_from_api(dataset_name, host=REST_API_URL, port=REST_API_PORT)
Link
Get the task name to fileset name mapping dictionary from the REST API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the dataset to retrieve the mapping for. |
required |
host
|
str
|
The IP address of the PlantDB REST API. Defaults to |
REST_API_URL
|
port
|
str or int
|
The port of the PlantDB REST API. Defaults to |
REST_API_PORT
|
Returns:
Type | Description |
---|---|
dict
|
The mapping of the task name to fileset name. |
Source code in plantdb/rest_api_client.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
get_toml_file(dataset_name, file_path, **api_kwargs)
Link
Return a loaded TOML file for selected dataset, if it exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the dataset. |
required |
file_path
|
str
|
The path to the TOML file. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
Returns:
Type | Description |
---|---|
dict
|
The configuration dictionary. |
Source code in plantdb/rest_api_client.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 |
|
list_scan_names(host=REST_API_URL, port=REST_API_PORT)
Link
List the names of the scan datasets served by the PlantDB REST API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host
|
str
|
The IP address of the PlantDB REST API. Defaults to |
REST_API_URL
|
port
|
str or int
|
The port of the PlantDB REST API. Defaults to |
REST_API_PORT
|
Returns:
Type | Description |
---|---|
list
|
The list of scan dataset names served by the PlantDB REST API. |
Examples:
>>> from plantdb.rest_api_client import list_scan_names
>>> # This example requires the PlantDB REST API to be active (`fsdb_rest_api --test` from plantdb library)
>>> print(list_scan_names())
['arabidopsis000', 'real_plant', 'real_plant_analyzed', 'virtual_plant', 'virtual_plant_analyzed']
Source code in plantdb/rest_api_client.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
list_task_images_uri(dataset_name, task_name='images', size='orig', **api_kwargs)
Link
Get the list of images URI for a given dataset and task name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the dataset to retrieve the images for. |
required |
task_name
|
str
|
The name of the task to retrieve the images from. Defaults to 'images'. |
'images'
|
size
|
(orig, large, thumb)
|
If an integer, use it as the size of the cached image to create and return.
Else, should be a string, defaulting to |
'orig'
|
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
Returns:
Type | Description |
---|---|
list of str
|
The list of image URI strings for the PlantDB REST API. |
Source code in plantdb/rest_api_client.py
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 |
|
parse_requests_json(data)
Link
Parse a requests content, should be from a AnglesAndInternodes task source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
buffer
|
The data source from a requests content. |
required |
Returns:
Type | Description |
---|---|
dict
|
The full angles and internodes dictionary with 'angles', 'internodes', '' & '' entries. |
Source code in plantdb/rest_api_client.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
|
parse_requests_mesh(data)
Link
Parse a requests content, should be from a TriangleMesh task source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
buffer
|
The data source from a requests content. |
required |
Returns:
Type | Description |
---|---|
dict
|
The parsed triangular mesh with two entries: 'vertices' for vertex coordinates and 'triangles' for triangle coordinates. |
Source code in plantdb/rest_api_client.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
|
parse_requests_pcd(data)
Link
Parse a requests content, should be from a PointCloud task source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
buffer
|
The data source from a requests content. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The parsed pointcloud with vertex coordinates sorted as XYZ. |
Source code in plantdb/rest_api_client.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
|
parse_requests_skeleton(data)
Link
Parse a requests content, should be from a CurveSkeleton task source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
buffer
|
The data source from a requests content. |
required |
Returns:
Type | Description |
---|---|
dict
|
The parsed skeleton with two entries: 'points' for points coordinates and 'lines' joining them. |
Source code in plantdb/rest_api_client.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
|
parse_requests_tree(data)
Link
Parse a requests content, should be from a TreeGraph task source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
buffer
|
The data source from a requests content. |
required |
Returns:
Type | Description |
---|---|
Graph
|
The loaded (tree) graph object. |
Source code in plantdb/rest_api_client.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
parse_scans_info(host=REST_API_URL, port=REST_API_PORT)
Link
Parse the information dictionary for all scans served by the PlantDB REST API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host
|
str
|
The IP address of the PlantDB REST API. Defaults to |
REST_API_URL
|
port
|
str or int
|
The port of the PlantDB REST API. Defaults to |
REST_API_PORT
|
Returns:
Type | Description |
---|---|
dict
|
The scan-id (dataset name) indexed information dictionary. |
Examples:
>>> from plantdb.rest_api_client import parse_scans_info
>>> # This example requires the PlantDB REST API to be active (`fsdb_rest_api --test` from plantdb library)
>>> scan_dict = parse_scans_info()
>>> print(sorted(scan_dict.keys()))
['arabidopsis000', 'real_plant', 'real_plant_analyzed', 'virtual_plant', 'virtual_plant_analyzed']
Source code in plantdb/rest_api_client.py
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 |
|
parse_task_requests_data(task, data, extension=None)
Link
The task data parser, behave according to the source and default to JSON parser.
Source code in plantdb/rest_api_client.py
663 664 665 666 667 668 669 |
|
refresh(dataset_name=None, **kwargs)
Link
Refreshes the database, potentialy only for a specified dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str or None
|
The name of the dataset to trigger a refresh.
If |
None
|
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
timeout |
int
|
A timeout, in seconds, to suceed the refresh request. Defaults to |
Returns:
Type | Description |
---|---|
dict
|
Parsed JSON response from the refresh API if the request is successful. |
Raises:
Type | Description |
---|---|
HTTPError
|
If the request fails or the response status is not successful. |
Examples:
>>> from plantdb.rest_api_client import refresh
>>> refresh("arabidopsis000", host="127.0.0.1", port="5000")
Source code in plantdb/rest_api_client.py
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 |
|
refresh_url(dataset_name=None, **kwargs)
Link
Generates a formatted URL for refreshing a specific dataset or the entire database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str or None
|
The name of the dataset for which the refresh URL needs to be generated.
If not provided, the refresh URL for the entire server is returned instead.
Defaults to |
None
|
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The hostname or IP address of the PlantDB REST API server. Defaults to |
port |
str or int
|
The port number of the PlantDB REST API server. Defaults to |
Returns:
Type | Description |
---|---|
str
|
A correctly formatted URL for refreshing the specified dataset or the entire PlantDB REST API server. |
Source code in plantdb/rest_api_client.py
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 |
|
sanitize_name(name)
Link
Sanitizes and validates the provided name.
The function ensures that the input string adheres to predefined naming rules by:
- stripping leading/trailing spaces,
- isolating the last segment after splitting by slashes,
- validating the name against an alphanumeric pattern
with optional underscores (
_
), dashes (-
), or periods (.
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name to sanitize and validate. |
required |
Returns:
Type | Description |
---|---|
str
|
Sanitized name that conforms to the rules. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided name contains invalid characters or does not meet the naming rules. |
Source code in plantdb/rest_api_client.py
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 |
|
scan_image_url(scan_id, fileset_id, file_id, size='orig', host=REST_API_URL, port=REST_API_PORT)
Link
Get the URL to the image for a scan dataset and task fileset served by the PlantDB REST API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan_id
|
str
|
The name of the scan dataset to be retrieved. |
required |
fileset_id
|
str
|
The name of the fileset containing the image to be retrieved. |
required |
file_id
|
str
|
The name of the image file to be retrieved. |
required |
size
|
(orig, large, thumb)
|
If an integer, use it as the size of the cached image to create and return.
Else, should be a string, defaulting to |
'orig'
|
host
|
str
|
The IP address of the PlantDB REST API. Defaults to |
REST_API_URL
|
port
|
str or int
|
The port of the PlantDB REST API. Defaults to |
REST_API_PORT
|
Returns:
Type | Description |
---|---|
str
|
The URL to an image of a scan dataset and task fileset. |
Source code in plantdb/rest_api_client.py
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 |
|
scan_preview_image_url(scan_id, host=REST_API_URL, port=REST_API_PORT, size='thumb')
Link
Get the URL to the preview image for a scan dataset served by the PlantDB REST API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan_id
|
str
|
The name of the scan dataset to be retrieved. |
required |
host
|
str
|
The IP address of the PlantDB REST API. Defaults to |
REST_API_URL
|
port
|
str or int
|
The port of the PlantDB REST API. Defaults to |
REST_API_PORT
|
size
|
(orig, large, thumb)
|
If an integer, use it as the size of the cached image to create and return.
Else, should be a string, defaulting to |
'orig'
|
Returns:
Type | Description |
---|---|
str
|
The URL to the preview image for a scan dataset. |
Source code in plantdb/rest_api_client.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
|
test_host_port_availability(url)
Link
Verifies the connectivity to a given host and port from a URL-like string.
This function parses a URL string into host and port components, attempts to establish a socket connection to check its availability, and raises appropriate exceptions on failure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
A string specifying the host and port in the format 'host:port'. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the input URL is not in the correct format 'host:port'. |
ConnectionError
|
If the specified host and port cannot be connected, indicating that the port might be closed or unavailable. |
RuntimeError
|
If an unexpected error occurs during the verification process. |
Examples:
>>> from plantdb.rest_api_client import test_host_port_availability
>>> test_host_port_availability('127.0.0.1:5000')
Source code in plantdb/rest_api_client.py
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 |
|
upload_dataset_file(scan_id, file_path, chunk_size=0, **kwargs)
Link
Uploads a file to the server using the DatasetFile POST endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
server_url
|
str
|
The base URL of the server hosting the REST API. |
required |
scan_id
|
str
|
The unique identifier of the scan associated with the file upload. |
required |
file_path
|
str
|
The path to the file to be uploaded. |
required |
chunk_size
|
int
|
The size of chunks (in bytes) to read and send, by default 0 (no chunking). |
0
|
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing the server's response. |
Examples:
>>> from plantdb.rest_api_client import upload_dataset_file
>>> upload_dataset_file('arabidopsis000', '/path/to/local/file.txt')
Source code in plantdb/rest_api_client.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 |
|
upload_scan_archive(dataset_name, path, **kwargs)
Link
Upload a scan archive file to a specified dataset on a server.
This function sends a POST request to upload a scan archive file to a particular dataset, utilizing the archive URL and optionally specified additional API-related request parameters. Ensures proper handling of file opening/closing procedures and response status checks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the target dataset for the archive upload. |
required |
path
|
str
|
The local file system path to the archive to be uploaded. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
host |
str
|
The IP address of the PlantDB REST API. Defaults to |
port |
str or int
|
The port of the PlantDB REST API. Defaults to |
timeout |
int
|
A timeout, in seconds, to suceed the upload request. Defaults to |
Returns:
Type | Description |
---|---|
str
|
The time it took to upload the archive. |
Raises:
Type | Description |
---|---|
RequestException
|
If the HTTP request fails for any reason. |
HTTPError
|
If the request returns an unsuccessful HTTP status code. |
Examples:
>>> from plantdb.rest_api_client import upload_scan_archive
>>> upload_scan_archive("arabidopsis000", path='/tmp/arabidopsis000.zip', host="127.0.0.1", port="5002")
Source code in plantdb/rest_api_client.py
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 |
|