Skip to main content

SAW Python Client

In-development Python client for SAW. Currently tested on Linux and MacOS -- at present there may be some minor issues running the Python Client in a Windows environment that needs addressed (e.g., some Python process management methods are not cross-OS-compatible).

This SAW client depends on the saw-remote-api server.

TL;DR Steps to running SAW Python scripts

  1. Clone the repo
git clone https://github.com/GaloisInc/saw-script.git
  1. Enter the repo
cd saw-script
  1. Initialize git submodules
git submodule update --init
  1. Navigate to the python client
cd saw-python
  1. Install and setup some version of the saw-remote-api server and update any relevant environment variables as needed (see saw_client.connect() documentation for the various ways a server can be connected to). E.g., here is how the docker image of the server might be used:
$ docker run --name=saw-remote-api -d \
  -v $PWD/tests/saw/test-files:/home/saw/tests/saw/test-files \
  -p 8080:8080 \
  ghcr.io/galoisinc/saw-remote-api:nightly
$ export SAW_SERVER_URL="http://localhost:8080/"
  1. Install the Python client (requires Python v3.10 or newer -- we recommend using poetry to install the package):
$ poetry install 
  1. Run tests or individual scripts:
$ env CLASSPATH=/home/saw/tests/saw/test-files poetry run python -m unittest discover tests/saw
$ poetry run python tests/saw/test_salsa20.py

Note that the CLASSPATH setting is set on the client side but points to server-side files, in this case the test files that we mounted inside the Docker container.

(We're aware the tests currently emit some ResourceWarnings regarding subprocesses when run via unittest even though they pass and successfully verify the goals. It's on our to-do list.)

Python Client Installation (via Poetry)

First, clone the repository and submodules.

$ git clone https://github.com/GaloisInc/saw-script.git
$ cd saw-script
$ git submodule update --init

Then, use poetry to install the python client from the saw-python directory:

$ cd saw-python
$ poetry install

SAW server

To run the verification scripts a saw-remote-api server must be available, either as a local executable or running in docker image listening on a port.

Connecting with a server in a script

Connecting to a server in a Python script is accomplished via the saw_client.connect method. Its accompanying Python doc strings describe the various ways it can be used. Below is a brief summary:

saw_client.connect(), when provided no arguments, will attempt the following in order:

  1. If the environment variable SAW_SERVER is set and refers to an executable, it is assumed to be a saw-remote-api executable and will be used for the duration of the script.
  2. If the environment variable SAW_SERVER_URL is set, it is assumed to be the URL for a running SAW server in http mode and will be connected to. (N.B., this can be a local server or a server running in a docker image.)
  3. If an executable saw-remote-api is available on the PATH it is assumed to be a SAW server and will be used for the duration of the script.

Additional arguments and options are documented with the function.

Notable, the reset_server keyword can be used to connect to a running server and reset it, ensuring states from previous scrips have been cleared. E.g., saw_client.connect(reset_server=True).

Acquiring a SAW Server

There are several ways a server executable can be obtained.

Server executables

An executable of the server is included in the SAW release/nightly tarballs.

If using a SAW release, it is recommended to use v0.8 or greater if possible. (v0.7 does include the server and may work for individual use cases, but running repeated scripts against the same persistent server will not work as intended.)

Nightly server builds can be found as Artifacts of the Nightly Builds github action. I.e., go to the Nightly Builds Github Action, click on a successful build, scroll to the bottom and under Artifacts a Linux, Windows, and MacOS tarball will be listed. (Apologies... we need to make these easier to find...)

Server docker images

Docker images for the SAW server are currently uploaded to DockerHub.

These images are set up to run as HTTP saw-remote-api servers, e.g.:

docker run --name=saw-remote-api -d \
  -p 8080:8080 \
  galoisinc/saw-remote-api:TAG

(where TAG is either latest or nightly) will launch a server listening at http://localhost:8080/. (As of March 2020, nightly is recommended, as the server in the last official release (i.e., the one accompanying SAW v0.7) contains some non-trivial bugs that greatly limit its utility.)

The -v option to docker run can be used to load files into the docker server's working directory so they can be loaded into the server at the request of python scripts. E.g., -v PATH_TO_FILES:/home/saw/files/ will upload the contents of the host machine's directory PATH_TO_FILES to the /home/saw/files/ directory in the docker container, which corresponds to the relative path files/ for the SAW server. (If desired, it can be useful to place files in a location in the Docker container such that the same relative paths in scripts refer to the same files in the host machine and docker container.)

Building from Source

If this repository is checked out and the build directions are successfully run, cabal v2-exec which saw-remote-api should indicate where the server executable has been stored by cabal.

Alternatively cabal v2-install saw-remote-api should install the server executable into the user's ~/.cabal/bin directory (or similar), which (if configured properly) should then appear as saw-remote-api in a user's PATH.

Running Python SAW verification scripts

Once the server is setup and any path variables are setup as desired, the Python (>= v3.9) client can be installed using poetry as follows:

$ cd saw-python
$ poetry install

Then the tests or individual scripts can be run as follows:

$ poetry run python -m unittest discover tests/saw
$ poetry run python tests/saw/test_salsa20.py

If leveraging environment variables is undesirable, the scripts themselves can specify a command to launch the server, e.g.:

saw_client.connect(COMMAND)

where COMMAND is a command to launch a new SAW server in socket mode.

Or a server URL can be specified directly in the script, e.g.:

saw_client.connect(url=URL)

where URL is a URL for a running SAW server in HTTP mode.

Running Verification Scripts from a clean state

To ensure any previous server state is cleared when running a SAW Python script against a persistent server (e.g., one running in HTTP mode in a different process), the reset_server keyword can be passed to saw_client.connect(). E.g.,

saw_client.connect(url="http://localhost:8080/", reset_server=True)

will connect to a SAW server running at http://localhost:8080/ and will guarantee any previous state on the server is cleared.

Python Version Support

Currently, saw-python officially supports python 3.12.

Metadata

Release files for saw-client 1.6

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

Source distribution (sdist)

Source distribution for saw-client 1.6
File Size Uploaded
saw_client-1.6.tar.gz 33.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for saw-client 1.6
File Interpreter ABI Platform
saw_client-1.6-py3-none-any.whl Python 3 none any Details

Total release size: 70.0 kB

Release files / saw_client-1.6.tar.gz

Download URL saw_client-1.6.tar.gz
Size 33.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0aae1331ae0fb031edb9d000f8db75086b7994ae1c39851f967552fad9205c17
BLAKE2b-256 checksum
How to use checksums
39f588acc1e5416eb43f4078349aa63e10ed2a94d0e1e611d16a8f140c1094c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-139-generic

Release files / saw_client-1.6-py3-none-any.whl

Download URL saw_client-1.6-py3-none-any.whl
Size 36.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4a6491ee555c49c0f2669136ba1c35ba598e4892dbb4429af0ad7a42d55eda4
BLAKE2b-256 checksum
How to use checksums
30a74c7eb730372c661592bed7595e8fb1a3c2931b3d255ea388319eab9bfcca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-139-generic

Release history Release notifications | RSS feed

This release

1.6 This release

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2.1

2 release files

1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.9.0

2 release files

0.8.1

2 release files

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