Python SDK
Thin Python wrapper for the Sematryx REST API, with optional local fallback using scipy for callable objectives.
PyPI release coming soon. The SDK is available now via
pip install sematryx once published. Until then, install directly:pip install git+https://github.com/smartofficialintelligence/sematryx-sdk.gitInstall the Python SDK (when published)
pip install sematryxRequires Python 3.8+. For local optimization without an API key, install the local extra:
Install with local solver support
pip install sematryx[local] # includes scipy + numpyPass a Python callable to run the optimization locally using scipy. No API key or network connection required.
Local optimization with a Python function
from sematryx import optimize
# Local mode: pass a Python callable — no API key needed
def sphere(x):
return sum(xi**2 for xi in x)
result = optimize(
objective_function=sphere,
bounds=[[-5, 5], [-5, 5]],
max_evaluations=1000,
)
print(f"Solution: {result.solution}")
print(f"Value: {result.objective_value}")Pass a math expression string to run the optimization on the Sematryx cloud. Requires an API key.
Cloud optimization with an expression
from sematryx import optimize
# Cloud mode: pass a math expression string — requires API key
result = optimize(
objective_function="x[0]**2 + x[1]**2",
bounds=[[-5, 5], [-5, 5]],
max_evaluations=1000,
api_key="smtrx_...", # or set SEMATRYX_API_KEY env var
strategy="auto", # auto | differential_evolution | cma_es | …
)
print(f"Solution: {result.solution}")
print(f"Value: {result.objective_value}")