In this Part 2 of a two-part series, we will install and use the pyviyatools on Windows.
The pyviyatools require the SAS Viya CLI and the trusted certificates file it requires, and of course Python - preferably python3. In this guide I chose to install pyviyatools using git from a command line, though like most of the things featured in this guide, there are other ways to get it. If you followed Part 1 of this guide, Install and use the SAS Viya CLI on Windows, much of the hard work is already done.
If you have not already read and followed Part 1, I would suggest you glance at this guide to get an idea of what it covers, and then go and follow the steps in Part 1 first.
This guide documents the concluding part of one possible ‘happy path’ for setting the SAS Viya CLI and pyviyatools up on Windows from scratch. If you have some of the components already, you may find you can skip the corresponding section. But between Part 1 of this guide and the steps below, below you can find the complete process.
In Part 2 of this guide, we will cover:
In this Part 2, we assume all the components from Part 1 are already present, so we only need to install the things in the 'Part 2' box in the dependency diagram. We will assume that everything outside that box (the Windows client machine, chocolatey, the SAS Viya CLI and the trustedcerts.pem certificates file which the pyviyatools also requires) are already set up and validated:
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
python --version
, from both PowerShell and Windows Command Prompt and get a Python 3.x.x version number in response. For the sake of consistency, we will install it using chocolatey here.python --version
If Python3 is installed, you should see something like this, and you can continue to the next section, to upgrade pip:
Python 3.11.4
If Python3 is not installed, you should see something like this (in red):
python3 : The term 'python3' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + python3 --version + ~~~~~~~ + CategoryInfo : ObjectNotFound: (python3:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
choco install python3 -y
python --version
again to verify that Python3 is installed and in your path. You should see something like this:Python 3.11.4
python.exe -m pip install --upgrade pip
python -m pip install requests
python -m pip install configobj
git version
. Since we are using chocolatey to install other packages in these instructions, we may as well pick that method for this step.git version
If you see something like this, git is already installed:
git version 2.41.0.windows.1
If you see something like this, git is not installed:
git : The term 'git' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + git + ~~~ + CategoryInfo : ObjectNotFound: (git:String) [], CommandNotFoundException
choco install git.install -y
git version
again to verify that git is installed and in your path. You should see something like this:git version 2.41.0.windows.1
Push-Location Set-Location Env: cd C:\ViyaHome git clone https://github.com/sassoftware/pyviyatools.git Pop-Location
dir C:\ViyaHome\pyviyatools
Partial expected output (with some files omitted):
PS C:\Users\student> dir C:\ViyaHome\pyviyatools Directory: C:\ViyaHome\pyviyatools Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 7/14/2023 6:24 AM templates -a---- 7/14/2023 6:24 AM 57 .gitattributes -a---- 7/14/2023 6:24 AM 153 .gitignore -a---- 7/14/2023 6:24 AM 70 application.properties -a---- 7/14/2023 6:24 AM 6521 applyauthmodel.py -a---- 7/14/2023 6:24 AM 4857 applyfolderauthorization.py -a---- 7/14/2023 6:24 AM 4308 applyviyarules.py -a---- 7/14/2023 6:24 AM 7899 archivefiles.py -a---- 7/14/2023 6:24 AM 3656 callrestapi.py ... Some files omitted ... -a---- 7/14/2023 6:24 AM 3987 toggleviyarules.py -a---- 7/14/2023 6:24 AM 5327 unittestsadm33.sh -a---- 7/14/2023 6:24 AM 8687 unittestsadm34.sh -a---- 7/14/2023 6:24 AM 4563 unittestviya4.sh -a---- 7/14/2023 6:24 AM 3150 updatedomain.py -a---- 7/14/2023 6:24 AM 4731 updatepreferences.py -a---- 7/14/2023 6:24 AM 7843 validateviya-manual.md -a---- 7/14/2023 6:24 AM 23618 validateviya.py PS C:\Users\student>
setup.py
script. This tool uses the Python3 configobj module we installed earlier to set values in a pyviyatools configuration file called application.properties
. In the PowerShell terminal window, run this, substituting the location where you installed the sas-viya CLI executable for C:\ViyaHome\CLI
, if it is somewhere else on your Windows machine. Recall that we installed and configured the SAS Viya CLI in Part 1 of this guide.cd C:\ViyaHome\pyviyatools ./setup.py --clilocation C:\ViyaHome\CLI --cliexecutable sas-viya
Expected output:
Note: updating C:\ViyaHome\pyviyatools\application.properties NOTE: configuration values set to {'sascli.location': 'C:\\ViyaHome\\CLI', 'sascli.executable': 'sas-viya'}
[Environment]::SetEnvironmentVariable("Path",[Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) + ";C:\ViyaHome\pyviyatools", [EnvironmentVariableTarget]::Machine)
.authinfo
file. In the following command, I have used the username and password of a SAS Viya administrator account: user geladm
, password lnxsas
. Substitute the username and password of the account you wish to use by default for these values in the command below. In the PowerShell terminal window, run this$authinfo_file=$HOME+'\.authinfo' [IO.File]::WriteAllLines($authinfo_file, 'default user geladm password lnxsas') type $authinfo_file
Note: We use WriteAllLines
here to write the line to the .authinfo
file, because when I used echo
, the character encoding ended up being UTF-16, which was not understood by python3’s configObj module.
loginviauthinfo.py
and any other pyviyatools you run, e.g. C:\ViyaHome\pyviyatools\loginviauthinfo.py
😞set current_namespace=gelcorp set SAS_CLI_PROFILE=%current_namespace% set SSL_CERT_FILE=%USERPROFILE%\.certs\%current_namespace%_trustedcerts.pem set REQUESTS_CA_BUNDLE=%SSL_CERT_FILE% loginviauthinfo.py
Expected result (showing your profile name instead of ‘gelcorp
’, your ingress host instead of ‘gelcorp.rext03-0175.race.sas.com
’ and your SAS Viya user – ideally an administrator – instead of ‘geladm
’):
C:\Users\student>loginviauthinfo.py Logging in with profile: gelcorp Getting Credentials for: gelcorp.rext03-0175.race.sas.com Logging in as user: geladm Enter credentials for https://gelcorp.rext03-0175.race.sas.com: Login succeeded. Token saved. C:\Users\student>
C:\ViyaHome\pyviyatools\
or the path you to your copy of the pyviyatools, if you did not add the pyviyatools directory to your path):listcaslibs.py
Expected output (caslibs shown depend on the caslibs visible to your authenticated user in your SAS Viya deployment – caslibs visible to my administrative user, geladm
, in my SAS Viya deployment are shown in the output below):
C:\Users\student>listcaslibs.py server,caslib cas-shared-default,CASUSER(geladm) cas-shared-default,Financial Data cas-shared-default,Formats cas-shared-default,hrdl cas-shared-default,ModelPerformanceData cas-shared-default,Models cas-shared-default,Public cas-shared-default,salesdl cas-shared-default,Samples cas-shared-default,SystemData C:\Users\student>
listgroupsandmembers.py --id SASAdministrators
Expected output:
groupid,groupname,grouptype,groupproviderid,memberid,membername,membertype,memberproviderid SASAdministrators,SAS Administrators,group,local,geladm,"geladm",user,ldap SASAdministrators,SAS Administrators,group,local,GELCorpSystemAdmins,"GELCorp System Admins",group,ldap
getfolderid.py --f /Public
Expected output:
creationTimeStamp ,createdBy ,modifiedTimeStamp ,modifiedBy ,version ,id ,name ,description ,type ,memberCount ,properties , "2023-07-13T08:08:51.478982Z","anonymous","2023-07-13T08:08:51.478982Z","anonymous","1","fef7a224-d3fd-4c03-8a51-fdd05b0cbfe0","Public","Public folder for general access.","folder","0","{'allowMove': 'false', 'uuid': '935842da-9ba0-479c-99e3-6a4e489322fc'}",
sas-viya folders show
command:sas-viya --output text folders show --path /Public
explainaccess.py -f /Public --header
Expected output:
principal,read,update,delete,secure,add,remove,read(convey),update(convey),delete(convey),secure(convey),add(convey),remove(convey) authenticatedUsers,grant*,prohibit,prohibit,prohibit,grant*,grant*,grant*,grant*,grant*,prohibit,grant*,grant* SASAdministrators,grant,grant,grant,grant,grant,grant,grant,grant,grant,prohibit,grant,grant
validateviya.py
Expected output:
Data Collection Test Started: Logged in User Data Collection Test Started: List Users Data Collection Test Started: List Base Folders Data Collection Test Started: List CAS Servers Data Collection Test Started: List CAS Server Metrics Data Collection Test Started: List CAS Server Caslibs Data Collection Test Started: List CASLib Tables Computation Test Started: Run Test SAS Code name ,id "geladm","geladm" name ,id "SAS LDAP Service Account","sasldap" "SAS System Account","sas" "CAS System Account","cas" "SAS Administrator","sasadm" "SAS Test User 1","sastest1" "SAS Test User 2","sastest2" "geladm","geladm" "Douglas","Douglas" "Delilah","Delilah" "Alex","Alex" "Amanda","Amanda" "Ahmed","Ahmed" "Fay","Fay" "Fernanda","Fernanda" "Fiona","Fiona" "Frank","Frank" "Fred","Fred" "Hamish","Hamish" "Hazel","Hazel" "Heather","Heather" "Helena","Helena" "Henrik","Henrik" "Hugh","Hugh" "Santiago","Santiago" "Sarah","Sarah" "Sasha","Sasha" "Sean","Sean" "Sebastian","Sebastian" "Shannon","Shannon" "Sheldon","Sheldon" "Sophia","Sophia" "hrservice","hrservice" "salesservice","salesservice" "financeservice","financeservice" name ,description "Users","Base Folder for all user folders." "Public","Public folder for general access." "Products","Products folder for samples, canned objects and other SAS-provided content." "gelcontent","Base folder" "Conversational Flows","Conversational Flows Folder" "Model Repositories","None" name ,host ,port ,description "cas-shared-default","sas-cas-server-default-client","5570","controller" serverName ,systemNodes ,systemCores ,cpuSystemTime ,memory "cas-shared-default","4","32","0.013651","1319040" name ,scope ,description "CASUSER(geladm)","global","Personal File System Caslib" "Financial Data","global","gelcontent finance" "Formats","global","Stores user defined formats." "hrdl","global","gelcontent hrdl" "ModelPerformanceData","global","Stores performance data output for the Model Management service." "Models","global","Stores models created by Visual Analytics for use in other analytics or SAS Studio." "Public","global","Shared and writeable caslib, accessible to all users." "salesdl","global","gelcontent salesdl" "Samples","global","Stores sample data, supplied by SAS." "SystemData","global","Stores application generated data, used for general reporting." serverName ,caslibName ,name "cas-shared-default","systemData","AUDIT" "cas-shared-default","systemData","AUDIT_ACTIVITIES" "cas-shared-default","systemData","AUDIT_ACTIVITIES_PROPERTIES" "cas-shared-default","systemData","AUDIT_ACTIVITIES_URIS" "cas-shared-default","systemData","SASVIYATYPES" runSuccessful ,jobState "True","completed"
From here on, you should be able to run sas-viya
commands and run any of the pyviyatools as permitted by the versions of the software you have available, and the permissions of the user you defined in your .authinfo file. The SAS Viya CLI has an extensive set of plugins, documented in SAS Help Center here:
https://go.documentation.sas.com/doc/en/sasadmincdc/default/calcli/n1vth8mtb8ipprn1prz5j26p3nvc.htm.
pyviyatools
provides many convenient tools/scripts which my GEL colleague Gerry Nelson and I, and a number of other contributors have written to enable or simplify certain tasks in SAS Viya. It is documented in markdown files in the pyviyatools project in GitHub, particularly in:
All the tools I have tried in the course of writing this guide worked well on Windows, as they are supposed to. However, due to the nature of our work, my fellow pyviyatools developers and I use them in LINUX more than in Windows. The tools are supposed to work the same on both but it is possible that you may find a tool that does not work as well on Windows as it does in LINUX. Please let us know about any issues that you come across while using the pyviyatools, by raising an issue in the pyviyatools project or by emailing one of us. It would help if you mention that you are using it in Windows, if you are.
My thanks to Gerry Nelson and Allan Tham for their help in discussing and refining some of the things I included in this guide, and to Gerry in particular for his work in developing and publishing the pyviyatools. See you next time!
Find more articles from SAS Global Enablement and Learning here.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.