Let’s create a few new folders to contain our project. We’ll put it in My Documents\Projects\SwisPlayground.
Open Visual Studio Code from the Start Menu. Open the file using File > Open Folder

You’ll be prompted to trust the folders. Since this is our computer, we’ll trust ourselves.

Install the Python Extension
On the extensions panel on the left search for Python.

Click install to begin the installation of the extension and a few other related extensions.
Create a new file in your folder called hello.py and enter
msg = "Hello, World!"
print(msg)
Then save the file.
Build a Virtual Environment
It’s best practice to keep projects separated into virtual environments to insulate them from other plugins and configurations. To create a new environment, open the command palette with <CTRL><SHIFT><P> and type Python: and select Create Environment then select Venv to create a virtual environment.
Select your interpreter from the list (you’ll probably only have the one).

If prompted to enter the virtual environment, select Yes. You’ll know you are in the right environment when the bottom right of VS Code shows the virtual environment.

Run your test file and look for errors by clicking the play button in the code window.

On our test system, we got no errors, so we are ready to move on.

Importing Python Modules
Since you are already in your environment space (as shown by the (.venv) in the terminal window), we can install the necessary modules.
The “orionsdk” module packaged such that it has most of what you’ll need to begin scripting. To install it, we’ll use pip.
In the lower terminal window type pip install orionsdk and hit enter.

First Script
Create a new file, call it query.py and paste in the below code:
import requests
from orionsdk import SwisClient
# main() is our main function to do the thing
def main():
# these are the variables where we store your connection information
hostName = '10.1.20.1' # Put your server ip/hostname here
username = 'admin' # Put your username here
password = 'MyAdminPassword' # Put your password
# This is the query we are using
swqlQuery = 'SELECT Caption, Uri FROM Orion.Nodes ORDER BY Caption'
# Build a connection to the server
swis = SwisClient(hostName, username, password)
# let's run the query and store the results in a variable
response = swis.query(swqlQuery)
# there are multiple responses, so we'll need to go through each entry
for result in response['results']:
# output the caption and uri
print("{Caption} [{Uri}]".format(**result))
requests.packages.urllib3.disable_warnings()
if __name__ == '__main__':
main()
Save the file and run it by pressing <F5> or selecting Run > Start Debugging.
You should get a list back with your nodes and the corresponding URIs.
AP6-1st [swis://MyServerName./Orion/Orion.Nodes/NodeID=7]
AP6-2nd [swis://MyServerName./Orion/Orion.Nodes/NodeID=8]
AP6-3rd [swis://MyServerName./Orion/Orion.Nodes/NodeID=6]
AP6-Ground [swis://MyServerName./Orion/Orion.Nodes/NodeID=3]
hp283fdw [swis://MyServerName./Orion/Orion.Nodes/NodeID=4]
KMS-DESKTOP [swis://MyServerName./Orion/Orion.Nodes/NodeID=1026]
KMSDOCKER01 [swis://MyServerName./Orion/Orion.Nodes/NodeID=1017]
Congratulations. Your environment is now setup for Python development with the SolarWinds Orion API. Be sure to explore the samples provided in GitHub for additional information and help.