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']})")
# Natural language search
results = client.feed.get(query="semiconductor export controls", days_back=30)
print(f"Found {results['count']} headlines")
# Enrich a news item
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 = 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 agents
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
Release history Release notifications | RSS feed
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.2.tar.gz
(12.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
kronical-0.1.2-py3-none-any.whl
(15.1 kB
view details)
File details
Details for the file kronical-0.1.2.tar.gz.
File metadata
- Download URL: kronical-0.1.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40c692ae652e0ec4c163c727f964b5d82fda25b8f4dabaf2ee439ecb9f40f8d4
|
|
| MD5 |
a80aeaa8adc782a3adf16a45427948d8
|
|
| BLAKE2b-256 |
eb7e168ef11dc04bf61ebafb00e16eacf57fc10d993d89d4e963a7b0fa91b498
|
File details
Details for the file kronical-0.1.2-py3-none-any.whl.
File metadata
- Download URL: kronical-0.1.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0353bba9b54cb67b3557fe22a02fe59526c9ab03c209a728e37952a36795edda
|
|
| MD5 |
a0aefa37fb57b0116e5392f643c0a73e
|
|
| BLAKE2b-256 |
502999df4933b259a2840b44452e4028bf14b82c38721023b5c01196d84a96ee
|