Skip to main content

Python SDK for the IYREE analytics platform

Project description

iyree

Python SDK for the IYREE BI analytics platform.

pip install iyree

# With pandas support
pip install iyree[pandas]

Quick Start

Synchronous

from iyree import IyreeClient

with IyreeClient(api_key="my-key", gateway_host="https://api.iyree.io") as client:
    # DWH — run SQL
    result = client.dwh.sql("SELECT * FROM orders LIMIT 10")
    for row in result.to_dicts():
        print(row)

    # DWH — insert data
    client.dwh.insert("staging_table", "col1,col2\n1,hello\n2,world")

    # Cube — analytics query
    result = client.cube.load({"measures": ["orders.count"]})
    print(result.data)

    # S3 — upload / download
    client.s3.upload_object("data/report.csv", b"a,b\n1,2")
    data = client.s3.download_object("data/report.csv")

    # KV — key-value store
    client.kv.put("config", {"theme": "dark"}, key="user_prefs")
    doc = client.kv.get("config", "user_prefs")

Asynchronous

from iyree import AsyncIyreeClient

async with AsyncIyreeClient(api_key="my-key") as client:
    result = await client.dwh.sql("SELECT 1 AS n")
    print(result.to_dicts())

Configuration

Parameter Env Var Default Description
api_key required API key for gateway auth
gateway_host IYREE_GATEWAY_HOST Gateway base URL
timeout 30.0 Default request timeout (seconds)
stream_load_timeout 300.0 DWH Stream Load timeout
cube_continue_wait_timeout 120.0 Cube polling timeout
max_retries 3 Max retry attempts

Cube Query Builder

Build type-safe Cube.js queries:

from iyree import Cube, Query, TimeDimension, DateRange, TimeGranularity

orders = Cube("orders")

query = Query(
    measures=[orders.measure("count"), orders.measure("total_amount")],
    dimensions=[orders.dimension("status")],
    time_dimensions=[
        TimeDimension(
            orders.dimension("created_at"),
            date_range=DateRange(relative="last 30 days"),
            granularity=TimeGranularity.day,
        )
    ],
)

with IyreeClient(api_key="my-key") as client:
    result = client.cube.load(query)
    df = result.to_dataframe()  # requires iyree[pandas]

Or use raw dicts:

result = client.cube.load({
    "measures": ["orders.count"],
    "timeDimensions": [{
        "dimension": "orders.created_at",
        "granularity": "day",
        "dateRange": "last 7 days",
    }],
})

DWH — Stream Load (Insert)

import pandas as pd

df = pd.DataFrame({"id": [1, 2], "name": ["Alice", "Bob"]})
result = client.dwh.insert("users", df, label="load_20240101")
print(f"Loaded {result.number_loaded_rows} rows")

S3 — Object Storage

# Auto-paginating iterator
for obj in client.s3.list_objects_iter(prefix="data/"):
    print(obj.key, obj.size)

# Stream download to file
client.s3.download_object_to_file("data/large.csv", "/tmp/large.csv")

# Upload a DataFrame as Parquet
client.s3.upload_dataframe("reports/q1.parquet", df, format="parquet")

Error Handling

from iyree import IyreeClient, IyreeAuthError, IyreeNotFoundError

try:
    with IyreeClient(api_key="my-key") as client:
        doc = client.kv.get("store", "missing-key")
except IyreeAuthError:
    print("Invalid API key")
except IyreeNotFoundError:
    print("Document not found")

Development

pip install -e ".[dev]"
pytest

License

MIT

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

iyree-0.4.0.tar.gz (114.5 kB view details)

Uploaded Source

Built Distribution

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

iyree-0.4.0-py3-none-any.whl (46.8 kB view details)

Uploaded Python 3

File details

Details for the file iyree-0.4.0.tar.gz.

File metadata

  • Download URL: iyree-0.4.0.tar.gz
  • Upload date:
  • Size: 114.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for iyree-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7435e42446e95d2c1f3f2a3ec4b5e7566847cd498a6da84b2800dc961e31631f
MD5 82c2f21f733d7c80adc06c5dfc46b9e6
BLAKE2b-256 16aa2387d9f95b0dd82b6db9d5105e56d8c77a951d8c027f5d44fb9bf2884c7d

See more details on using hashes here.

File details

Details for the file iyree-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: iyree-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 46.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for iyree-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a84e358807a8073dd95f70720d7725ca898c32d6278823fabc95b6252e0e4ff4
MD5 24a2acf8c419d24c47d960743c1b5968
BLAKE2b-256 7e740cfa1effad1cba0222c0ed5ab1bce13ab5c6d5a266105122187022382d98

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