The REST architecture that SAS Viya is built on is, by its nature, open. This is a very powerful thing! In addition, the supplied command-line interfaces (CLIs) add a user-friendly interface to make it easier to make REST calls. Occasionally, however, it is necessary to call REST directly. This can occur when there is (currently) no CLI interface to a piece of functionality, or you wish to run a more complex task from a single command. In the SAS Global Enablement and Learning (GEL) group, as we staged our software images and developed our materials for our SAS Viya training, we found ourselves with some of these needs. As a result, we developed the GEL pyviyatools.
The GEL pyviyatools are a set of Python-based command-line tools that call the SAS Viya REST APIs. The tools can be used to make direct calls to any REST-endpoint (like a cURL command), and as a framework to build additional tools that make multiple rest calls to provide more complex functionality. The tools are designed to be used in conjunction with the sas-admin command line interfaces (CLI).
One of the challenges of making REST calls to SAS Viya is getting your authentication token. The tools simplify this issue by using the authentication mechanism provided by the SAS Viya command-line interfaces.
callrestapi (call_rest_api) is a general tool, and the building block for all the other tools. It calls a function callrestapi() that can also be used from any python program to build more complex tools.
The tools are self-documenting just like the Viya CLIs (just use the -h or –help option)
With callrestapi, you must pass a method and endpoint. You can optionally pass JSON data for a post request, content type headers, and the -o option to change the style of output.
In addition to this basic cURL-like functionality, there are some tools built on top of callrestapi that perform more complex functions. Here are few examples -- check out the GitHub project for a full list.
createdomain.py creates a SAS Viya authentication domain
updatedomain.py loads a set of userids and passwords to a Viya domain from a csv file
listrules.py lists authorization rules subset on a principal and/or a uri
loginviauthinfo.py uses an authinfo file to authenticate to the CLI
updateprefences.py updates preferences for a user or group of users
updatedomain.py loads a set of userids and passwords to a SASViya domain from a csv file
createfolders.py creates a set of SAS Viya folders from a csv file
explainaccess.py explains access for a folder, object or service endpoint
You can get the tools from GitHub where the installation and usage instructions are documented
Please try these tools if you need more command-line functions in your SAS Viya environment. In addition, if you want to contribute additional tools built on the framework, please see the CONTRIBUTING.md file in the GitHub repository. You can also report any issues or suggestions via GitHub issues.
Introducing Python-based command-line tools for SAS Viya was published on SAS Users.