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 git+https://github.com/fluid-cloudnative/fluid-client-python.git

(you may need to run pip with root permission: sudo pip install git+https://github.com/fluid-cloudnative/fluid-client-python.git)

Then import the package:

import fluid

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Then import the package:

import fluid

Getting Started

Please follow the installation procedure and then run the following:

The following is a code sample which creates a dataset and get its status.

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.bit.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()

Documentation For Models

Documentation For Authorization

All endpoints do not require authorization.

Author