Browse documentation
SDKs
Python SDK
The official Python SDK for the Drishti API provides a synchronous HTTP client, low-level request methods, and an async websocket client.
Requirements
- Python
3.10+ - A valid Drishti API key
Installation
pip install drishti-sdkPackage: drishti-sdk on PyPI.
Quick start
from drishti_sdk import DrishtiClient
with DrishtiClient(api_key="YOUR_API_KEY") as client:
news = client.get_news(
symbols=["RELIANCE", "TCS"],
limit=10,
)
print(len(news["data"]))WebSocket session
The websocket client connects automatically on the first subscribe, events, or async with call and keeps retrying after disconnects until the session closes.
Event listeners
import asyncio
from drishti_sdk import DrishtiClient
async def main() -> None:
client = DrishtiClient(api_key="YOUR_API_KEY")
async with client.websocket(
reconnect_initial_delay=1.0,
reconnect_max_delay=30.0,
on_announcements=lambda announcement: print(
"announcement", announcement
),
) as ws:
await ws.subscribe("announcements", symbols=["RELIANCE"])
await asyncio.Event().wait()
asyncio.run(main())Async iterator
async with client.websocket() as ws:
await ws.subscribe("announcements", symbols=["RELIANCE"], detailed=False)
async for event in ws.events():
if event.kind == "data":
print(event.channel, event.data)Batch jobs
from drishti_sdk import DrishtiClient
with DrishtiClient(api_key="YOUR_API_KEY") as client:
with open("batch.jsonl", "rb") as f:
file_bytes = f.read()
job = client.post_batch_jobs_file(
file_name="batch.jsonl",
file_bytes=file_bytes,
display_name="Quarterly run",
)Helper surface
API wrappers
Workflow helpers
| Function | Reference |
|---|---|
wait_for_batch_job_completion | Polls get_batch_jobs_job_id until a terminal job status is reached. |
submit_batch_job_and_wait | Calls post_batch_jobs_file, then waits for completion. |
Transport helpers
| Function | Reference |
|---|---|
request | Any API route; pass an arbitrary method and path. |
request_v1 | Any /v1/... route; convenience wrapper around request. |
get | Convenience wrapper over request for GET routes. |
post | Convenience wrapper over request for POST routes. |
put | Convenience wrapper over request for PUT routes. |
patch | Convenience wrapper over request for PATCH routes. |
delete | Convenience wrapper over request for DELETE routes. |
websocket | /docs/guides/websockets |