Skip to main content

Python Client for LawSaathi - The Most Capable LEGAL AI

Project description

LawSaathi Python SDK

PyPI version Python versions License: MIT

Python Client for LawSaathi — The Most Capable LEGAL AI.

Installation

pip install lawsaathi

# With WebSocket streaming support:
pip install lawsaathi[websocket]

Quick Start

from lawsaathi import LawSaathi

client = LawSaathi(api_key="ls_live_your_api_key_here")

# Ask any legal question
response = client.chat("What is IPC Section 302?")
print(response['response'])
print(f"Tokens used: {response['usage']['total_tokens']}")
print(f"Cost: ₹{response['usage']['cost_rupees']}")

File Attachments (OpenAI-style)

Attach files to your queries — just pass file paths. The SDK handles uploading automatically.

# Analyze a contract — just pass the file path!
response = client.chat(
    "Summarize the key clauses in this contract",
    files=["contract.pdf"]
)
print(response['response'])

# Multiple files work too
response = client.chat(
    "Compare these two agreements",
    files=["agreement_v1.pdf", "agreement_v2.pdf"]
)

Streaming (WebSocket)

# Requires: pip install lawsaathi[websocket]
for chunk in client.stream("Explain bail provisions under CrPC"):
    print(chunk, end="", flush=True)

# Streaming with files
for chunk in client.stream("Analyze this document", files=["contract.pdf"]):
    print(chunk, end="", flush=True)

Check Balance

balance = client.get_balance()
print(f"Balance: ₹{balance['balance_rupees']}")
print(f"Tokens available: {balance['tokens_available']:,}")

Error Handling

from lawsaathi import (
    LawSaathi,
    AuthenticationError,
    RateLimitError,
    InsufficientCreditsError,
    APIError,
)

client = LawSaathi(api_key="ls_live_your_key")

try:
    response = client.chat("Hello")
except AuthenticationError:
    print("Invalid API key — check or regenerate it")
except InsufficientCreditsError as e:
    print(f"Not enough credits. Balance: ₹{e.balance_rupees}")
except RateLimitError as e:
    print(f"Rate limited. Retry after: {e.retry_after}s")
except APIError as e:
    print(f"API error ({e.status_code}): {e}")

Pricing

Cost per 1M tokens ₹998
Free credits on signup ₹100
Minimum topup ₹999
Credit expiry 150 days

Rate Limits

Limit Default
Requests/minute 5
Requests/day 2,500
Max file size 100 MB

Need higher limits? Request a quota increase from the Developer Dashboard.

Requirements

  • Python 3.8+
  • requests library (installed automatically)
  • websocket-client (optional, for streaming)

Links

License

MIT License — see LICENSE for details.

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

lawsaathi-1.0.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

lawsaathi-1.0.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file lawsaathi-1.0.1.tar.gz.

File metadata

  • Download URL: lawsaathi-1.0.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for lawsaathi-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7cd5e4fe3786e7897f9c6b68b5780ff32a47670e66ca2e2db4bf4bd7ab2a3c37
MD5 9ded52e0ef8fbfef83742dde8bd274a6
BLAKE2b-256 c4a837174244b6b0cfbac00ba5f5d536cdf040896f0c220502f72f260e269498

See more details on using hashes here.

File details

Details for the file lawsaathi-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: lawsaathi-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for lawsaathi-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 830af2086bc7870e712f42e4321a443cbae2ecd17bd83a53caf458ea5c31effd
MD5 ff356d6ad9a96a737f152bf20fadfc7b
BLAKE2b-256 f4641ee305b7e20c08b4b656a9d22ea71005bf1b3dbddb298a4bd67758eb4229

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