Python Client for YTsaurus

0.13.48 · active · verified Sun Apr 12

ytsaurus-client is the official Python client library for YTsaurus, a scalable and fault-tolerant open-source big data platform for distributed storage and processing. It provides a Python-friendly mechanism for running operations, reading/writing data to the cluster, and interacting with distributed file systems, MapReduce, and NoSQL key-value storage. The library is actively maintained with frequent releases, currently at version 0.13.48.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the YTsaurus client and perform basic operations like listing a directory and getting a node's attribute. It assumes `YT_PROXY` and `YT_TOKEN` environment variables are set for authentication and cluster proxy address. For a local setup, you might need `ytsaurus-local` and direct configuration.

import os
import yt
from yt.common import YtError

# Configure connection via environment variables for a runnable example
# In a real scenario, these would be set in your environment
# or passed explicitly in client config.
# Example: os.environ['YT_PROXY'] = 'your-yt-cluster-proxy'
# Example: os.environ['YT_TOKEN'] = os.environ.get('YT_TOKEN', 'your-oauth-token')

# Fallback for demonstration if environment variables are not set
# Replace with actual proxy if running locally without env vars set.
# For example: config=yt.config.Config(proxy='localhost:8000', token='your-token')
client = yt.YtClient(config=yt.default_config.get_config_from_env())

try:
    # Example: List the root directory of Cypress
    # This requires 'read' permission on '//'
    root_content = client.list("//", attributes=["type"]) # Get type attribute
    print(f"First 5 items in root directory: {[item.attributes.get('type', 'unknown') + ' ' + str(item) for item in root_content[:5]]}")

    # Example: Get an attribute of a system node
    node_type = client.get("//sys/@type")
    print(f"Type of //sys: {node_type}")

except YtError as e:
    print(f"YTsaurus Error: {e.message}")
    print("Please ensure YT_PROXY and YT_TOKEN environment variables are correctly set and you have access to the cluster.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →