Skip to content

fluid-cloudnative/fluid-client-python

Repository files navigation

Fluid Python SDK

Fluid SDK in Python

This Python package is automatically generated by the OpenAPI Generator project:

Requirements.

  • Python >= 3.7

Installation & Usage

pip install

pip install fluid-pysdk

(you may need to run pip with root permission: sudo pip install fluid-pysdk)

Getting Started

Fluid Python SDK provides two types of "client SDK" for users with different expertises and preference.

  • fluid.FluidClient (the recommended one) provides a more Pythonic interface with polished user experience.
  • fluid.FluidK8sClient provides a low-level YAML-style interface for those who have rich experience in Kubernetes.

The following shows the same code example using two types of client SDK. The example simply creates a dataset and get its status.

with fluid.FluidClient

import logging
import sys

from fluid import FluidClient, ClientConfig

logger = logging.getLogger("fluidsdk")
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
logger.addHandler(stream_handler)
logger.setLevel(logging.INFO)

def main():
    name = "demo"
    namespace = "default"
    
    client_config = ClientConfig(namespace=namespace)
    fluid_client = FluidClient(client_config)
    
    
    try:
        fluid_client.create_dataset(name, "hbase", "https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/", "/")
    except Exception as e:
       raise RuntimeError(f"Failed to create dataset: {e}") 
    
    logger.info(f"Dataset \"{namespace}/{name}\" created successfully")
    
    try:
        dataset = fluid_client.get_dataset(name, namespace)
    except Exception as e:
        raise RuntimeError(f"Error when getting dataset \"{namespace}/{name}\": {e}")
    else:
        logger.info(f"Dataset \"{namespace}/{name}\"'s phase is: {dataset.report_status(status_type='binding_status')['phase']}")

if __name__ == '__main__':
    main()

with fluid.FluidK8sClient

import logging
import sys

from kubernetes import client

from fluid import FluidK8sClient
from fluid import constants
from fluid import models

logger = logging.getLogger("fluidsdk")
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
logger.addHandler(stream_handler)
logger.setLevel(logging.INFO)


# Output detailed debug message for fluidsdk
# logger.setLevel(logging.DEBUG)

def main():
    fluid_client = FluidK8sClient()

    name = "demo"
    namespace = "default"

    dataset = models.Dataset(
        api_version=constants.API_VERSION,
        kind=constants.DATASET_KIND,
        metadata=client.V1ObjectMeta(
            name=name,
            namespace=namespace
        ),
        spec=models.DatasetSpec(
            mounts=[
                models.Mount(
                    mount_point="https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/",
                    name="hbase",
                    path="/",
                )
            ]
        )
    )

    try:
        fluid_client.create_dataset(dataset)
    except Exception as e:
        raise RuntimeError(f"Failed to create dataset: {e}")

    logger.info(f"Dataset \"{dataset.metadata.namespace}/{dataset.metadata.name}\" created successfully")

    try:
        dataset = fluid_client.get_dataset(name, namespace)
    except Exception as e:
        raise RuntimeError(f"Error when getting dataset \"{namespace}/{name}\": {e}")

    assert type(dataset) == models.Dataset
    logger.info(f"Dataset \"{namespace}/{name}\"'s phase is: {dataset.status.phase}")


if __name__ == '__main__':
    main()

Versioning

Fluid Python SDK's version ALWAYS follows the Fluid's version as long as they share the fully compatible APIs. For example, if a released version of Fluid is v1.0.1, Fluid Python SDK with version prefix "v1.0.1" is guaranteed to have same APIs as the released Fluid version.

Fluid Python SDK may have "post" version that updates the inner code but keep the APIs untouched (e.g. hotfixes). For example, "v1.0.1.post1" is a post version of "v1.0.1" which includes the latest changes.

Documentation For Models

Documentation For Authorization

All endpoints do not require authorization.

Author