Apache Kylin Python Client Library

2.8.4 · active · verified Sat Apr 11

The `kylinpy` library provides a Python client to interact with Apache Kylin, an OLAP engine for Big Data, allowing users to query and manage Kylin instances programmatically. It abstracts the REST API interactions, facilitating tasks such as executing queries, managing projects, and retrieving metadata. The current version is 2.8.4, and it maintains an active release cadence, often aligning with Apache Kylin server updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to an Apache Kylin instance, select a project, and execute a simple SQL query using the `kylinpy` client. It retrieves the results directly into a pandas DataFrame. Credentials and project name are sourced from environment variables for secure and flexible configuration.

import os
from kylinpy import KylinClient

# Configure connection details using environment variables for security
HOST = os.environ.get('KYLIN_HOST', 'localhost')
PORT = os.environ.get('KYLIN_PORT', '7070')
USERNAME = os.environ.get('KYLIN_USERNAME', 'ADMIN')
PASSWORD = os.environ.get('KYLIN_PASSWORD', 'KYLIN')
PROJECT = os.environ.get('KYLIN_PROJECT', 'learn_kylin')

try:
    # Initialize the KylinClient
    client = KylinClient(
        host=HOST,
        port=PORT,
        username=USERNAME,
        password=PASSWORD
    )

    # Select the project context for operations
    client.use_project(PROJECT)
    print(f"Connected to Kylin at {HOST}:{PORT}, project: {PROJECT}")

    # Execute a sample query and get results as a pandas DataFrame
    sql_query = "SELECT LSTG_FORMAT_NAME, sum(PRICE) FROM KYLIN_SALES GROUP BY LSTG_FORMAT_NAME ORDER BY sum(PRICE) DESC LIMIT 5"
    df = client.query_to_dataframe(sql_query)

    print("\nQuery Results (top 5 rows):")
    print(df.to_string())

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure KYLIN_HOST, KYLIN_PORT, KYLIN_USERNAME, KYLIN_PASSWORD, and KYLIN_PROJECT environment variables are correctly set or provide valid defaults.")

view raw JSON →