Skip to main content

Python driver with native interface for Proton

Project description

Introduction

Proton is a unified streaming and historical data processing engine in a single binary. The historical store is built based on ClickHouse.

This project provides python driver to interact with Proton, the code is based on https://github.com/mymarilyn/clickhouse-driver.

Installation

Proton Python Driver currently supports the following versions of Python: 3.8, 3.9, 3.10, 3.11 and 3.12.

Installing with pip We recommend creating a virtual environment when installing Python dependencies. For more information on setting up a virtual environment, see the Python documentation.

pip install proton-driver

Quick Start

  1. Run proton with docker. Make sure the port 8463 is exposed.

docker run -d -p 8463:8463 --pull always --name proton ghcr.io/timeplus-io/proton:latest
  1. Run following python code

from proton_driver import connect
with connect("proton://default:@localhost:8463/default") as conn:
  with conn.cursor() as cursor:
    cursor.execute("select 1")
    print(cursor.fetchone())

above code should return (1,) , which shows that everything is working fine now.

Streaming Query

from proton_driver import client

c = client.Client(host='127.0.0.1', port=8463)

# create a random stream if not exist
c.execute("CREATE RANDOM STREAM IF NOT EXISTS"
          " devices("
          " device string default 'device'||to_string(rand()%4), "
          " temperature float default rand()%1000/10"
          ")")
# query the stream and return in a iterator
rows = c.execute_iter(
    "SELECT device, count(*), min(temperature), max(temperature) "
    "FROM devices GROUP BY device",
)
for row in rows:
    print(row)

the output of the code will be something like following, as for streaming query is unbounded, you can add your flow control to terminate the loop.

('device0', 747, 0.0, 99.5999984741211)
('device1', 723, 0.10000000149011612, 99.30000305175781)
('device3', 768, 0.30000001192092896, 99.9000015258789)
('device2', 762, 0.20000000298023224, 99.80000305175781)
('device0', 1258, 0.0, 99.5999984741211)
('device1', 1216, 0.10000000149011612, 99.69999694824219)
('device3', 1276, 0.30000001192092896, 99.9000015258789)
('device2', 1250, 0.20000000298023224, 99.80000305175781)

Insert Data

from proton_driver import client

c = client.Client(host='127.0.0.1', port=8463)

# create a random stream if not exist
c.execute("INSERT INTO proton_stream (raw) VALUES",rows) #rows is an array of arrays

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

proton-driver-0.2.10.tar.gz (342.3 kB view hashes)

Uploaded Source

Built Distributions

proton_driver-0.2.10-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (219.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

proton_driver-0.2.10-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (225.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

proton_driver-0.2.10-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (216.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

proton_driver-0.2.10-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (222.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

proton_driver-0.2.10-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (216.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

proton_driver-0.2.10-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (222.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

proton_driver-0.2.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (990.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

proton_driver-0.2.10-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (953.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

proton_driver-0.2.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (904.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

proton_driver-0.2.10-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (876.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

proton_driver-0.2.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (909.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

proton_driver-0.2.10-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (881.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

proton_driver-0.2.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (957.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

proton_driver-0.2.10-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (894.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

proton_driver-0.2.10-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (847.3 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

proton_driver-0.2.10-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (820.3 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

proton_driver-0.2.10-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (779.5 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

proton_driver-0.2.10-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (754.4 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

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