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.1.0.tar.gz (11.0 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.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for simulacrum_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1d683543129e015d3029f5beb134c535f413837593a5bdabacba291815ac730b
MD5 8e99c3504292890c3c50433d65d84ebc
BLAKE2b-256 9bfe2c722cdcff80763fb744940f2d3a15826559bf8b06f76a09fc6b1774b1b9

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for simulacrum_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e814ea6dc63fa611614d662306ce21d9d2e14a0b9df9773dbecf81e5bf5c7a35
MD5 231310460f494e8f4e6ad50e648739e1
BLAKE2b-256 fa474a96cb0c1a5f78fca4ce1b9ed8617e29621b33a3332cd9a7ba9b5b22ef34

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