Skip to main content

Tasilab Python SDK

Tasilab is the first API-native paper trading sandbox for the Saudi Stock Exchange, empowering developers to build, test, and deploy AI-driven trading strategies with zero financial risk.

This package is the official Python client. Use it to pull historical TASI data, log backtests as experiments, and view results in the Tasilab dashboard.

Install

pip install tasilab

Quick start

from tasilab import Tasilab

tasi = Tasilab(api_key="YOUR_API_KEY")

# 1. Pull historical bars (Tasilab caches them for you)
hist = tasi.get_historical("1120", "2024-01-01", "2025-12-31")

# 2. Run your strategy locally → list of trade dicts
trades = my_strategy(hist["bars"])

# 3. Log the run as a Tasilab experiment (auto-seals on exit)
with tasi.create_experiment(
    name="MACD 12/26/9 on Al Rajhi",
    symbol="1120",
    start_date="2024-01-01",
    end_date="2025-12-31",
    parameters={"fast": 12, "slow": 26, "signal": 9},
) as exp:
    exp.log_trades(trades)
    exp.log_metrics({"total_return_sar": 439.64, "win_rate": 0.412})

The with block automatically marks the experiment completed on clean exit and failed if an exception propagates, so experiments never get stuck in running.

Paper trading

The SDK also supports live paper-trading against the simulated exchange:

order = tasi.buy("2222", quantity=100)
portfolio = tasi.portfolio()

See https://tasilab.com for the full surface.

The Lab

Thin wrappers over the Lab's REST endpoints. Every call returns the API's JSON unchanged — the SDK adds no client-side metrics of its own.

Edge Explorer — does a condition change what happens next?

conditions = tasi.list_conditions()          # what can be tested
situations = tasi.list_situations()          # the Guided Lab's presets

result = tasi.edge_explorer(
    "2222",
    {"type": "consecutive_down", "sessions": 3},
    period="5Y",
    forward_days=10,
)
print(result["data_version"])                # bars fingerprint — reproducible

Pass persist=False to compute without writing a row to Experiments. Use it for exploratory calls you do not want in run history.

Historical Testing — run a strategy over past bars:

print(tasi.backtest_limits())                # your tier's limits

run = tasi.backtest(
    "1120",
    period="3Y",
    strategy_type="ma_crossover",
    fast_ma="SMA", fast_period=10,
    slow_ma="SMA", slow_period=50,
    stop_loss_pct=0.05,
)

Which strategy fields apply depends on strategy_type — threshold, ma_crossover, price_ma_cross or macd_signal_cross. The API validates the combination and returns a 422 naming the offending field.

Model Test — a quick predictive model over the same history:

model = tasi.quick_predictor("2010", period="3Y", model="logreg")
for feature in model["feature_importances"]:
    print(feature["name"], feature["importance"], feature["direction"])

For LogReg the direction is meaningful. For Random Forest it is None and the value is an absolute mean-decrease-in-impurity score — an importance, not a signed coefficient. Do not read it as one.

License

Proprietary — see https://tasilab.com for terms.

Metadata

Release files for tasilab 0.2.1

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

Source distribution (sdist)

Source distribution for tasilab 0.2.1
File Size Uploaded Provenance Actions
tasilab-0.2.1.tar.gz 11.8 kB Without provenance Details for tasilab-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 22.1 kB

Release files / tasilab-0.2.1.tar.gz

Download URL tasilab-0.2.1.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0f90f46d85a818971fa6bffcc9486520892968018dd105ecd1f947068404dc96
BLAKE2b-256 checksum
How to use checksums
add8c340ed000c11d3bf2ceeaf84ff74914c7d526359330400c723104c06779a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / tasilab-0.2.1-py3-none-any.whl

Download URL tasilab-0.2.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97ec6dfaf3b41cb4c63f0ec411e0c116812338d307d720925245d306df2ad31d
BLAKE2b-256 checksum
How to use checksums
dd57b70bd2282803252bf30e69d3ff51ff426eb145a8252bb020cd89d7e8a15f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for tasilab 0.2.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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