Skip to main content

Python client for the Drishti API (/v1)

Project description

Drishti SDK (Python)

Official Python SDK for the Manasija Drishti API (/v1).

This SDK provides:

  • A synchronous HTTP client with named-argument endpoint helpers
  • A low-level request interface for advanced/custom usage
  • A WebSocket client for real-time streams (/v1/ws)
  • Configurable retry/backoff for transient HTTP failures

Requirements

  • Python 3.10+
  • A valid Drishti API key

Installation

pip install drishti-sdk

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"]))

All requests automatically include X-API-Key using the provided api_key.

Retry Configuration

Retries are configurable globally on the client and per request.

from drishti_sdk import DrishtiClient

with DrishtiClient(
    api_key="YOUR_API_KEY",
    retry_max_retries=3,
    retry_initial_delay=0.25,
    retry_max_delay=4.0,
    retry_multiplier=2.0,
    retry_on_statuses=(408, 429, 500, 502, 503, 504),
) as client:
    # Per-request override
    news = client.request(
        "GET",
        "/v1/news",
        params={"limit": 10},
        retry_max_retries=1,
    )

HTTP Usage

from drishti_sdk import DrishtiClient

with DrishtiClient(api_key="YOUR_API_KEY") as client:
    announcements = client.get_announcements(
        symbols=["RELIANCE"],
        categories=["Corporate Action"],
        important=True,
        detailed=True,
        limit=20,
    )

    earnings = client.get_earnings_detail(
        symbol="MEDIASSIST",
        quarter="q4_26",
        detailed=True,
    )

    transcript = client.get_concalls_transcript(
        symbol="TCS",
        quarter="q4_26",
    )

    alerts = client.get_alerts(
        symbols=["INFY"],
        important=True,
        limit=25,
    )

Error Handling

from drishti_sdk import DrishtiApiError, DrishtiClient

try:
    with DrishtiClient(api_key="YOUR_API_KEY") as client:
        client.get_account()
except DrishtiApiError as exc:
    print(exc.status_code)
    print(exc.body)
    raise

WebSocket Usage (/v1/ws)

import asyncio
from drishti_sdk import DrishtiClient, SubscribeOptions


async def main() -> None:
    client = DrishtiClient(api_key="YOUR_API_KEY")
    async with client.websocket() as ws:
        await ws.subscribe(
            SubscribeOptions(
                product="announcements",
                symbols=["RELIANCE"],
                detailed=False,
            )
        )
        async for event in ws.events():
            if event.kind == "subscribed":
                print("ready", event.product, event.tier)
            elif event.kind == "data":
                print(event.channel, event.data)


asyncio.run(main())

Callback style:

async with client.websocket(
    reconnect_initial_delay=1.0,
    reconnect_max_delay=30.0,
    on_reconnect_attempt=lambda attempt, delay, reason: print(attempt, delay, reason),
    on_data=lambda event: print(event.data) if event.kind == "data" else None,
    on_announcements=lambda announcement: print("announcement", announcement),
    on_alerts=lambda alert: print("alert", alert),
) as ws:
    await ws.subscribe("alerts", symbols=["RELIANCE"])
    await asyncio.Event().wait()  # callbacks run in the background; Ctrl+C to stop

Register listeners after connect:

def on_announcement(announcement: dict[str, object]) -> None:
    print("announcement", announcement)

ws.on_announcements(on_announcement)
ws.off("announcements", on_announcement)

WebSocket Reference

The WebSocket session is created from the HTTP client, so it inherits the same api_key and base_url settings. The session connects to /v1/ws and sends X-API-Key on connect.

Supported subscription products:

  • news
  • announcements
  • earnings
  • concalls
  • alerts

Useful session options:

  • reconnect_initial_delay
  • reconnect_max_delay
  • reconnect_backoff_multiplier
  • reconnect_jitter_ratio
  • reconnect_warn_after_attempts
  • ping_interval
  • ping_timeout
  • open_timeout
  • close_timeout
  • max_queue
  • on_subscribed
  • on_data
  • on_news
  • on_announcements
  • on_earnings
  • on_concalls
  • on_alerts
  • on_error
  • on_message
  • on_open
  • on_close
  • on_reconnect_attempt
  • on_reconnect_warning

The session connects automatically on the first async call (subscribe, events, or entering an async with block) and keeps retrying in the background after disconnects.

Subscription messages accept either SubscribeOptions(...) or the product name as a string. Symbols are normalized to uppercase and de-duplicated before the message is sent. Subscriptions are replayed after every reconnect.

Event shapes:

  • subscribed: acknowledgement with product, tier, full_feed, symbols, and detailed
  • data: payload event with channel and data
  • error: error event with message and optional code
  • raw: unclassified JSON payload

Direct exports available from drishti_sdk:

  • DRISHTI_WS_PRODUCTS
  • SubscribeOptions
  • DrishtiWebSocketSession
  • DrishtiWebSocketClientSessionOptions
  • DataEvent
  • ErrorEvent
  • RawEvent
  • SubscribedEvent
  • WebSocketEvent
  • build_websocket_url
  • parse_websocket_message
  • stream_product

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",
    )

    status = client.get_batch_jobs_job_id(job_id=job["id"])

Wait until completion:

final_job = client.wait_for_batch_job_completion(
    job_id=job["id"],
    poll_interval=2.0,
    timeout=300.0,
)

Submit and wait in one call:

final_job = client.submit_batch_job_and_wait(
    file_name="batch.jsonl",
    file_bytes=file_bytes,
    display_name="Quarterly run",
    poll_interval=2.0,
    timeout=300.0,
)

API Surface

REST helper methods

  • get_news
  • get_symbols_metadata
  • get_announcements_categories
  • get_announcements
  • get_announcements_attachments
  • post_daily_summary
  • get_earnings
  • get_earnings_detail
  • get_earnings_attachments
  • get_concalls
  • get_upcoming_concalls
  • get_concalls_detail
  • get_concalls_transcript
  • post_concalls_transcripts
  • get_alerts
  • get_account
  • get_account_limits
  • get_account_usage
  • get_account_ledger
  • post_batch_jobs
  • post_batch_jobs_file
  • get_batch_jobs
  • get_batch_jobs_job_id
  • delete_batch_jobs_job_id
  • get_batch_jobs_job_id_results
  • wait_for_batch_job_completion
  • submit_batch_job_and_wait
  • websocket

Low-level HTTP methods

  • request
  • get
  • post
  • put
  • patch
  • delete
  • request_v1

Development

pip install -e .[dev]

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

drishti_sdk-1.0.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

drishti_sdk-1.0.0-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file drishti_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: drishti_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for drishti_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f499f826045a69a87824246a99b3106e7991b4561ff96534e1e1034395b7f8e1
MD5 a99496bcf145757a3cf816559d465431
BLAKE2b-256 aa057a3af1fac6e60b4fb8523dbda71611755c6177dc1f99509c617ae4327742

See more details on using hashes here.

Provenance

The following attestation bundles were made for drishti_sdk-1.0.0.tar.gz:

Publisher: publish-pypi.yml on manasijatech/drishti-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drishti_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: drishti_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for drishti_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c410a08c6fa9acb2960f718985f0e4b26a2101816ecebe8c8a5b6848eb04634
MD5 68c29aac5eb9f1c80f9a5753487b2258
BLAKE2b-256 e41d0abcb4523dd9a8658be9848183d7cc38f95ae72100d87fb9383b41bb48c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for drishti_sdk-1.0.0-py3-none-any.whl:

Publisher: publish-pypi.yml on manasijatech/drishti-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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