Coder Social home page Coder Social logo

ksqldb's Introduction

KSQLdb for Python

Project Overview

A Python wrapper for the KSQLdb REST API

Installation

pip install ksqldb

Client configuration

from ksqldb import KSQLdbClient

client = KSQLdbClient('http://localhost:8088')

It can also be configured with Basic authentication:

from ksqldb import KSQLdbClient

client = KSQLdbClient('http://localhost:8088', api_key="<KEY>", api_secret="<SECRET>")

Usage

client.get_properties()

Returns KSQLdb properties

client.get_properties()

client.ksql(ksql_string, stream_properties=None)

For a full list of statement options make sure to check KSQLdb API: /ksql endpoint

Examples of executing KSQL statements:

client.ksql("show topics;")
client.ksql("show streams;")
client.ksql("show tables;")
client.ksql("describe <STREAM_NAME> extended;")

client.query_sync(query_string, stream_properties=None, timeout=10)

Runs a query synchronously. Can't be used with EMIT CHANGES queries.

Examples of executing KSQL queries:

client.query_sync("select * from STREAM_NAME;")

# To get data from beginning of stream use: 
client.query_sync("select * from STREAM_NAME;", stream_properties={"ksql.streams.auto.offset.reset": "earliest"})

client.query_async(query_string, stream_properties=None, timeout=10)

Runs a query asynchronously.

To test this in python shell can use python -m asyncio Examples of executing KSQL async queries:

async for x in client.query_async("select * from STREAM_NAME emit changes;", timeout=None):
    print(x)
    
# To get data from beginning of stream use: 
async for x in client.query_async("select * from STREAM_NAME emit changes;", stream_properties={"ksql.streams.auto.offset.reset": "earliest"}, timeout=None):
    print(x)

close_query(query_id)

Usually you don't need to close a sync query, but should be done for async ones.

client.close_query("QUERY_ID")

inserts_stream(stream_name, rows)

Inserts data into a stream.

rows = [
    {
        "col1" : "val1",
        "col2": 2.3,
        "col3": True
    },
    {
        "col1" : "val1",
        "col2": 2.3,
        "col3": True
    },
]
client.inserts_stream("STREAM_NAME", rows)

ksqldb's People

Contributors

erachter avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

eshepelyuk

ksqldb's Issues

Implement ksql_async

Hello

Could you please implement asynchronous version of ksql() method ?
In general, do you think it's possible to use httpx both for synchronous and asynchronous HTTP calls, so requests can be removed from the project ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.