A CLI and API client library for interfacing with Imandra's web APIs
Project description
Imandra CLI and API client library
Imandra is a cloud-native automated reasoning engine for analysis of algorithms.
This package contains a python library imandra
for interacting with Imandra's
web APIs, to do things such as:
- Creating cloud-hosted Imandra Core instances to interact with Imandra via:
- Jupyter Notebooks
- the HTTP API wrapper around an Imandra Core session,
imandra-http-api
.
- Submitting IPL analysis jobs
If you're interested in developing Imandra models, you may also want to see the main Imandra docs site, and consider setting up Imandra Core locally by following the installation instructions there.
The imandra
python API reference documentation is available here.
The imandra
package also adds an entry point called imandra-cli
which exposes the imandra
library functionality in a more discoverable way:
$ python3 -m venv ./my/venv
...
$ ./my/venv/pip install imandra
...
$ ./my/venv/bin/imandra-cli --help
usage: imandra [-h] auth,ipl,core,rule-synth,cfb ...
Imandra CLI
positional arguments:
{auth,ipl,core,rule-synth,cfb}
optional arguments:
-h, --help show this help message and exit
On Windows, the entry point can be found as .\my\venv\Scripts\imandra-cli.exe
.
Authentication
In particular you may want to run:
$ ./my/venv/bin/imandra-cli auth login
and follow the prompts to authenticate. This will create the relevant credentials in ~/.imandra
(or %APPDATA%\imandra
on Windows).
You should now be able to invoke CLI commands that require authentication, and construct an auth
object from python code:
import imandra.auth
auth = imandra.auth.Auth()
This auth object can then be passed to library functions which make requests to Imandra's web APIs.
Interacting with Imandra Core via HTTP
The package also includes imandra_http_api_client
an open-api generated API
client for imandra-http-api
, the HTTP wrapper for Imandra itself, which can be
used for verifying Imandra models.
Although developing models is best done via a local Imandra Core installation, if you've already built a model and want to dynamically interrogate its logical constitution using Imandra, Imandra Core's HTTP API can lend a hand by giving you lightweight access to an Imandra Core instance, and returning responses in a structured, machine-readable format over HTTP.
- See the
imandra_http_api_client
API reference documentation for this module.
If you have a local Imandra Core
installation,
you can invoke imandra-http-api
directly, and connect to it on localhost:
# In a terminal
$ imandra-http-api
# with imandra-http-api running locally on port 3000
import imandra_http_api_client
config = imandra_http_api_client.Configuration(
host = 'http://localhost:3000',
)
If you do not have a local Imandra Core installation, you can create an instance
of imandra-http-api
on our cloud (after authenticating via the CLI command
imandra auth login
):
import imandra.auth
import imandra.instance
import imandra_http_api_client
auth = imandra.auth.Auth()
instance = imandra.instance.create(self.auth, None, "imandra-http-api")
config = imandra_http_api_client.Configuration(
host = self.instance['new_pod']['url'],
access_token = self.instance['new_pod']['exchange_token'],
)
You can then use your imandra_http_api_client.Configuration
object to make requests to imandra-http-api
:
with imandra_http_api_client.ApiClient(config) as api_client:
# Create an instance of the API class
api_instance = imandra_http_api_client.DefaultApi(api_client)
eval_req = {
"src": "fun x -> List.rev (List.rev x) = x",
"syntax": "iml",
"hints": {
"method": {
"type": "auto"
}
}
}
req = {
"src": "fun x -> List.rev (List.rev x) = x",
"syntax": "iml",
"hints": {
"method": {
"type": "auto"
}
}
}
print("Request: ")
print(req)
verify_request_src = imandra_http_api_client.VerifyRequestSrc.from_dict(req)
try:
# Verify a string of source code
api_response = api_instance.verify_by_src(verify_request_src)
print("The response of DefaultApi->verify:\n")
pprint(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->verify: %s\n" % e)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.