CLI and Python API

You can use the CHYT CLI and the CHYT Python API to run your clique or send a query to CHYT from a program or the command line. They can be obtained as part of the ytsaurus-client.

The command line utility accepts two environment variables: YT_PROXY and CHYT_ALIAS. You can use the former to specify the YTsaurus cluster, and the latter to specify the used clique.

For example, you can use the following command for Linux and macOS to set environment variables and no longer pass the --proxy <cluster_name> and --alias *ch_public parameters to all subsequent calls:

export YT_PROXY=<cluster_name> YT_ALIAS=*ch_public
About using the --alias parameter

In the CHYT CLI, depending on the command, the name of the clique is passed differently: either with or without an asterisk *.

  1. The execute command must always be called with an asterisk and the --alias key. Example:

    yt clickhouse execute --proxy <cluster_name> --alias *<clique_name>
    

    This is because it's a rather old command that includes logic dependent on the aliases of YTsaurus operations, which start with an asterisk.

  2. You can omit the asterisk * in commands from the yt clickhouse ctl range. Example:

    yt clickhouse ctl start <clique_name>
    

    Note that the old format is still supported for backward compatibility. Example:

    yt clickhouse ctl start *<clique_name>
    

The process that launches the clique can sometimes be informally called a launcher.

ytsaurus-client

The main way to get started with YTsaurus is to install the ytsaurus-client package. For more information, see Python Wrapper.

The package includes yt. In order to use the CHYT features, you can run any command as yt clickhouse [command].

For example, you can make a test query to the public clique ch_public as follows:

yt clickhouse execute "select 'Hello world'" --alias *ch_public

The package additionally contains the CHYT Python API available in the yt.clickhouse module:

python3
Python 3.7.3 (default, Oct  7 2019, 12:56:13)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import yt.clickhouse as chyt
>>> import yt.wrapper as yt
>>> client = yt.YtClient("<cluster_name>")
>>> list(chyt.execute("select * from `//home/user/sample_table`", alias="*ch_public", client=client))
[{'a': 100}, {'a': 101}, {'a': 102}, {'a': 205}, {'a': 206}, {'a': 1100}]

The library is available for Python 3.

For more detailed specification of the Python API and CLI features, see Executing queries.