Skip to main content

ASP Studio for Python

PyPI Python License: MIT

ASP Studio shows the answer sets of an Answer Set Programming program, draws them as a graph, and steps through how a recursive program reaches its result. It works in Jupyter, in VS Code notebooks and from the command line. It uses the clingo Python API and shares its visualizer with the ASP Studio VS Code extension.

Playground · Documentation · Source · Issues

The ASP Studio visualizer

pip install "asp-studio[notebook]"      # Python 3.9 or newer

The notebook extra adds IPython for the %%asp magic. Without it you still get solve() and the command line.

In a notebook

%load_ext asp_studio
%%asp
parent(anna,bob). parent(bob,carl). parent(carl,eve).
ancestor(X,Y) :- parent(X,Y).
ancestor(X,Z) :- parent(X,Y), ancestor(Y,Z).

The output has four tabs. Animator steps through the rounds and shows which rule fired with which variable bindings. Answer Sets lists every model. Graph draws the atoms. Console shows clingo's messages and the position of any error.

Cell options:

Option Meaning
-n 5, --models 5 At most 5 answer sets (0 means all).
-o "--opt-mode=optN -c n=6" Extra clingo options. A value that starts with a dash is fine.
-t 20 Timeout in seconds. The default is 10.
--tab answers First tab to show: animator, answers, graph or console.
--theme dark auto (default), light or dark. Inside VS Code the editor theme is used.
--height 500 Starting height in pixels. The output grows with its content.
--out res Keep the result in a variable called res.

From Python

import asp_studio as asp

res = asp.solve("a :- not b. b :- not a.", models=0, timeout=10)
res.result          # 'SATISFIABLE'
list(res)           # [['b'], ['a']]
res.diagnostics     # positions of errors and warnings from clingo
res                 # as the last line of a cell: shows the visualizer
asp.show(res, tab="graph")

solve takes ASP text, a pathlib.Path, a (name, text) pair, or a list of those, which are joined in order. A broken program does not raise: check res.ok and res.error. Diagnostics carry the name of the file they came from. With #minimize or #maximize and a finished search, only the optimal models are kept, and their costs are in res.costs.

Attribute Meaning
res.ok, res.error Whether the program ran, and why not.
res.result SATISFIABLE, UNSATISFIABLE, OPTIMUM FOUND or UNKNOWN.
res.models, res.costs The answer sets as lists of atom strings, and their costs.
res.more True if you limited the models and more exist.
res.diagnostics Diagnostic(file, line, col, severity, message) entries.
res.ms, res.time Wall-clock milliseconds, and clingo's own total time.

Command line

asp-studio program.lp --open                # writes program.html and opens it
asp-studio instance.lp encoding.lp -n 3     # several files are joined in order
cat program.lp | asp-studio - --out report.html   # read standard input
asp-studio program.lp -o --opt-mode=optN    # extra clingo options
asp-studio --version
Option Meaning
-n, --models At most this many answer sets (0 means all).
-o, --options Extra clingo options.
-t, --timeout Timeout in seconds. The default is 10.
--out Output file, or a directory. The default is <first file>.html.
--tab, --theme First tab and color theme of the report.
--open Open the report in your browser.

The exit code is 0 when the program ran, 1 when it has an error (positions print as file:line:col) and 2 for bad arguments or unreadable input. python -m asp_studio does the same without the script on PATH.

Notes

  • The animator follows positive programs only: no not, choice rules, constraints or ranges. For other programs it names the unsupported line, and the other three tabs still work.
  • The visualizer runs in an isolated <iframe>. Jupyter shows such output only in trusted notebooks.
  • Outside notebooks and VS Code, the color theme follows the operating system.

Development

pip install -e ".[test]"
pytest
python sync_static.py     # copy ../media/{engine.js,webview.js,webview.css,themes.css} into the package

The visualizer files live in ../media and are copied into src/asp_studio/static. A test fails when the copies drift apart.

MIT license. Not affiliated with the Potassco team.

Metadata

Release files for asp-studio 0.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asp-studio 0.2.7
File Size Uploaded Provenance Actions
asp_studio-0.2.7.tar.gz 35.2 kB With provenance Details for asp_studio-0.2.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for asp-studio 0.2.7
File Interpreter ABI Platform Actions
asp_studio-0.2.7-py3-none-any.whl Python 3 none any Details for asp_studio-0.2.7-py3-none-any.whl

Total release size: 68.2 kB

Release files / asp_studio-0.2.7.tar.gz

Download URL asp_studio-0.2.7.tar.gz
Size 35.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b523573796d3a79d82774e01edbdec8d6f6350a17cd86ba4de7c64a5756a11e9
BLAKE2b-256 checksum
How to use checksums
a541e0744431efa55daebd9fd4cb9340d09df29d00460d473ae9125424a83ac6
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 8, 2026.

Transparency log

Release files / asp_studio-0.2.7-py3-none-any.whl

Download URL asp_studio-0.2.7-py3-none-any.whl
Size 33.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ae4c566b9582ae2b796535cfcb0f1659c083c0c16cbfed7a6155c7b1bf7d96d
BLAKE2b-256 checksum
How to use checksums
8b9f801e545dcd713e744f2f6591c046c3408fe913d25eceb8ddb0b3bcdaab22
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 8, 2026.

Transparency log

Security for asp-studio 0.2.7

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.

Select from 2 files

Attestation for asp_studio-0.2.7.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 8, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page