Skip to main content

Python SDK for querying StarRocks data.

Project description

mmcqdata

mmcqdata 是一个面向 StarRocks 查询场景的轻量 Python SDK,提供连接管理、SQL 查询和可选的 pandas 输出能力。

安装

安装基础版本:

pip install mmcqdata

如果需要直接返回 pandas.DataFrame

pip install "mmcqdata[pandas]"

快速开始

from mmcqdata import StarRocksClient, StarRocksConfig

config = StarRocksConfig(
    host="starrocks.example.com",
    port=9030,
    user="readonly_user",
    password="secret",
    database="analytics",
)

with StarRocksClient(config) as client:
    rows = client.query(
        "SELECT trade_date, symbol, close FROM daily_bar WHERE symbol = %s LIMIT 5",
        ("600519.SH",),
    )
    print(rows)

环境变量初始化

也可以通过环境变量创建客户端:

export MMCQDATA_HOST="starrocks.example.com"
export MMCQDATA_PORT="9030"
export MMCQDATA_USER="readonly_user"
export MMCQDATA_PASSWORD="secret"
export MMCQDATA_DATABASE="analytics"
from mmcqdata import StarRocksClient

with StarRocksClient.from_env() as client:
    row = client.query_one("SELECT 1 AS ok")
    print(row)

默认读取以下环境变量:

  • MMCQDATA_HOST
  • MMCQDATA_PORT
  • MMCQDATA_USER
  • MMCQDATA_PASSWORD
  • MMCQDATA_DATABASE
  • MMCQDATA_CONNECT_TIMEOUT
  • MMCQDATA_READ_TIMEOUT
  • MMCQDATA_WRITE_TIMEOUT

可用接口

  • StarRocksClient.query():返回多行字典结果。
  • StarRocksClient.query_one():返回单行字典结果。
  • StarRocksClient.execute():执行 SQL 并返回影响行数。
  • StarRocksClient.query_dataframe():返回 pandas.DataFrame
  • StarRocksClient.ping():检查连接是否可用。

发布到 PyPI

仓库里已经提供了发布脚本 scripts/publish.sh。该脚本会:

  1. 安装发布需要的工具。
  2. 构建源码包和 wheel。
  3. 执行 twine check
  4. 使用环境变量中的 PYPI_TOKEN 上传到 PyPI。

使用方式:

cd /Users/water/Documents/workspace/quant/repos/mmcqdata
export PYPI_TOKEN="pypi-xxxxxxxxxxxxxxxx"
./scripts/publish.sh

也可以执行:

bash scripts/publish.sh

不建议使用:

sh scripts/publish.sh

如果只想先试传到 TestPyPI,可以额外设置:

export PYPI_REPOSITORY_URL="https://test.pypi.org/legacy/"
./scripts/publish.sh

注意:不要把真实 token 写进仓库文件,直接放在终端环境变量里即可。

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

mmcqdata-0.2.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mmcqdata-0.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file mmcqdata-0.2.0.tar.gz.

File metadata

  • Download URL: mmcqdata-0.2.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for mmcqdata-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e80a930c0a15c4bdf56c829efc0514efb03ab560ef8fbfbb4f1771703a9d05d7
MD5 e1e89db1e50a12631c9580a09c2742cb
BLAKE2b-256 4e13b7f76c4ffb449d4b43780e27f153b759c156857101ec8fd51f47f58a0ef1

See more details on using hashes here.

File details

Details for the file mmcqdata-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mmcqdata-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for mmcqdata-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b258468c38d87e6dbf77c92085728e6e3773f2d885442cc0f110a5e5db7c3d50
MD5 926242436d1d5eb88c8f152f78767c97
BLAKE2b-256 a430111c634b191cc41c5ac246bf80ba468ed0ef677e2f9c35e38dabb6608f83

See more details on using hashes here.

Supported by

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