Skip to main content

PythonAlloyClient

This is a Python client library for interacting with the Alloy Language Server. Currently, it supports checking the syntax of a given Alloy code snippet with the Alloy language server, but more features are planned for the future to make use of the full capabilities of the Alloy language server.

Installation

You can install the package from PyPI using pip.

pip install PythonAlloyClient

Or install directly from the source.

git clone https://github.com/mrigankpawagi/PythonAlloyClient.git
cd PythonAlloyClient
pip install -e .

Requirements

  • Python 3.6+
  • Java Virtual Machine (JVM) 17 or later for running the Alloy language server

Usage

Basic Usage

from PythonAlloyClient import AlloyServer

server = AlloyServer() # Initialize the server
server.start() # Start the server

syntax_status = server.check_syntax("sig Person {}")
server.stop() # Stop the server

print(syntax_status.success) # True

Once the server is started, you can use the check_syntax method to check the syntax of an Alloy code snippet which is supplied as a string. The method returns a SyntaxStatus object with the following attributes.

  • success (bool): True if the syntax check passed, False otherwise
  • error_type (str): Type of error (always Syntax error for now), None if success is True
  • line_number (int): Line number where the error occurred, None if success is True
  • column_number (int): Column number where the error occurred, None if success is True
  • error_message (str): Error message, None if success is True
  • full_error_message (str): Full error message from Alloy, None if success is True

If a syntax check failed due to an unexpected error, the full_error_message attribute will contain the error message, success will be False, and all other attributes will be None.

Another Example

alloy_code = """
sig X {}
sig A extends X {}
sig A extends X {}
"""
syntax_check = server.check_syntax(alloy_code)

print(syntax_check.success) # False
print(syntax_check.error_type) # Syntax error
print(syntax_check.line_number) # 4
print(syntax_check.column_number) # 5
print(syntax_check.error_message) # "A" is already the name of a sig/parameter in this module.

Custom Alloy Build

By default, PythonAlloyClient uses the JAR file at PythonAlloyClient/resources/org.alloytools.alloy.dist.jar to run the Alloy language server. If you want to use a custom build of the Alloy language server, you can specify the path to the JAR file when initializing the AlloyServer object.

from PythonAlloyClient import AlloyServer

server = AlloyServer(alloy_jar_path="path/to/alloy.jar")

Other Options

PythonAlloyClient can print logs about the server's status and the requests being made to the server by setting the quiet attribute to False. This is set to True by default.

from PythonAlloyClient import AlloyServer

server = AlloyServer(quiet=False)

You can also set the try_get_diagnostics parameter while checking syntax in order to catch any error-level diagnostics sent by the server. This can be useful for cases where the syntax is correct but there are compilation errors like type-errors. It is set to False by default, and has a minor time overhead. The error returned in this case will have error_type as Diagnostics error.

from PythonAlloyClient import AlloyServer

server = AlloyServer()
server.start()
syntax_check = server.check_syntax(alloy_code, try_get_diagnostics=True)

Development

Setting Up the Development Environment

This project uses pytest for testing. This is listed in requirements.txt and can be installed using pip.

Running Tests

python -m pytest tests/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit Pull Requests or issues.

Metadata

Release files for PythonAlloyClient 0.1.4

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

Source distribution (sdist)

Source distribution for PythonAlloyClient 0.1.4
File Size Uploaded
pythonalloyclient-0.1.4.tar.gz 20.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for PythonAlloyClient 0.1.4
File Interpreter ABI Platform
pythonalloyclient-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 41.5 MB

Release files / pythonalloyclient-0.1.4.tar.gz

Download URL pythonalloyclient-0.1.4.tar.gz
Size 20.7 MB
Tags Source
SHA-256 checksum
How to use checksums
b5f64066b7a8d7581dd4554ed3ed7613b25a5bb5f3f6c321b7807aff9a5f7ee6
BLAKE2b-256 checksum
How to use checksums
115e2da6afc3e4593531b48e0e536ff1f930435be22a1aeb533baf668bdf012b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / pythonalloyclient-0.1.4-py3-none-any.whl

Download URL pythonalloyclient-0.1.4-py3-none-any.whl
Size 20.7 MB
Tags Python 3
SHA-256 checksum
How to use checksums
883943e00a8620f2ff040b2bd66d85221e749e8fb81609284496981c13c5cba6
BLAKE2b-256 checksum
How to use checksums
29f3bef775530418351ffeb00f6327fc2a5292fc14e529638a2632f07aaf9031
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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