Alluxio
ProductsLanguageHome
  • Alluxio概览
  • 用户指南
    • 快速上手指南
    • 架构
    • FAQ
    • 作业服务器
    • 应用场景
  • 核心功能
    • 缓存
    • 统一命名空间
  • 部署 Alluxio
    • 在Kubernetes上部署Alluxio
    • 本地运行Alluxio
    • 在集群上独立运行Alluxio
    • 在Docker上运行Alluxio
    • 在具有HA的群集上部署Alluxio
    • 使用Docker部署AlluxioFuse加速深度学习训练(试验)
    • 基本要求
  • 云源生
    • Tencent EMR
  • 计算应用
    • Apache Spark
    • Presto
    • Spark on Kubernetes
    • Apache Flink
    • Apache Hadoop MapReduce
    • Presto on Iceberg (Experimental)
    • Trino
    • Apache Hive
    • 深度学习框架
    • Tensorflow
  • 底层存储系统
    • Alluxio集成Amazon AWS S3作为底层存储
    • Alluxio集成GCS作为底层存储
    • Alluxio集成Azure Blob Store作为底层存储
    • Azure Data Lake Storage Gen2
    • Azure 数据湖存储
    • Alluxio集成HDFS作为底层存储
    • Alluxio集成COS作为底层存储
    • Alluxio集成COSN作为底层存储
    • Alluxio集成Ceph Object Storage作为底层存储
    • Alluxio集成NFS作为底层存储
    • Alluxio集成Kodo作为底层存储
    • Alluxio集成Swift作为底层存储
    • Alluxio集成WEB作为底层存储
    • Alluxio集成Minio作为底层存储
    • 阿里云对象存储服务
    • Alluxio集成Ozone作为底层存储
    • Alluxio集成CephFS作为底层存储
  • 安全设置
    • 安全性
  • 运维指南
    • 配置项设置
    • 命令行接口
    • 管理员命令行接口
    • Web界面
    • 日志
    • 度量指标系统
    • 远程记录日志
  • 管理
    • 升级
    • 异常诊断与调试
  • APIs
    • Filesystem API
    • S3 Client
    • POSIX API
    • REST API
    • Python Client
    • 兼容Hadoop的Java
    • Go 客户端
  • 开发者资源
    • 编译Alluxio源代码
    • 开发指南
    • 代码规范
    • 如何开发单元测试
    • 文档规范
  • 参考
    • 配置项列表
    • List of Metrics
  • REST API
    • Master REST API
    • Worker REST API
    • Proxy REST API
    • Job REST API
  • Javadoc
Powered by GitBook
On this page
  • Python Client
  • Alluxio代理依赖
  • 安装python客户端库
  • 使用示例
  1. APIs

Python Client

Last updated 7 months ago

Python Client

Alluxio 有一个 ,这个客户端提供了 来和 Alluxio 交互。它提供了一个和 Alluxio Java API 类似的 API。查看这篇来了解有关所有可用方法的详细文档。通过来了解如何在 Alluxio 上执行基本的文件系统操作。

Alluxio代理依赖

这个Python客户端通过由Alluxio代理提供的REST API来和Alluxio相互交流。 这个代理服务器是一个独立的服务器,可以通过${ALLUXIO_HOME}/bin/alluxio-start.sh proxy来开启它和通过命令${ALLUXIO_HOME}/bin/alluxio-stop.sh proxy来关闭它。默认情况下,可以通过端口39999来使用REST API。 使用HTTP代理服务器有性能上的影响。特别的是,使用这个代理服务器需要一个额外的跳。为了达到最佳性能,运行这个代理服务器的时候推荐在每个计算节点上分配一个Alluxio worker。

安装python客户端库

$ pip install alluxio

使用示例

下面的程序示例包括了如何在Alluxio创建目录、下载、上传、检查文件是否存在以及文件列表状态。

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import sys

import alluxio
from alluxio import option


def colorize(code):
    def _(text, bold=False):
        c = code
        if bold:
            c = '1;%s' % c
        return '\033[%sm%s\033[0m' % (c, text)
    return _

green = colorize('32')


def info(s):
    print green(s)


def pretty_json(obj):
    return json.dumps(obj, indent=2)


def main():
    py_test_root_dir = '/py-test-dir'
    py_test_nested_dir = '/py-test-dir/nested'
    py_test = py_test_nested_dir + '/py-test'
    py_test_renamed = py_test_root_dir + '/py-test-renamed'

    client = alluxio.Client('localhost', 39999)

    info("creating directory %s" % py_test_nested_dir)
    opt = option.CreateDirectory(recursive=True)
    client.create_directory(py_test_nested_dir, opt)
    info("done")

    info("writing to %s" % py_test)
    with client.open(py_test, 'w') as f:
        f.write('Alluxio works with Python!\n')
        with open(sys.argv[0]) as this_file:
            f.write(this_file)
    info("done")

    info("getting status of %s" % py_test)
    stat = client.get_status(py_test)
    print pretty_json(stat.json())
    info("done")

    info("renaming %s to %s" % (py_test, py_test_renamed))
    client.rename(py_test, py_test_renamed)
    info("done")

    info("getting status of %s" % py_test_renamed)
    stat = client.get_status(py_test_renamed)
    print pretty_json(stat.json())
    info("done")

    info("reading %s" % py_test_renamed)
    with client.open(py_test_renamed, 'r') as f:
        print f.read()
    info("done")

    info("listing status of paths under /")
    root_stats = client.list_status('/')
    for stat in root_stats:
        print pretty_json(stat.json())
    info("done")

    info("deleting %s" % py_test_root_dir)
    opt = option.Delete(recursive=True)
    client.delete(py_test_root_dir, opt)
    info("done")

    info("asserting that %s is deleted" % py_test_root_dir)
    assert not client.exists(py_test_root_dir)
    info("done")


if __name__ == '__main__':
    main()
Python 客户端
REST API
文档
示例