@@ -14,11 +14,6 @@ pip install git+https://github.com/fluid-cloudnative/fluid-client-python.git
1414```
1515(you may need to run ` pip ` with root permission: ` sudo pip install git+https://github.com/fluid-cloudnative/fluid-client-python.git ` )
1616
17- Then import the package:
18- ``` python
19- import fluid
20- ```
21-
2217### Setuptools
2318
2419Install via [ Setuptools] ( http://pypi.python.org/pypi/setuptools ) .
@@ -28,16 +23,55 @@ python setup.py install --user
2823```
2924(or ` sudo python setup.py install ` to install the package for all users)
3025
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+
3236``` python
33- import fluid
34- ```
37+ import logging
38+ import sys
3539
36- ## Getting Started
40+ from fluid import FluidClient, ClientConfig
3741
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+ ```
3973
40- The following is a code sample which creates a dataset and get its status.
74+ ### with ` fluid.FluidK8sClient `
4175
4276``` python
4377import logging
@@ -75,7 +109,7 @@ def main():
75109 spec = models.DatasetSpec(
76110 mounts = [
77111 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/" ,
79113 name = " hbase" ,
80114 path = " /" ,
81115 )
0 commit comments