Skip to main content

Lightweight Python client for the SAHMK Developer API.

Project description

SAHMK Python SDK

A lightweight Python client for the SAHMK Developer API — real-time and historical Saudi stock market (Tadawul) data.

Features

  • Real-time quotes — live prices for 350+ Tadawul stocks
  • Batch quotes — up to 50 stocks in a single request
  • Historical data — daily/weekly/monthly OHLCV with custom date ranges
  • Market overview — TASI index, gainers, losers, volume/value leaders, sectors
  • Company info — fundamentals, technicals, valuation, analyst consensus (by plan)
  • Financials — income statements, balance sheets, cash flow
  • Dividends — history, yield, upcoming payments
  • Events — AI-generated stock event summaries
  • WebSocket streaming — real-time price updates pushed to you (Pro+ plan)

Installation

After the first PyPI release:

pip install sahmk

Or clone this repo for local development:

git clone https://github.com/sahmk-sa/sahmk-python.git
cd sahmk-python
pip install -r requirements.txt

Quick Start

from sahmk import SahmkClient

client = SahmkClient("your_api_key")

# Get a stock quote
quote = client.quote("2222")
print(f"{quote['name_en']}: {quote['price']} SAR ({quote['change_percent']}%)")

# Get market summary
market = client.market_summary()
print(f"TASI: {market['index_value']} ({market['index_change_percent']}%)")

# Batch quotes (Starter+ plan)
result = client.quotes(["2222", "1120", "4191"])
for q in result["quotes"]:
    print(f"{q['symbol']}: {q['price']}")

Get Your API Key

  1. Sign up at sahmk.sa/developers
  2. Verify your email
  3. Go to Dashboard → API Keys → Create Key
  4. Copy your key (starts with shmk_live_ or shmk_test_)

Plans

Plan Price Requests/Day WebSocket
Free 0 SAR 100 -
Starter 149 SAR/mo 5,000 -
Pro 499 SAR/mo 50,000 Yes
Enterprise 1,499+ SAR/mo Unlimited Yes

Examples

Check the examples/ directory:

File Description
quote.py Get a single stock quote
batch_quotes.py Fetch multiple stocks at once
historical.py Historical price data
market_summary.py Market overview and movers
websocket_stream.py Real-time WebSocket streaming (Pro+)

API Reference

Base URL: https://app.sahmk.sa/api/v1

Endpoint Plan Description
GET /quote/{symbol}/ Free Stock quote
GET /quotes/?symbols=... Starter+ Batch quotes (up to 50)
GET /historical/{symbol}/ Starter+ Historical OHLCV data
GET /market/summary/ Free Market overview & TASI index
GET /market/gainers/ Free Top gainers
GET /market/losers/ Free Top losers
GET /market/volume/ Free Volume leaders
GET /market/value/ Free Value leaders
GET /market/sectors/ Free Sector performance
GET /company/{symbol}/ Free+ Company info (tiered by plan)
GET /financials/{symbol}/ Starter+ Financial statements
GET /dividends/{symbol}/ Starter+ Dividend history & yield
GET /events/ Pro+ AI-generated stock events

All endpoints require the X-API-Key header.

Full docs: sahmk.sa/developers/docs

WebSocket Streaming (Pro+)

import asyncio
from sahmk import SahmkClient

client = SahmkClient("your_api_key")

async def on_quote(msg):
    symbol = msg["symbol"]
    price = msg["data"]["price"]
    print(f"{symbol}: {price}")

asyncio.run(client.stream(["2222", "1120"], on_quote=on_quote))

Connection URL: wss://app.sahmk.sa/ws/v1/stocks/?api_key=YOUR_KEY

License

MIT — see LICENSE

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

sahmk-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

sahmk-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file sahmk-0.1.0.tar.gz.

File metadata

  • Download URL: sahmk-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sahmk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b17db08effa5ce118bd65fa8a3a48cd75ef314955ed61ea0e84bff1ea9229a94
MD5 825268720bce1994e2c31dc7b7210435
BLAKE2b-256 875145a586d28519fa8015ecd21adc1b00841c869e3170f969d1abe1ffca6ef8

See more details on using hashes here.

Provenance

The following attestation bundles were made for sahmk-0.1.0.tar.gz:

Publisher: publish-pypi.yml on sahmk-sa/sahmk-python

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

File details

Details for the file sahmk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sahmk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sahmk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91fe87f49d2b653c58834d42998d0b485026d3dff8afd65a84ad8f128a733aeb
MD5 a4c949ebf100c11dd855be29f19424ef
BLAKE2b-256 6f63992f266b28921099abcf2a11328e391058df53dd5edb0bfd26448743e25f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sahmk-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on sahmk-sa/sahmk-python

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