Skip to main content

Clickhouse sink connector for bytewax

Project description

Actions Status PyPI Bytewax User Guide

Bytewax

bytewax-clickhouse

bytewax-clickhouse is commercially licensed with publicly available source code. Please see the full details in LICENSE.

Installation

pip install bytewax-clickhouse

Usage

Before running any workload, you will need to start ClickHouse if you are not already running it.

docker compose up -d

ClickHouse Sink requires a PyArrow table, Schema and keys for order and partition.

The Sink is eventually consistent based on the keys.

Add the import

from bytewax.clickhouse import operators as chop

Add A schema and order by string to your code.

CH_SCHEMA = """
        metric String,
        value Float64,
        ts DateTime,
        """

ORDER_BY = "metric, ts"

define a pyarrow schema

PA_SCHEMA = pa.schema(
    [
        ("metric", pa.string()),
        ("value", pa.float64()),
        ("ts", pa.timestamp("us")),  # microsecond
    ]
)

Use the ClickHouse Sink to write data to ClickHouse

chop.output(
    "output_clickhouse",
    metrics,
    "metrics",
    "admin",
    "password",
    database="bytewax",
    port=8123,
    ch_schema=CH_SCHEMA,
    order_by=ORDER_BY,
    pa_schema=PA_SCHEMA,
    timeout=timedelta(seconds=1),
    max_size=10,
)

Setting up the project

Install just

We use just as a command runner for actions / recipes related to developing Bytewax. Please follow the installation instructions. There's probably a package for your OS already.

Install pyenv and Python 3.12

I suggest using pyenv to manage python versions. the installation instructions.

You can also use your OS's package manager to get access to different Python versions.

Ensure that you have Python 3.12 installed and available as a "global shim" so that it can be run anywhere. The following will make plain python run your OS-wide interpreter, but will make 3.12 available via python3.12.

$ pyenv global system 3.12

Install uv

We use uv as a virtual environment creator, package installer, and dependency pin-er. There are a few different ways to install it, but I recommend installing it through either brew on macOS or pipx.

Development

We have a just recipe that will:

  1. Set up a venv in venvs/dev/.

  2. Install all dependencies into it in a reproducible way.

Start by adding any dependencies that are needed into pyproject.toml or into requirements/dev.in if they are needed for development.

Next, generate the pinned set of dependencies with

> just venv-compile-all

Create and activate a virtual environment

Once you have compiled your dependencies, run the following:

> just get-started

Activate your development environment and run the development task:

> . venvs/dev/bin/activate
> just develop

License

bytewax-clickhouse is commercially licensed with publicly available source code. Please see the full details in LICENSE.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

bytewax_clickhouse-0.0.1-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file bytewax_clickhouse-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bytewax_clickhouse-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f08c0e1748f90070c479a5863901ea6feca0607bd5a0070c956bd3ad4a910b8
MD5 ce5016c8ca76a01949e695b688e9ea8c
BLAKE2b-256 57ce8c8bd98b5527ac918bcd6f7b43452a8109677c42f7a353fb17946a7a0e25

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