Skip to content

Commit

Permalink
update kv_operation.py route to bazel-out and update readme (#137)
Browse files Browse the repository at this point in the history
* update kv_operation.py route to bazel-out and update readme

* update readme

* Update README.md

* Update README.md

---------

Co-authored-by: cjcchen <[email protected]>
  • Loading branch information
NoBugInMyCode and cjcchen authored Mar 9, 2024
1 parent c3953f9 commit ca0ac0f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
39 changes: 27 additions & 12 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -29,4 +29,19 @@ from kv_operation import set_value, get_value
set_value("test", "111222")
get_value("test")
```
```

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")
```




3 changes: 2 additions & 1 deletion api/kv_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ca0ac0f

Please sign in to comment.