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 1.4 and 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.2.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

starrocks-1.2.2-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: starrocks-1.2.2.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for starrocks-1.2.2.tar.gz
Algorithm Hash digest
SHA256 0176f677291d70321bbb9f0252686a1443fb0c1b986039dddcb66bd60e60c5fa
MD5 a4fdba795db37bf5c32ed1da6629c497
BLAKE2b-256 fa81e044a25ce3f2524af1a17532d611c7f2bd47c300a5a20a410d244a4d5a1c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: starrocks-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for starrocks-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e39978afa9abc2361d44ec426e1d8495e42aab5d9e66ffdbb5e21db542b5f45a
MD5 05499c9e8d237ab2b4f11b414182b5d1
BLAKE2b-256 08e553b3b819bf211900cfc70c32a7c4826a9e615f692be8e83199b192d11051

See more details on using hashes here.

Supported by

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