base-yt-client-notebook
from yt import wrapper as yt
You can use YTsaurus client without passing a proxy and a token. YTsaurus client implicitly uses the token from the YT_TOKEN secret and works with the current cluster.
Let's get attributes from //sys directory.
yt.get("//sys/@")
Create ytsaurus client, create table and sort it.
client = yt.YtClient(config=yt.default_config.get_config_from_env())
import uuid
username = yt.get_user_name()
if yt.exists(f"//sys/users/{username}/@user_info/home_path"):
home = yt.get(f"//sys/users/{username}/@user_info/home_path")
base_example_path = f"{home}/{uuid.uuid4().hex}"
else:
base_example_path = f"//tmp/examples/{uuid.uuid4().hex}"
yt.create("map_node", base_example_path)
print(base_example_path)
records = [{"key": "a", "value": 3}, {"key": "b", "value": 2}, {"key": "c", "value": 1}]
table_path = f"{base_example_path}/table_to_be_sorted"
client.write_table(f"{base_example_path}/table_to_be_sorted", input_stream=records, force_create=True)
client = yt.YtClient(config=yt.default_config.get_config_from_env())
print([r for r in client.read_table(table_path)])
client.run_sort(table_path, table_path, sort_by="value")
print([r for r in client.read_table(table_path)])