Skip to main content

Python SQLAlchemy Dialect for StarRocks

Project description

StarRocks Python Client

A StarRocks client for the Python programming language.

StarRocks is the next-generation data platform designed to make data-intensive real-time analytics fast and easy. It delivers query speeds 5 to 10 times faster than other popular solutions. StarRocks can perform real-time analytics well while updating historical records. It can also enhance real-time analytics with historical data from data lakes easily. With StarRocks, you can get rid of the de-normalized tables and get the best performance and flexibility.

Installation

pip install starrocks

SQLAlchemy Usage

To connect to StarRocks using SQLAlchemy, use a connection string (URL) following this pattern:

  • User: User Name
  • Password: DBPassword
  • Host: StarRocks FE Host
  • Catalog: Catalog Name
  • Database: Database Name
  • Port: StarRocks FE port

Here's what the connection string looks like:

starrocks://<User>:<Password>@<Host>:<Port>/<Catalog>.<Database>

Example

Python connector supports only Python 3 and SQLAlchemy 2:

from sqlalchemy import create_engine, Integer, insert
from sqlalchemy.schema import Table, MetaData, Column
from sqlalchemy.sql.expression import select, text

engine = create_engine('starrocks://root:xxx@localhost:9030/hive_catalog.hive_db')

### Querying data
with engine.connect() as connection:
    rows = connection.execute(text("SELECT * FROM hive_table")).fetchall()
    print(rows)


### DDL Operation
meta = MetaData()
tbl = Table(
    'table1',
    meta,
    Column("id", Integer),
    starrocks_engine='OLAP',
    starrocks_comment='table comment',
    starrocks_properties=(
        ("storage_medium", "SSD"),
        ("storage_cooldown_time", "2025-06-04 00:00:00"),
        ("replication_num", "1")
    ))

meta.create_all(engine)

### Insert data
stmt = insert(tbl).values(id=1)
stmt.compile()
with engine.connect() as connection:
    connection.execute(stmt)
    rows = connection.execute(tbl.select()).fetchall()
    print(rows)

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

starrocks-1.2.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

starrocks-1.2.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file starrocks-1.2.0.tar.gz.

File metadata

  • Download URL: starrocks-1.2.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.9 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8

File hashes

Hashes for starrocks-1.2.0.tar.gz
Algorithm Hash digest
SHA256 3e02a6dd2e10ff868a0fe87cf5be9cf018ddeabe980537bd40a43246bd479a52
MD5 f0dbff990176d154e7d740e8865dce09
BLAKE2b-256 974d84f2aecf9298ef9a281ede2898f44c37470f20a5d765a5482a3de3ee24b6

See more details on using hashes here.

File details

Details for the file starrocks-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: starrocks-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.9 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8

File hashes

Hashes for starrocks-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af7a4f3738bb30854dc231a05c734487f075bd5ec920230ecb28acd73822421c
MD5 bb94279b7b9a466d7332daa8263efed9
BLAKE2b-256 c3ef0e799ab3c8d71f055df177d61a2f55d297bd02c6e4c17a89f68110144697

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page