Skip to main content

Python SDK for the Kronical API — real-time causal intelligence

Project description

Kronical Python SDK

Python client library for the Kronical API.

Installation

pip install kronical

# With WebSocket support
pip install kronical[websocket]

Quick Start

from kronical import KronicalClient

client = KronicalClient(
    api_key="kron_hf_...",
    base_url="https://api.kronical.ai",
)

# Health check
print(client.health())

# Get latest headlines
feed = client.feed.get(limit=10)
for h in feed["headlines"]:
    print(f"{h['text']} ({h['context']['novelty']})")

# Semantic search (merged into feed)
results = client.feed.get(query="semiconductor export controls", days_back=30)
print(f"Found {results['count']} headlines")

# Enrich a headline
enriched = client.enrichment.submit("Fed raises rates by 25bps to 5.75%")
print(enriched["enrichment"]["context_narrative"])

# Batch enrichment
batch = client.enrichment.batch([
    "Fed raises rates by 25bps",
    "ECB holds rates steady",
])
print(f"Batch {batch['batch_id']} submitted")

# Poll for results
results = client.enrichment.get_batch(batch["batch_id"])
print(f"Status: {results['batch']['status']}")

# Pulse columns
columns = client.pulse.list()
client.pulse.create(name="Fed Policy", query="Federal Reserve monetary policy")
client.pulse.update(columns["columns"][0]["column_id"], enabled=False)

# Smart columns
columns = client.smart_columns.list()
new_col = client.smart_columns.create(
    name="China Semi",
    instruction="Any news about semiconductor export restrictions involving China",
)
matches = client.smart_columns.matches(hours=24)

# Watchlist
states = client.watchlist.ticker_states(["AAPL", "NVDA", "TSLA"])
impacts = client.watchlist.impacts("NVDA", hours=48)
sparkline = client.watchlist.sparkline("AAPL")

# Usage stats
usage = client.usage.get(days=30)
print(f"Total requests: {usage['summary']['total_requests']}")

Async Client

import asyncio
from kronical import AsyncKronicalClient

async def main():
    async with AsyncKronicalClient(
        api_key="kron_hf_...",
        base_url="https://api.kronical.ai",
    ) as client:
        feed = await client.feed.get(limit=10)
        print(f"Got {feed['count']} headlines")

asyncio.run(main())

WebSocket Streams

Requires pip install kronical[websocket].

import asyncio
from kronical.websocket import KronicalWebSocket

async def main():
    ws = KronicalWebSocket(
        api_key="kron_hf_...",
        base_url="wss://api.kronical.ai",
    )

    # Live headline feed (runs forever)
    # The connected message includes pulse_columns list.
    # Each headline message includes matched_columns list.
    async def on_headline(msg):
        if msg.get("type") == "connected":
            print(f"Columns: {msg.get('pulse_columns')}")
            return
        print(f"[{msg.get('novelty')}] {msg.get('text')} (columns: {msg.get('matched_columns')})")

    await ws.pulse(on_message=on_headline)

asyncio.run(main())

Enrichment Feed (Bidirectional)

async def enrich_stream():
    ws = KronicalWebSocket(
        api_key="kron_hf_...",
        base_url="wss://api.kronical.ai",
    )
    await ws.connect_enrichment()

    result = await ws.enrich("Fed raises rates by 25bps to 5.75%")
    print(result)

    await ws.close()

Error Handling

from kronical import KronicalClient
from kronical.exceptions import RateLimitError, AuthenticationError, NotFoundError

client = KronicalClient(api_key="kron_hf_...", base_url="https://api.kronical.ai")

try:
    results = client.feed.get(query="oil prices", days_back=30)
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except AuthenticationError:
    print("Invalid API key")
except NotFoundError:
    print("Resource not found")

The SDK automatically retries on 429 (rate limit) responses with exponential backoff.

Configuration

Parameter Default Description
api_key required Your Kronical API key (kron_hf_...)
base_url required API base URL (https://api.kronical.ai)
timeout 30.0 Request timeout in seconds
max_retries 3 Max retries on rate limit (429)

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

kronical-0.1.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

kronical-0.1.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file kronical-0.1.1.tar.gz.

File metadata

  • Download URL: kronical-0.1.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for kronical-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c840f4352e1bb86a21717c575999f2981f9c7d8a8c95dc757900995d6abd04dc
MD5 7c97869d8241d1f76c7b1ff8e3c34c21
BLAKE2b-256 a0d0f10500b7b989c8191a3e3d15518d9ff7abe59adefa6a96be06da46c30e11

See more details on using hashes here.

File details

Details for the file kronical-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kronical-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for kronical-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e42ab0b8eaf3555b947fab1e24d57ca86630074187ae2579642adc99c3559010
MD5 c5be63d3b12a044214159292d97407bf
BLAKE2b-256 59d409a2e1e0e2cbc9a2f9278bd3519a5bc28875fb8fe71af8258b2e1cbe1006

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