Quick Start — spx-sdk in 5 Minutes
(file: examples/hello_world_sensor.py)
Goal
Feel the entire journey—from pip install to a running simulation—then see how easy it is to bolt on new physics with a single class.
Prerequisites
Python
>=3.9 (tested 3.9–3.12)
pip
23+
pip install --upgrade spx-sdk # from PyPI
# or, for local dev
git clone https://github.com/HammerHeads-Engineers/spx-sdk.git
cd spx-sdk && pip install -e .Hello-World Sensor (60 s kettle run)
Create sensor.yaml
import yaml, numpy as np
from spx_sdk import Model
yaml_str = """
attributes:
temperature: 25.0 # °C
actions:
- function: $ext(temperature)
call: "$in(temperature) + (100 - $in(temperature)) \
* (1 - 0.945 ** $(.timer.time))" # slows as it nears 100 °C
"""
sensor = Model("Sensor", yaml.safe_load(yaml_str))
sensor.prepare();
for t in np.arange(0, 60.1, 0.1): # 0 → 60 s, 0.1 s ticks
sensor["timer"]["time"] = t # drive the built-in timer
sensor.run()
print(f"{t:4.1f}s ➜ {sensor['attributes']['temperature']['external_value']:.2f} °C")
import json, numpy as np
from spx_sdk import Model
json_str = json.dumps({
"attributes": {"temperature": 25.0},
"actions": [
{
"function": "$ext(temperature)",
"call": "$in(temperature) + (100 - $in(temperature)) * (1 - 0.945 ** $(.timer.time))"
}
]
})
model_def = json.loads(json_str)
# instantiate and run
sensor = Model(name="Sensor", definition=model_def)
sensor.prepare()
for t in np.arange(0, 60.1, 0.1):
sensor["timer"]["time"] = t
sensor.run()
print(f"{t:5.1f}s → {sensor['attributes']['temperature']['external_value']:.2f}°C")
What just happened?
Model
Alias for BaseModel; auto-installs a timer and polling component.
attributes:
Declares a temperature attribute (internal/external values handled for you).
function action
Runs every tick; $in reads, $ext writes; $(.timer.time) fetches simulated time.
prepare() → run()->run()->run()....
Two-phase loop: resolve parameters, then execute actions.
Extending in 30 Seconds
Add Newton-style cooling without touching core code.
Add it to the YAML—no other glue code required:
Run the same loop—now the curve approaches an equilibrium that balances heating and cooling.
Next Steps 🚀
Build reusable parts
link...
Create rich conditional logic
link...
Drive real hardware or protocols
link...
Unit-test your models
link...
Remember
Every class with @register_class is auto-registered at package import. No dummy imports, no boilerplate.
Happy modeling!—the SPX-SDK team
Last updated

