Skip to main content

cmoney-datahub

Thin Python client for the CMoney DataHub delivery API. It mirrors the portal's pull path (catalog → tree → presign → parquet) and returns pandas DataFrames. Downloads are S3-direct (the API only signs URLs), so large pulls are not bound by any server request timeout.

Install

pip install cmoney-datahub

Optional extras: polars (engine="polars"), duckdb (.sql()), progress (tqdm bar), or everything — pip install "cmoney-datahub[all]".

The package is a thin client; you still need a CMoney DataHub API key to pull data — pass it as Client("dpk_...") or set CMONEY_DATAHUB_KEY. Contact your account manager for a key.

Alternative: install from the portal (no PyPI)

The key must go in an HTTP header, so download the wheel then install it:

curl -fsSL -H "X-API-Key: dpk_..." \
  "https://datahub.cmoney.tw/api/skill?format=wheel" -o cmoney_datahub-0.1.0-py3-none-any.whl
pip install --force-reinstall cmoney_datahub-0.1.0-py3-none-any.whl

In Jupyter: run the curl in a ! cell, then %pip install --force-reinstall <wheel> and restart the kernel. For local development: pip install -e ./sdk.

Quickstart

from cmoney_datahub import Client

c = Client("dpk_...")            # or set CMONEY_DATAHUB_KEY and call Client()
c.datasets()                     # datasets this key is entitled to (code · slug · title · category)

df = c.get("market-vote", start="2026-06", end="2026-06")
df.head()

The dataset id accepts the client-facing slug (stock-pageviews) or the internal code (a3-stock-pv) interchangeably.

The surface model — one get() = one surface

A dataset exposes one or more surfaces. A surface is either a bare panel (e.g. app-forum) or a panel/grain pair (e.g. app-forum/daily); the grain drives the column set. Each get() returns exactly one surface's schema — if a multi-surface dataset is under-specified, it raises AmbiguousSurfaceError rather than silently stacking mismatched columns.

# grid dataset (panel × grain)
df = c.get("stock-pageviews", panel="app-forum", grain="daily",
           start="2026-01", end="2026-03")
# equivalently: surface="app-forum/daily"

# record / list dataset
df = c.get("paper-trading", surface="deal-record", start="2026-01", end="2026-03")

# single-surface dataset — nothing to pass
df = c.get("market-vote", start="2026-06", end="2026-06")

Discover surfaces with c.surfaces(code); inspect one with c.schema(code, panel=..., grain=...).

Core methods

Method Purpose
Client(key=None, api=...) Connect. key falls back to $CMONEY_DATAHUB_KEY.
.datasets() Entitled datasets (drops not-yet-uploaded ones).
.surfaces(code) Pullable surface list for a dataset.
.schema(code, *, surface=|panel=+grain=) One surface's columns + types.
.coverage(code, *, surface=|panel=+grain=) {from, to, months} coverage.
.estimate(code, start, end, *, surface=|panel=+grain=) {files, bytes} without downloading.
.get(code, start, end, *, surface=|panel=+grain=, tickers=, columns=, version=, workers=4, engine="pandas", cache=True, progress=) Pull one surface → DataFrame.
.get_all(code, start, end, ...) Every surface at once → {surface: DataFrame}.
.iter_get(code, ..., columns=, version=, cache=True) Stream one DataFrame per file (bounded memory).
.download(code, dest, ..., workers=4, cache=True) Write parquet files to disk (no pandas), keeping the S3 layout.
.sql(query, code=None, *, surface=|panel=+grain=, start, end, table="data") DuckDB over the cached slice → pandas.
.versions(code) Available versions (months) → pass to version=.
.usage() Trial quota vs cap.

Working with large datasets

A single get() concatenates every file into one DataFrame — fine for most slices, but a wide multi-year pull (e.g. stock-pageviews ≈ 1 GB / 144M rows) can exhaust memory. Two escape hatches:

# stream one month at a time — memory stays bounded
for df in c.iter_get("stock-pageviews", panel="app-forum", grain="daily",
                     start="2024-01", end="2026-06"):
    process(df)

# or land parquet on disk and query with DuckDB / Polars (no pandas)
paths = c.download("stock-pageviews", "./pv", panel="app-forum", grain="daily")
import duckdb
duckdb.sql("select * from read_parquet('pv/**/*.parquet')")

# or let the SDK stage + query it for you (auto-caches; exposes the slice as view `data`)
top = c.sql("select stockid, sum(pv) pv from data group by 1 order by pv desc limit 10",
            code="stock-pageviews", panel="app-forum", grain="daily",
            start="2026-01", end="2026-03")

get_all() pulls every surface at once, and engine= changes the return type:

panels = c.get_all("stock-pageviews", start="2026-01", end="2026-03")   # {surface: DataFrame}
df = c.get("market-vote", start="2026-06", end="2026-06", engine="polars")  # polars.DataFrame

Behaviour notes

  • Ticker filter is client-side. tickers=["2330"] filters after download; the server never receives symbols (PIT-safe, matches the flat-file delivery model).
  • Column projection. columns=["stockid", "pv"] reads only those columns from parquet — less memory and parse time on wide datasets.
  • sha-verified local cache (on by default). Files are cached by content hash, so repeat pulls read from disk and cost no quota. Disable with cache=False; relocate with cache_dir= or $CMONEY_DATAHUB_CACHE.
  • Quota is checked before downloading — a request that won't fit the trial cap raises QuotaError up front (the server 403 is the hard backstop).
  • Window / entitlement are enforced server-side. An over-range request warns (or raises with strict=True) and returns the available intersection.
  • Every get() reports. It prints a one-line summary + live remaining quota, and attaches df.attrs["cmoney"] = {files, downloaded, cached, failures, bytes}. Silence it with progress=False.

Errors

AuthError · EntitlementError · NotFoundError · QuotaError · RateLimitError · AmbiguousSurfaceError — all subclasses of DataHubError.

Metadata

Release files for cmoney-datahub 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cmoney-datahub 0.1.1
File Size Uploaded Provenance Actions
cmoney_datahub-0.1.1.tar.gz 16.2 kB Without provenance Details for cmoney_datahub-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cmoney-datahub 0.1.1
File Interpreter ABI Platform Actions
cmoney_datahub-0.1.1-py3-none-any.whl Python 3 none any Details for cmoney_datahub-0.1.1-py3-none-any.whl

Total release size: 33.9 kB

Release files / cmoney_datahub-0.1.1.tar.gz

Download URL cmoney_datahub-0.1.1.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c72b8cea2486631db84b0e0995da3fd56be5cbe47a599f96777450c4f5d0514f
BLAKE2b-256 checksum
How to use checksums
713aa0d848baccfdf0a7fdd6fc2850f80561c9db4d04bc4b6ef01bca9f72019a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / cmoney_datahub-0.1.1-py3-none-any.whl

Download URL cmoney_datahub-0.1.1-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64f39a9896d3ece7d04a76181884c938173d91762c81c8574dae09bd24551234
BLAKE2b-256 checksum
How to use checksums
a4493ef49314a858e924872320e4294353369fe6b512fb000c929cdf2e0fdbe5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for cmoney-datahub 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page