Inventory SAS® Viya® SAS® Content folders with Python and the Folders REST API


This SAS KB article describes a structured approach to creating an inventory of SAS Viya content stored in SAS Content folders using Python and the Folders REST API. This article outlines how to recursively traverse folder structures; identify non-folder content, such as reports, decisions, and models; and export the results into a structured CSV file for further analysis.

The approach builds upon a SAS Communities example by adapting it for execution within SAS® Studio and enhancing it with capabilities required for real-world use. These enhancements include support for internal authentication using the SAS Viya session token, external execution using OAuth authentication, pagination handling for large folders, improved error handling, and metadata enrichment.

In addition, this article highlights important considerations related to API-level authorization, including scenarios where content is accessible through the user interface but is restricted when accessed via the API.

This article is intended to help SAS administrators and technical users implement a reliable and repeatable method for content inventory, supporting activities such as migration planning, governance, and troubleshooting.


Option A: Run Internally from SAS Studio Using the PYTHON Procedure

Use this version when you run Python inside SAS Studio on the same SAS Viya environment. This version obtains the active SAS Viya compute session token from SAS_SERVICES_TOKEN.

Before you run the code, do the following:


Option B: Run Externally from a Python Environment

Use this version when running from a local machine, server, automation host, or external Python runtime. In this mode, SAS Studio does not provide SAS_SERVICES_TOKEN. You must supply a valid OAuth access token.

External Execution Notes:


Troubleshooting

401 Full authentication is required

SAS_SERVICES_TOKEN was not found

Certificate Warning

CSV was created, but no rows are present


Notes and Considerations