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.3.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.3.0
File Size Uploaded Provenance Actions
sahiapi-0.3.0.tar.gz 52.6 kB With provenance Details for sahiapi-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 113.5 kB

Release files / sahiapi-0.3.0.tar.gz

Download URL sahiapi-0.3.0.tar.gz
Size 52.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8012e19df5d6b15e11b6a78d3933ce4ec109689da63982f292b3099f8ba34964
BLAKE2b-256 checksum
How to use checksums
da7168134d05b9a7c0ac97c8814453f1bb268612746fa7114d6dba16839aa9ba
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 Oct 29, 2026.

Transparency log

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

Download URL sahiapi-0.3.0-py3-none-any.whl
Size 60.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e90b0c059ee9d57929721777715fdaeec897d0f9a58d7621adf67e32c91ed6c
BLAKE2b-256 checksum
How to use checksums
cd179a67052c75d943c5cee3cc1b201fb3c154786f2a1edb42d1653a1b683517
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 Oct 29, 2026.

Transparency log

Security for sahiapi 0.3.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.3.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 Oct 29, 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