Skip to main content

Python driver with native interface for Proton

Project description

Introduction

Timeplus is a unified streaming and historical data processing engine in a single binary.

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

Installation

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

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 --extra-index-url https://d.timeplus.com/simple/

Quick Start

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

docker run -d -p 8463:8463 --pull always --name proton d.timeplus.com/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

Pandas DataFrame

Big fan of Pandas? We too! You can mix SQL and Pandas API together:

import pandas as pd
import time

from proton_driver import client

if __name__ == "__main__":
    c = client.Client(host='127.0.0.1', port=8463)

    # setup the test stream
    c.execute("drop stream if exists test")
    c.execute("""create stream test (
                    year int16,
                    first_name string
                )""")
    # add some data
    df = pd.DataFrame.from_records([
        {'year': 1994, 'first_name': 'Vova'},
        {'year': 1995, 'first_name': 'Anja'},
        {'year': 1996, 'first_name': 'Vasja'},
        {'year': 1997, 'first_name': 'Petja'},
    ])
    c.insert_dataframe(
        'INSERT INTO "test" (year, first_name) VALUES',
        df,
        settings=dict(use_numpy=True),
    )
    # or c.execute("INSERT INTO test(year, first_name) VALUES", df.to_dict('records'))
    time.sleep(3) # wait for 3 sec to make sure data available in historical store

    df = c.query_dataframe('SELECT * FROM table(test)')
    print(df)
    print(df.describe())

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 Distributions

proton_driver-0.2.11-pp310-pypy310_pp73-win_amd64.whl (190.8 kB view hashes)

Uploaded PyPy Windows x86-64

proton_driver-0.2.11-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (218.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

proton_driver-0.2.11-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (211.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

proton_driver-0.2.11-pp310-pypy310_pp73-macosx_10_15_x86_64.whl (190.6 kB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

proton_driver-0.2.11-pp39-pypy39_pp73-win_amd64.whl (190.7 kB view hashes)

Uploaded PyPy Windows x86-64

proton_driver-0.2.11-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (217.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

proton_driver-0.2.11-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (210.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

proton_driver-0.2.11-pp39-pypy39_pp73-macosx_10_15_x86_64.whl (190.4 kB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

proton_driver-0.2.11-pp38-pypy38_pp73-win_amd64.whl (189.2 kB view hashes)

Uploaded PyPy Windows x86-64

proton_driver-0.2.11-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (216.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

proton_driver-0.2.11-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (210.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

proton_driver-0.2.11-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (187.4 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

proton_driver-0.2.11-cp313-cp313-win_amd64.whl (201.7 kB view hashes)

Uploaded CPython 3.13 Windows x86-64

proton_driver-0.2.11-cp313-cp313-musllinux_1_1_x86_64.whl (991.3 kB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.1+ x86-64

proton_driver-0.2.11-cp313-cp313-musllinux_1_1_aarch64.whl (975.7 kB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.1+ ARM64

proton_driver-0.2.11-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (984.1 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

proton_driver-0.2.11-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (969.9 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

proton_driver-0.2.11-cp313-cp313-macosx_11_0_arm64.whl (206.9 kB view hashes)

Uploaded CPython 3.13 macOS 11.0+ ARM64

proton_driver-0.2.11-cp313-cp313-macosx_10_13_x86_64.whl (210.2 kB view hashes)

Uploaded CPython 3.13 macOS 10.13+ x86-64

proton_driver-0.2.11-cp312-cp312-win_amd64.whl (204.3 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

proton_driver-0.2.11-cp312-cp312-musllinux_1_1_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

proton_driver-0.2.11-cp312-cp312-musllinux_1_1_aarch64.whl (992.2 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

proton_driver-0.2.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (999.2 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

proton_driver-0.2.11-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (985.1 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

proton_driver-0.2.11-cp312-cp312-macosx_11_0_arm64.whl (208.8 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

proton_driver-0.2.11-cp312-cp312-macosx_10_13_x86_64.whl (212.0 kB view hashes)

Uploaded CPython 3.12 macOS 10.13+ x86-64

proton_driver-0.2.11-cp311-cp311-win_amd64.whl (204.4 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

proton_driver-0.2.11-cp311-cp311-musllinux_1_1_x86_64.whl (995.2 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

proton_driver-0.2.11-cp311-cp311-musllinux_1_1_aarch64.whl (985.9 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

proton_driver-0.2.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (985.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

proton_driver-0.2.11-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (977.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

proton_driver-0.2.11-cp311-cp311-macosx_11_0_arm64.whl (207.3 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

proton_driver-0.2.11-cp311-cp311-macosx_10_9_x86_64.whl (211.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

proton_driver-0.2.11-cp310-cp310-win_amd64.whl (204.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

proton_driver-0.2.11-cp310-cp310-musllinux_1_1_x86_64.whl (923.3 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

proton_driver-0.2.11-cp310-cp310-musllinux_1_1_aarch64.whl (910.9 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

proton_driver-0.2.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (906.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

proton_driver-0.2.11-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (894.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

proton_driver-0.2.11-cp310-cp310-macosx_11_0_arm64.whl (206.8 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

proton_driver-0.2.11-cp310-cp310-macosx_10_9_x86_64.whl (210.6 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

proton_driver-0.2.11-cp39-cp39-win_amd64.whl (205.7 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

proton_driver-0.2.11-cp39-cp39-musllinux_1_1_x86_64.whl (925.9 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

proton_driver-0.2.11-cp39-cp39-musllinux_1_1_aarch64.whl (913.4 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

proton_driver-0.2.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (914.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

proton_driver-0.2.11-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (901.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

proton_driver-0.2.11-cp39-cp39-macosx_11_0_arm64.whl (208.1 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

proton_driver-0.2.11-cp39-cp39-macosx_10_9_x86_64.whl (212.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

proton_driver-0.2.11-cp38-cp38-win_amd64.whl (206.2 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

proton_driver-0.2.11-cp38-cp38-musllinux_1_1_x86_64.whl (966.0 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

proton_driver-0.2.11-cp38-cp38-musllinux_1_1_aarch64.whl (954.4 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

proton_driver-0.2.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (926.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

proton_driver-0.2.11-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (915.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

proton_driver-0.2.11-cp38-cp38-macosx_11_0_arm64.whl (208.5 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

proton_driver-0.2.11-cp38-cp38-macosx_10_9_x86_64.whl (212.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

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