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
Built Distribution
File details
Details for the file starrocks-1.1.0.tar.gz
.
File metadata
- Download URL: starrocks-1.1.0.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e136a3738f73813098e0543371d341b9ac048e7cf60e2346002c081e959c6453 |
|
MD5 | 94a48bdc387d0a08379d1f5f12c30385 |
|
BLAKE2b-256 | 90673c7eacf17a4396cf6c4b81fc42b639898c492a6937407ed5f40b28791f86 |
File details
Details for the file starrocks-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: starrocks-1.1.0-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 796f3de0404adc7736b2369b00e4a12c8cf3705aa6a3669292ad7c49ba0e794d |
|
MD5 | 2e40d298aa46b43b88ca2afd43a275c0 |
|
BLAKE2b-256 | 21327fa1614d7ba06e2e7df8691ef42f64d87b8d7afd795792c73cf1fae154de |