@@ -14,11 +14,6 @@ pip install git+https://github.com/fluid-cloudnative/fluid-client-python.git
14
14
```
15
15
(you may need to run ` pip ` with root permission: ` sudo pip install git+https://github.com/fluid-cloudnative/fluid-client-python.git ` )
16
16
17
- Then import the package:
18
- ``` python
19
- import fluid
20
- ```
21
-
22
17
### Setuptools
23
18
24
19
Install via [ Setuptools] ( http://pypi.python.org/pypi/setuptools ) .
@@ -28,16 +23,55 @@ python setup.py install --user
28
23
```
29
24
(or ` sudo python setup.py install ` to install the package for all users)
30
25
31
- Then import the package:
26
+ ## Getting Started
27
+
28
+ Fluid Python SDK provides two types of "client SDK" for users with different expertises and preference.
29
+ - ` fluid.FluidClient ` (the recommended one) provides a more Pythonic interface with polished user experience.
30
+ - ` fluid.FluidK8sClient ` provides a low-level YAML-style interface for those who have rich experience in Kubernetes.
31
+
32
+ The following shows the same code example using two types of client SDK. The example simply creates a dataset and get its status.
33
+
34
+ ### with ` fluid.FluidClient `
35
+
32
36
``` python
33
- import fluid
34
- ```
37
+ import logging
38
+ import sys
35
39
36
- ## Getting Started
40
+ from fluid import FluidClient, ClientConfig
37
41
38
- Please follow the [ installation procedure] ( #installation--usage ) and then run the following:
42
+ logger = logging.getLogger(" fluidsdk" )
43
+ stream_handler = logging.StreamHandler(sys.stdout)
44
+ stream_handler.setFormatter(logging.Formatter(' %(asctime)s - %(name)s - %(levelname)s - %(message)s ' ))
45
+ logger.addHandler(stream_handler)
46
+ logger.setLevel(logging.INFO )
47
+
48
+ def main ():
49
+ name = " demo"
50
+ namespace = " default"
51
+
52
+ client_config = ClientConfig(namespace = namespace)
53
+ fluid_client = FluidClient(client_config)
54
+
55
+
56
+ try :
57
+ fluid_client.create_dataset(name, " hbase" , " https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/" , " /" )
58
+ except Exception as e:
59
+ raise RuntimeError (f " Failed to create dataset: { e} " )
60
+
61
+ logger.info(f " Dataset \" { namespace} / { name} \" created successfully " )
62
+
63
+ try :
64
+ dataset = fluid_client.get_dataset(name, namespace)
65
+ except Exception as e:
66
+ raise RuntimeError (f " Error when getting dataset \" { namespace} / { name} \" : { e} " )
67
+ else :
68
+ logger.info(f " Dataset \" { namespace} / { name} \" 's phase is: { dataset.report_status(status_type = ' binding_status' )[' phase' ]} " )
69
+
70
+ if __name__ == ' __main__' :
71
+ main()
72
+ ```
39
73
40
- The following is a code sample which creates a dataset and get its status.
74
+ ### with ` fluid.FluidK8sClient `
41
75
42
76
``` python
43
77
import logging
@@ -75,7 +109,7 @@ def main():
75
109
spec = models.DatasetSpec(
76
110
mounts = [
77
111
models.Mount(
78
- mount_point = " https://mirrors.bit .edu.cn/apache/hbase/stable/" ,
112
+ mount_point = " https://mirrors.tuna.tsinghua .edu.cn/apache/hbase/stable/" ,
79
113
name = " hbase" ,
80
114
path = " /" ,
81
115
)
0 commit comments