|
1 | | -# Python APIs |
| 1 | +# Py APIs |
2 | 2 |
|
3 | | -Python APIs |
| 3 | +### faasr_get_file |
| 4 | + |
| 5 | +Usage: `faasr_get_file(server_name, remote_folder, remote_file, local_folder, local_file)` |
| 6 | + |
| 7 | +This function gets (i.e. downloads) a file from an S3 bucket to be used by the FaaSr function. |
| 8 | + |
| 9 | +`server_name` is a string with name of the S3 bucket to use; it must match a name declared in the workflow configuration JSON file. |
| 10 | +This is an optional argument; if not provided, the default S3 server specified as `DefaultDataStore` in the workflow configuration JSON file is used. |
| 11 | + |
| 12 | +`remote_folder` is string with the name of the remote folder where the file is to be downloaded from. This is an optional argument that defaults to `""` |
| 13 | + |
| 14 | +`remote_file` is a string with the name for the file to be downloaded from the S3 bucket. This is a required argument. |
| 15 | + |
| 16 | +`local_folder` is a string with the name of the local folder where the file to be downloaded is stored. This is an optional argument that defaults to `"."` |
| 17 | + |
| 18 | +`local_file` is a string with the name for the file downloaded from the S3 bucket. This is a required argument. |
| 19 | + |
| 20 | +Examples: |
| 21 | + |
| 22 | +```py |
| 23 | +faasr_get_file(remote_folder="myfolder", remote_file="myinput1.csv", local_file="input1.csv") |
| 24 | +faasr_get_file(server_name="My_Minio_Bucket", remote_file="myinput2.csv", local_file="input2.csv") |
| 25 | +``` |
| 26 | + |
| 27 | +### faasr_put_file |
| 28 | + |
| 29 | +Usage: `faasr_put_file(server_name, local_folder, local_file, remote_folder, remote_file)` |
| 30 | + |
| 31 | +This function puts (i.e. uploads) a file from the local FaaSr function to an S3 bucket. |
| 32 | + |
| 33 | +`server_name` is a string with name of the S3 bucket to use; it must match a name declared in the workflow configuration JSON file. |
| 34 | +This is an optional argument; if not provided, the default S3 server specified as `DefaultDataStore` in the workflow configuration JSON file is used. |
| 35 | + |
| 36 | +`local_folder` is a string with the name of the local folder where the file to be uploaded is stored. This is an optional argument that defaults to `"."` |
| 37 | + |
| 38 | +`local_file` is a string with the name for the file to be uploaded to the S3 bucket. This is a required argument. |
| 39 | + |
| 40 | +`remote_folder` is string with the name of the remote folder where the file is to be uploaded to. This is an optional argument that defaults to `""` |
| 41 | + |
| 42 | +`remote_file` is a string with the name for the file to be uploaded to the S3 bucket. This is a required argument. |
| 43 | + |
| 44 | + |
| 45 | +Examples: |
| 46 | + |
| 47 | +```py |
| 48 | +faasr_put_file(local_file="output.csv", remote_folder="myfolder", remote_file="myoutput.csv") |
| 49 | +faasr_get_file(server_name="My_Minio_Bucket", local_file="output.csv", remote_file="myoutput.csv") |
| 50 | +``` |
| 51 | + |
| 52 | +### faasr_get_folder_list |
| 53 | + |
| 54 | +Usage: `folderlist <- faasr_get_folder_list(server_name, faasr_prefix)` |
| 55 | + |
| 56 | +This function returns a list with the contents of a folder in the S3 bucket. |
| 57 | + |
| 58 | +`server_name` is a string with name of the S3 bucket to use; it must match a name declared in the workflow configuration JSON file. |
| 59 | +This is an optional argument; if not provided, the default S3 server specified as `DefaultDataStore` in the workflow configuration JSON file is used. |
| 60 | + |
| 61 | +`faasr_prefix` is a string with the prefix of the folder in the S3 bucket. This is an optional argument that defaults to `""` |
| 62 | + |
| 63 | +Examples: |
| 64 | + |
| 65 | +```py |
| 66 | +mylist1 <- faasr_get_folder_list(server_name="My_Minio_Bucket", faasr_prefix="myfolder") |
| 67 | +mylist2 <- faasr_get_folder_list(server_name="My_Minio_Bucket", faasr_prefix="myfolder/mysubfolder") |
| 68 | +``` |
| 69 | + |
| 70 | +### faasr_delete_file |
| 71 | + |
| 72 | +Usage: `faasr_delete_file(server_name, remote_folder, remote_file)` |
| 73 | + |
| 74 | +This function deletes a file from the S3 bucket. |
| 75 | + |
| 76 | +`server_name` is a string with name of the S3 bucket to use; it must match a name declared in the workflow configuration JSON file. |
| 77 | +This is an optional argument; if not provided, the default S3 server specified as `DefaultDataStore` in the workflow configuration JSON file is used. |
| 78 | + |
| 79 | +`remote_folder` is string with the name of the remote folder where the file is to be deleted from. This is an optional argument that defaults to `""` |
| 80 | + |
| 81 | +`remote_file` is a string with the name for the file to be deleted from the S3 bucket. This is a required argument. |
| 82 | + |
| 83 | +Examples: |
| 84 | + |
| 85 | +```py |
| 86 | +faasr_delete_file(remote_folder="myfolder", remote_file="myoutput.csv") |
| 87 | +faasr_delete_file(server_name="My_Minio_Bucket", remote_file="myoutput.csv") |
| 88 | +``` |
| 89 | + |
| 90 | +### faasr_log |
| 91 | + |
| 92 | +Usage: `faasr_log(log_message)` |
| 93 | + |
| 94 | +This function writes a log message to a file in the S3 bucket, to help with debugging. |
| 95 | +The default S3 server for logs is `DefaultDataStore` as specified in the workflow configuration JSON file. |
| 96 | +This default can be overridden with `LoggingDataStore` in the workflow configuration JSON file. |
| 97 | + |
| 98 | +`log_message` is a string with the message to be logged. |
| 99 | + |
| 100 | +Example: |
| 101 | + |
| 102 | +```py |
| 103 | +log_msg = f"Function compute_sum finished; output written to {folder}/{output} in default S3 bucket" |
| 104 | +faasr_log(log_msg) |
| 105 | +``` |
| 106 | + |
| 107 | +### faasr_rank |
| 108 | + |
| 109 | +Usage: `faasr_rank()` |
| 110 | + |
| 111 | +Only applicable for workflows with functions that are triggered for concurrent execution using rank. |
| 112 | +This returns this function's invocation rank as a dictionary with two keys: |
| 113 | + |
| 114 | +`max_rank` - an integer that determines to the maximum number of invocations (e.g. N) |
| 115 | +`rank` - an integer that determines this function's invocation rank (e.g. a number ranging from 1 to N) |
| 116 | + |
| 117 | +Example: |
| 118 | + |
| 119 | +In a workflow, suppose you have declared that a function `start` invokes a successor function `compute` with rank N=10, where each instance of `compute` works to produce an output file `myoutput_i.csv`, where i is a number from 1 to 10. |
| 120 | + |
| 121 | +At runtime, `start` invokes 10 instances of `compute`; `faasr_rank()` determines the value of `i` for each instance of `compute`, which can be used to construct the file name: |
| 122 | + |
| 123 | +```py |
| 124 | +rank_list = faasr_rank() |
| 125 | +my_rank = rank_list["rank"] |
| 126 | +max_rank = rank_list["max_rank"] |
| 127 | +local_file = f"myinput_{my_rank}.csv" |
| 128 | +df.to_csv(local_file, index=False) |
| 129 | +``` |
| 130 | + |
| 131 | +### faasr_invocation_id |
| 132 | + |
| 133 | +Usage: `faasr_invocation_id()` |
| 134 | + |
| 135 | +Returns this action's invocation ID. |
| 136 | + |
| 137 | +Example: |
| 138 | + |
| 139 | +```py |
| 140 | +invocation_id = faasr_invocation_id() |
| 141 | +print(invocation_id) |
| 142 | +``` |
0 commit comments