Skip to main content

Official Python SDK for accessing the Simulacrum API.

Project description

Simulacrum Logo

Simulacrum SDK

A lightweight Python client for the Simulacrum time-series forecasting API. The SDK wraps Simulacrum's REST endpoints with type-safe models, error handling, and convenience helpers so you can focus on building forecasting workflows instead of wiring HTTP requests.


Features

  • 🔐 Authenticated client with automatic bearer-token headers
  • 📈 Forecast API wrapper that serialises NumPy arrays transparently
  • API key validation to inspect key status, client ID, and expiry
  • 🚫 Rich exceptions that map Simulacrum error codes to Python types
  • 🧪 Tested models built on Pydantic for strict data validation

Installation

From PyPI (recommended)

Requires Python 3.8 or newer

pip install simulacrum-sdk

From GitHub source

Install directly from the latest commit on the main repository:

pip install git+https://github.com/Smlcrm/simulacrum-sdk.git

To work with the sources locally for development (Python 3.8+):

git clone https://github.com/Smlcrm/simulacrum-sdk.git
cd simulacrum-sdk
python -m venv .venv
source .venv/bin/activate  # On Windows use: .venv\Scripts\activate
pip install -e .[dev]

Usage Overview

Creating a client

from simulacrum import Simulacrum

client = Simulacrum(api_key="sp_your_api_key")

If you are running a local version of the Simulacrum API (i.e., on-premise model hosting), override the base URL:

client = Simulacrum(api_key="sp_your_api_key", base_url="https://staging.api.smlcrm.com")

Validating an API key

Your forecast requests will fail if your API key is invalid. To check your API key is valid run the following.

validation = client.validate()
print("Valid:", validation.valid)
print("Client ID:", validation.client)

Requesting a forecast

import numpy as np

series = np.array([102.4, 106.0, 108.3, 111.9])
forecast = client.forecast(series=series, horizon=3, model="default")

print("Next periods:", forecast)

The SDK returns a numpy.ndarray so you can pipe results into downstream analytics or visualisations immediately.

Handling errors

All API error codes are mapped to dedicated exceptions. Catch them to distinguish between authentication, quota, and request issues:

from simulacrum.exceptions import AuthError, QuotaExceededError, SimulacrumError

try:
    client.forecast(series=[1, 2, 3], horizon=5, model="default")
except AuthError:
    print("Check that your API key is correct and active.")
except QuotaExceededError:
    print("You have reached your usage limit for the current period.")
except SimulacrumError as exc:
    print(f"Unhandled Simulacrum error: {exc}")

Tutorial: Forecast a Time Series in Five Steps

  1. Install the SDK

    pip install simulacrum-sdk
    
  2. Create a project structure

    mkdir simulacrum-sample && cd simulacrum-sample
    python -m venv .venv
    source .venv/bin/activate
    pip install simulacrum-sdk
    
  3. Write a forecast script (forecast_example.py)

    from simulacrum import Simulacrum
    
    def main() -> None:
        client = Simulacrum(api_key="sp_your_api_key")
        series = [24.5, 25.1, 25.7, 26.2, 26.9]
        forecast = client.forecast(series=series, horizon=3, model="default")
        print("Forecast:", forecast.tolist())
    
    if __name__ == "__main__":
        main()
    
  4. Validate your API key (optional)

    validation = client.validate()
    if validation.valid:
        print("Key is active until", validation.expires_at)
    
  5. Run the script

    python forecast_example.py
    

This workflow demonstrates the complete loop: initialising the client, requesting a forecast, and checking key status.


Documentation

The public API is intentionally small:

Component Description
simulacrum.Simulacrum High-level client exposing forecast() and validate() methods.
simulacrum.models.ForecastRequest Pydantic model ensuring forecast payloads are well-formed.
simulacrum.models.ForecastResponse Wraps forecast results and exposes get_forecast() to return a numpy.ndarray.
simulacrum.models.ValidateAPIKeyResponse Validation metadata returned by Simulacrum.validate().
simulacrum.exceptions.* Custom error hierarchy mapping Simulacrum error codes to Python exceptions.

Explore inline docstrings for detailed parameter and return type information. The tests in tests/test_client.py demonstrate advanced usage patterns and validation behavior.

If you are contributing, run the suite with:

pip install -e .[dev]
python -m pytest

License

MIT © Simulacrum, Inc.

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

simulacrum_sdk-0.2.5.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

simulacrum_sdk-0.2.5-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file simulacrum_sdk-0.2.5.tar.gz.

File metadata

  • Download URL: simulacrum_sdk-0.2.5.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for simulacrum_sdk-0.2.5.tar.gz
Algorithm Hash digest
SHA256 e75f8d4fc2f9eb29f16149cdece93a2450c081316f697041813483e79a348320
MD5 6abc3d8d5ee171478939de0b14fffd01
BLAKE2b-256 5c1d2257b4c389256aa6875d9f242bddf61002a33444abd37721b56ed6cf0319

See more details on using hashes here.

File details

Details for the file simulacrum_sdk-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: simulacrum_sdk-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for simulacrum_sdk-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 479572c220c56ed3c8fa674f857e81d45aa4747baef4ad10862f4244a713880c
MD5 bc8c1c168dcbab90048f85c009e68a0e
BLAKE2b-256 650b3a3e1d2bec9305f85c34e73cfb375c9df2166473cd7c3aa9399d48e1d1e6

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