From ca0ac0f996d06bc08a862cbe90b647f43fcb8c98 Mon Sep 17 00:00:00 2001 From: Jiazhi Sun <123703679+NoBugInMyCode@users.noreply.github.com> Date: Fri, 8 Mar 2024 23:17:16 -0800 Subject: [PATCH] update kv_operation.py route to bazel-out and update readme (#137) * update kv_operation.py route to bazel-out and update readme * update readme * Update README.md * Update README.md --------- Co-authored-by: cjcchen --- api/README.md | 39 +++++++++++++++++++++++++++------------ api/kv_operation.py | 3 ++- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/api/README.md b/api/README.md index 437d3fc0f..e3d99ad14 100644 --- a/api/README.md +++ b/api/README.md @@ -1,23 +1,23 @@ # ResilientDB kv-Service Python API(Get and Set Command) ## Description -This API allows users to directly use kv-service of the ResilientDB in Python +This API allows users to use kv-service of the ResilientDB in Python directly. ## How to Run -1. Make sure you have installed bazel5.0 and pybind11 -2. cd to `incubator-resilientdb/api` folder -3. Run command `bazel build :pybind_kv_so` -4. From `kv_operation.py` import `get_value` and `set_value` function into your Python file to use it (Make sure to use same python version when run `bazel build` command and call the functions) +1. Make sure to run `./INSTALL.sh` in advance. +1. cd to `incubator-resilientdb/api` folder. +2. Run command `bazel build :pybind_kv_so`. +3. From `kv_operation.py`, import `get_value` and `set_value` functions into your Python file to use it (Make sure to use the same Python version when running `bazel build` command and calling the functions). ## Parameters ### `set_value`: -1. `key`: The key user want to store in key-value pair. Acceptable types are `str`, `int`, `float` -2. `value`: The `key`'s corresponding value in key-value pair. Acceptable types are `str`, `int`, `float` -3. `config_path`(optional): The absolute path to user's blockchain config file(ip addresses). If user does not specify this parameter, system will use main chain as default. Acceptable type is `str` -4. `return`: `True` if `value` has been set successfully, otherwise `value` has not been set successfully. +1. `key`: The key user wants to store in a key-value pair. Acceptable types are `str`, `int`, `float`. +2. `value`: The corresponding value to `key` in the key-value pair. Acceptable types are `str`, `int`, `float`. +3. config_path (optional): The path to the user's blockchain config file (IP addresses). If the user does not specify this parameter, the system will default to the address located in "ip.address.config." The acceptable type is `str`. +4. `return`: `True` if `value` has been set successfully; otherwise, `value` has not been set successfully. ### `get_value`: -1. `key`: The key user want to get in key-value pair. Acceptable types are `str`, `int`, `float` -2. `return`: `\n` if the corresponding value of `key` is empty, otherwise is corresponding value of `key` +1. `key`: The key user wants to get in a key-value pair. Acceptable types are `str`, `int`, `float`. +2. `return`: `\n` if the corresponding value of `key` is empty, otherwise is the corresponding value of `key`. ## Example @@ -29,4 +29,19 @@ from kv_operation import set_value, get_value set_value("test", "111222") get_value("test") -``` \ No newline at end of file +``` + +If having set up the environment parameter, "sys.path" can be ignorred. +``` +export PYTHON_PATH="/home/ubuntu/Desktop/incubator-resilientdb/api":PYTHON_PATH +``` +```angular2html +from kv_operation import set_value, get_value + +set_value("test", "111222") +get_value("test") +``` + + + + diff --git a/api/kv_operation.py b/api/kv_operation.py index 805a9b8a1..c100962eb 100644 --- a/api/kv_operation.py +++ b/api/kv_operation.py @@ -2,7 +2,8 @@ import sys current_file_path = os.path.abspath(__file__) current_dir = os.path.dirname(current_file_path) -new_path_dir = os.path.join(current_dir, "bazel-out", "k8-fastbuild", "bin") +parent_dir = os.path.dirname(current_dir) +new_path_dir = os.path.join(parent_dir, "bazel-out", "k8-fastbuild", "bin", "api") sys.path.insert(0, new_path_dir) import pybind_kv