Skip to main content

A toolkit for running ClickHouse queries interactively, leveraging the perks of an ipython console

Project description

clickhouse-repl

PyPI - Version PyPI - Downloads PyPI - License

A toolkit for running ClickHouse queries interactively, leveraging the perks of an ipython console

Installation

Use the package manager pip to install clickhouse-repl.

pip install clickhouse-repl

Usage

$ clickhouse-repl --help             
Usage: clickhouse-repl [OPTIONS]

  A toolkit for running ClickHouse queries interactively,  leveraging the
  perks of an ipython console.

  You can also set options with environment variables by using this format:
  CLICKHOUSE_REPL_<OPTION>

  Once in, run_query() will be your friend to execute queries.

Options:
  --host TEXT      Hostname or IP  [default: localhost]
  --port INTEGER   Native port  [default: 9000]
  --user TEXT      The ClickHouse user  [default: default]
  --password TEXT  Will be prompted. You can also set the environment variable
                   CLICKHOUSE_REPL_PASSWORD  [required]

  --database TEXT  The database we gonna use  [default: default]
  --help           Show this message and exit. 

Connecting

Password prompted

If no environment variable is set, password will be prompted.

$ clickhouse-repl
Password: 
Welcome to clickhouse-repl 1.0.0 on Python 3.7.2, IPython 7.19.0
Connected to localhost:9000, clickhouser-server version 20.12.5

Password provided

This is not considered secure since passwords ends up persisted on .bash_history, for example.

Avoid this one!

$ clickhouse-repl --password v3ryh4rdp4ssword

Depending on the shell and settings in place, it is possible to bypass the recording to history by prefixing the command with double space

Password from Environment Variable

You may set CLICKHOUSE_REPL_PASSWORD on your .bashrc/.zshrc/.bash_profile.

$   export CLICKHOUSE_REPL_PASSWORD=v3ryh4rdp4ssword
$ clickhouse-repl

Alternatively:

$   env CLICKHOUSE_REPL_PASSWORD=v3ryh4rdp4ssword clickhouse-repl

Connecting to specific database

Specify the database name and your session will start automatically from it.

Useful when your tables are somewhere else other than the ClickHouse default's database and you don't want to specify the database every time on your queries.

$ clickhouse-repl --database mydatabase

Running Queries

Using run_queries

$ clickhouse-repl
Password: 
Welcome to clickhouse-repl 1.0.0 on Python 3.7.2, IPython 7.19.0
Connected to localhost:9000, clickhouser-server version 20.12.5
In [1]: run_query('select now64()')
Out[1]: [(datetime.datetime(2021, 1, 19, 0, 41, 7, 216000),)]

In [2]: 

Using client/c

These are shortcuts to clickhouse_driver.Client instance, initiated when a clickhouse-repl session is started.

You may use it for whatever purpose you may find.

To run queries with it you need to call c.execute()/client.execute() instead of run_query(). The later is in fact just a idiomatic shortcut pointing to the first.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clickhouse-repl-1.0.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

clickhouse_repl-1.0.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file clickhouse-repl-1.0.0.tar.gz.

File metadata

  • Download URL: clickhouse-repl-1.0.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Linux/5.4.0-1036-azure

File hashes

Hashes for clickhouse-repl-1.0.0.tar.gz
Algorithm Hash digest
SHA256 719b5abcf5e093ba7973d37d9be2cd3db966a217e9a41069f940966eab41345e
MD5 eb7426f365b2326e87c7e97eaf08a379
BLAKE2b-256 f33c5e6f89aef1850fff1a3eb5a055cec320a93466a9085314b751bd4328fccb

See more details on using hashes here.

File details

Details for the file clickhouse_repl-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: clickhouse_repl-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Linux/5.4.0-1036-azure

File hashes

Hashes for clickhouse_repl-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c5f6edf440ae866cbd4bfe167a2bb8dd7c6c28fb16e66a328f9c592504080ac
MD5 90418251a2608b86f5dc9fea93336c54
BLAKE2b-256 2bc5da4719432ee37b4f8d696ccbe810466e20c7a816b6616d1f37d11d40af74

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page