Skip to main content

ASP Studio for Python

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.

Website and live demo: https://yakupbulbul.github.io/asp-vscode/

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.
-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, or a list of those, which are joined in order. A broken program does not raise: check res.ok and res.error. With #minimize or #maximize and a finished search, only the optimal models are kept, and their costs are in res.costs.

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
python -m asp_studio program.lp             # the same, without the script on PATH

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.

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

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.1.0
File Size Uploaded Provenance Actions
asp_studio-0.1.0.tar.gz 32.4 kB With provenance Details for asp_studio-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 63.3 kB

Release files / asp_studio-0.1.0.tar.gz

Download URL asp_studio-0.1.0.tar.gz
Size 32.4 kB
Tags Source
SHA-256 checksum
How to use checksums
27e3ba5202f275084642efc35724d2af28af9eb2b6f49e4df1f617b91d3c3958
BLAKE2b-256 checksum
How to use checksums
54588be4e41f21fbaa8e6f683f4bcbfb37c82f5c055c3c61c42bfe758117a014
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 5, 2026.

Transparency log

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

Download URL asp_studio-0.1.0-py3-none-any.whl
Size 30.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12cbfba4d865ab059b7656565d62452a8c41d05a7352497f100af0595a8ca545
BLAKE2b-256 checksum
How to use checksums
4e9458e257e62ccf167df79e90e9eb17d1ded24f6c381d22cefe2e56aa4a12c9
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 5, 2026.

Transparency log

Security for asp-studio 0.1.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.

Select from 2 files

Attestation for asp_studio-0.1.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 5, 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