Skip to main content

sahiapi

The official Python SDK for the Sahi trading APIs.

Build trading and investing workflows in Python: place and manage orders, track holdings, positions and funds, pull quotes, candles and option chains, and receive live ticks and order updates over WebSocket.

Sahi © 2026. Released under the MIT License.

Documentation

Features

  • Orders: place, modify and cancel orders, and read the order book and the trades behind each order.
  • Portfolio: holdings and open positions.
  • Funds: available balance and margin in use.
  • Market data: LTP and quotes for many instruments in one call, historical candles, option expiries and option chains.
  • Live streams: SahiFeed streams LTP, quotes and market depth, plus order updates, and reconnects and resubscribes on its own.
  • Typed errors: every API failure raises an exception carrying the HTTP status, error code, request id and a hint on how to fix it.

Installation

pip install sahiapi

Requires Python 3.9 or newer.

Quickstart

Create an API key in your Sahi account and approve it for the trading day, then connect:

import os
from sahiapi import SahiAPI

api = SahiAPI.from_credentials(
    key_id=os.environ["SAHI_KEY_ID"],
    secret=os.environ["SAHI_SECRET"],
)
print(api.get_profile())
print(api.get_funds())

For a TOTP key, also pass the current authenticator code as totp. See Mint with a TOTP key.

Example: place a limit order

Prices are in paise, so ₹2,499.55 is 249955.

response = api.place_order(
    exchange_segment=SahiAPI.EXCHANGE_SEGMENT_NSE,
    symbol="RELIANCE",
    txn_type=SahiAPI.TXN_TYPE_BUY,
    qty=1,
    order_type=SahiAPI.ORDER_TYPE_LIMIT,
    product=SahiAPI.PRODUCT_DELIVERY,
    validity=SahiAPI.VALIDITY_DAY,
    price=249955,
)
order_id = response["order_ids"][0]
print(api.get_order_detail(order_id))

See the Python SDK documentation for streaming, market data and every other endpoint.

Metadata

Release files for sahiapi 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sahiapi 0.4.0
File Size Uploaded Provenance Actions
sahiapi-0.4.0.tar.gz 52.8 kB With provenance Details for sahiapi-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sahiapi 0.4.0
File Interpreter ABI Platform Actions
sahiapi-0.4.0-py3-none-any.whl Python 3 none any Details for sahiapi-0.4.0-py3-none-any.whl

Total release size: 113.9 kB

Release files / sahiapi-0.4.0.tar.gz

Download URL sahiapi-0.4.0.tar.gz
Size 52.8 kB
Tags Source
SHA-256 checksum
How to use checksums
413ebda84a6c8b53b3f191d68b9d3b452f15b9d79d9a5f9df56b47efb692fd6d
BLAKE2b-256 checksum
How to use checksums
339bd86eb0d539bd4a4eb9a0ef60fe008e3dcf58fd1bb673f7e2d380196d122a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / sahiapi-0.4.0-py3-none-any.whl

Download URL sahiapi-0.4.0-py3-none-any.whl
Size 61.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f5f136131ef98c8ce3d383cec79f9243d6c6848c0320599c1b071b3e076a1bd
BLAKE2b-256 checksum
How to use checksums
79d831baa3db91be69e3b283d8b907ebf8e38b4f943015392ea36d4402251d27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for sahiapi 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sahiapi-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page