specsolve
Optimisation as a data pipeline. Tables in, polars builds the model, tables out. Every solve can be kept as parquet, to query, share or solve again.
specsolve solves linear and mixed-integer models from tables. You pass a model file and your data as Arrow tables or parquet paths. specsolve builds the model on polars, hands it to HiGHS, Gurobi or Xpress, and returns tidy tables. The model file is written in mathspec, which states the math and checks it before any data exists.
- Tables in, tables out. Pass any Arrow table, such as polars, pandas or DuckDB, or a parquet path. Each variable, dual and expression comes back as a tidy table with one row per coordinate. Your data →
- Every solve is an archive.
archive=writes the model, its data and its answer as parquet, with the solver and versions that made it.scan_archivereads it where it lies and solves the same question again, and a directory of runs reads as one set of tables. Archiving a solve → - Fast from the first call. A script that builds one small model and hands
it to the solver finishes in about half a second, about half of linopy's time
(#2031). The solver stays
loaded:
update()puts new numbers on it, and the next solve carries on from where the last one ended. Benchmarks → - No slow way to write a model. In linopy or Pyomo, the model is Python code, and slow code builds slowly. A specsolve model is a YAML file with data attached, and specsolve makes sure it builds fast. Coming from linopy →
- Sweeps and rolling horizons built in. One call runs scenario sweeps, rolling horizons and myopic pathways over the same model. specsolve checks each window against how the model couples before it runs. A horizon too large for one solve →
- Validated against PyPSA. PyPSA's model is one file here, grown rung by rung through storage, unit commitment, multi-period and stochastic runs. All 58 rungs match PyPSA's objective, and 36 match its duals row for row. The PyPSA ladder →
Example
# dispatch.yaml
dimensions:
snapshot: {dtype: int, ordered: true}
generator: {dtype: str}
parameters:
p_max: {dims: [generator]}
load: {dims: [snapshot]}
cost: {dims: [generator]}
variables:
p:
dims: [snapshot, generator]
where: "p_max > 0"
bounds: {lower: 0, upper: p_max}
constraints:
power_balance:
dims: [snapshot]
expression: sum(p, over=generator) == load
objective:
sense: minimize
expression: sum(p * cost)
import specsolve as sps, polars as pl
generators = ['wind', 'solar', 'gas']
sources = { # (1)!
'p_max': pl.DataFrame({'generator': generators, 'value': [100.0, 60.0, 200.0]}),
'cost': pl.DataFrame({'generator': generators, 'value': [1.0, 2.0, 50.0]}),
'load': pl.DataFrame({'snapshot': range(6), 'value': [80.0, 120.0, 150.0, 180.0, 140.0, 100.0]}),
'snapshot': range(6),
'generator': generators,
}
result = sps.solve('dispatch.yaml', sources, archive='runs/base/') # (2)!
print(result.objective) # 1920.0
print(result.primal('p')) # (3)!
print(result.dual('power_balance'))
base = sps.scan_archive('runs/base/') # (4)!
print(base.result.primal('p').group_by('generator').agg(pl.col('value').sum()))
- A source is any table: polars, pandas, pyarrow or DuckDB. It can also be a
parquet path, such as
'load': 'load.parquet'. archive=writes the spec, the data and the answer toruns/base/as parquet files.- A tidy table, with one row per snapshot and generator.
scan_archivereads the archive where it lies.base.sourcesare parquet paths, sosps.solve(base.spec, base.sources)asks the same question again.
Documentation
The documentation is at https://specsolve.readthedocs.io. What a file may contain is mathspec's language reference.
Installation
pip install specsolve
That brings polars, HiGHS and the language. Add the [gurobi] or [xpress]
extra for those solvers. The bridges out of a result, to_pandas and
to_dataarray, need pandas and xarray, which you install yourself. To work on
specsolve, see
CONTRIBUTING.md.
Prior art
The YAML surface comes from Calliope, and linopy supplies the vocabulary, the oracle and every benchmark denominator. Prior art and credit says what came from each.
Status
Alpha, pre-1.0.
Breaking changes land without a deprecation cycle. Pin an exact version if you depend on this, and read the changelog before upgrading. A retired spelling fails at load and names its rewrite. Real models round-trip through solve and are tested against linopy. The accepted surface is not yet frozen.
Licence
MIT.
Metadata
Release files for specsolve 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| specsolve-0.11.0.tar.gz | 182.9 kB | With provenance | Details for specsolve-0.11.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| specsolve-0.11.0-py3-none-any.whl | Python 3 | none | any | Details for specsolve-0.11.0-py3-none-any.whl |
Total release size: 393.5 kB
Release files / specsolve-0.11.0.tar.gz
| Download URL | specsolve-0.11.0.tar.gz |
|---|---|
| Size | 182.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdc9c43f1a596173dca360a42b98d095e9f88b86cc360866688fb1f26fc57b0d
|
|
BLAKE2b-256 checksum How to use checksums |
fd87e7fdb4cbaaa0da2886eaee2004832f3524fc1a9d89f1c7ba8b113e8230b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logRelease files / specsolve-0.11.0-py3-none-any.whl
| Download URL | specsolve-0.11.0-py3-none-any.whl |
|---|---|
| Size | 210.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a9d52aa0c57b939cb1c113fcb2d25edb4a3b9ccbba2e0d1a0c09bba5af164767
|
|
BLAKE2b-256 checksum How to use checksums |
5bd9a5261cff930d9bb13e202fcb0b7316df57c62e958dd56c144783ab482c08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logSecurity for specsolve 0.11.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for specsolve-0.11.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logA 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.