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.1.0.tar.gz (4.3 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.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mmcqdata-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e9f5be052f022535e16a34caf432707e930e0fc65f003408e818eb0d4b0c6c6d
MD5 50530bfdced606eea4084c9977f00733
BLAKE2b-256 7119e5ef2992bae4b903e2b27f5fa749908254eb3105ee1986889ef91c56ad4e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mmcqdata-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 939ac68ad74c585ebda7d1db40bd1d0ba8c98c20abde40acffe71713ace0700c
MD5 fb30dd78551a5a053092f6e4e8867b55
BLAKE2b-256 0520dace91bcfcf87611cf548fde7883a74f6b1584123c71d7a307f5621fcae9

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