Skip to main content

Installing sasvi into the SAS Viya Python

How to make import sasvi work inside the Python that SAS Configurator for Open Source (sas-pyconfig) builds for Viya, so PROC PYTHON, SAS Studio Python steps, and SAS Intelligent Decisioning can use the SDK.

This is an administrator task. You need kubectl access to the Viya namespace and, for the last step, write access to the deployment assets.

What you add​

One entry in the package list that sas-pyconfig installs, with the version pinned:

sasvi==<version>
  • Pin the version. A bare sasvi installs whatever release is newest when the job runs. It also never changes, so it never triggers an upgrade (why).
  • No spaces. pip_install_packages is a space-separated list, so write sasvi==<version> and not sasvi == <version>.

Before you start​

  • The profile must build Python 3.11 or later. Check python_tarball.
  • The build pod needs to reach PyPI, or an index that mirrors it. Check pip_index_url and pip_extra_url; none means plain public PyPI.
  • Substitute your own namespace for viya below if it differs.

Step 1. Pick the version​

Use a release from PyPI. Check in the compatibility matrix that it covers your Viya release.

Step 2. Test the install from inside the cluster​

Optional, and it catches a wrong version or a blocked network before you touch any configuration. Use the Python version your profile builds:

kubectl -n viya run pypiprobe --rm -i --restart=Never --image=python:3.11-slim \
--command -- sh -c 'pip install --no-deps --target /tmp/x "sasvi==<version>" 2>&1 | tail -12'

Look for Successfully installed sasvi-<version>.

Step 3. Add it to the package list​

Find the ConfigMap. The name carries a kustomize content-hash suffix that differs per deployment:

kubectl -n viya get configmaps | grep sas-pyconfig

Append sasvi==<version> to the end of default_py.pip_install_packages, keeping every existing package.

Use a patch rather than kubectl edit. The editor wraps that very long single-line value across multiple YAML lines, and a hand edit that reflows it can silently drop or merge packages. Deriving the new value from the old one cannot lose an entry:

NS=viya; CM=sas-pyconfig-parameters-<hash>
ENTRY="sasvi==<version>"
CUR=$(kubectl -n $NS get cm $CM -o jsonpath='{.data.default_py\.pip_install_packages}')
case "$CUR" in
*sasvi==*) echo "ALREADY PRESENT - not appending" ;;
*) kubectl -n $NS patch cm $CM --type merge -p "$(python3 -c 'import json,sys; print(json.dumps({"data":{"default_py.pip_install_packages": sys.argv[1].strip()+" "+sys.argv[2]}}))' "$CUR" "$ENTRY")" ;;
esac

The case guard matters. Without it, a second run appends the entry twice.

Confirm it landed, and that the word count went up by exactly one:

kubectl -n viya get cm $CM -o jsonpath='{.data.default_py\.pip_install_packages}'; echo
kubectl -n viya get cm $CM -o jsonpath='{.data.default_py\.pip_install_packages}' | wc -w
caution

This edit is a test only. The hash suffix on the ConfigMap name is a kustomize content hash, so the next kustomize build | kubectl apply regenerates the ConfigMap from the deployment assets and discards this change. Step 6 makes it permanent.

Step 4. Run the pyconfig job​

The job reads the ConfigMap at startup, so save the configuration first.

kubectl -n viya create job sas-pyconfig-manual --from=cronjob/sas-pyconfig

Generating a fresh job name each time avoids the spec.template is immutable error you get from reusing one.

The log is one JSON object per line, not plain text. Every message quoted below is the message field:

kubectl -n viya logs job/sas-pyconfig-manual | python3 -c "
import sys, json
for l in sys.stdin:
try: print(json.loads(l)['message'])
except Exception: print(l.rstrip())"

Avoid kubectl logs -f for the whole run. On a busy host it dies partway with failed to create fsnotify watcher: too many open files. That is a kubectl-side inotify limit, not a job failure. The job keeps running; poll instead.

What to expect​

Only pip runs. CPython is not rebuilt when just the package list changes; look for:

Pip install packages have changed, rebuilding packages: <md5>

R is a no-op when unchanged. Begin Operations for R default_r profile is followed immediately by End Operations for default_r profile at the same elapsed millisecond, so setting global.r_enabled: "false" is unnecessary.

Packages install one at a time, each in its own uv pip install --no-cache --system --upgrade <entry>, and sasvi is last.

Timing depends heavily on whether CPython already exists. A first-time build takes 20–40 minutes; a rerun where only one entry is new completes in under ten minutes for a ~55-entry profile, because the unchanged entries re-resolve as already satisfied.

Checking the result​

COMPLETIONS 1/1 does not mean every package installed. A package whose build fails is logged and skipped, and the job still exits 0 and reports Complete. Count the log lines instead of trusting the job status:

kubectl -n viya logs job/sas-pyconfig-manual | python3 -c "
import sys, json
msgs = []
for l in sys.stdin:
try: msgs.append(json.loads(l)['message'])
except Exception: pass
print('successes:', sum('install success' in m for m in msgs))
print('failures :', sum('install failed' in m for m in msgs))
for m in msgs:
if 'install failed' in m: print(m[:300])
print('sasvi:', [m for m in msgs if 'sasvi==' in m])"

Successes should equal the number of entries in pip_install_packages, plus one for pip_r_packages (rpy2). Confirm the sasvi line specifically appears. It is the only thing that proves sasvi was installed.

A pre-existing failure in some other package is common and unrelated to sasvi; packages that build C extensions against libraries the build image lacks are the usual culprits. Worth noting when you see one, but it does not block this change.

Step 5. Verify​

proc python;
submit;
import sasvi
print(sasvi.__version__)
endsubmit;
quit;

Step 6. Make it durable​

The live ConfigMap edit from step 3 is discarded by the next build and apply, after which nothing declares sasvi and it is no longer reinstalled. This step is not optional if the change should survive a redeployment.

The file is $deploy/site-config/sas-pyconfig/change-configuration.yaml. The mechanism SAS documents is a PatchTransformer, not a ConfigMapGenerator.

Look before you write. On a deployment that has ever been customised this file already exists and is already listed under transformers: in kustomization.yaml, often already carrying the full pip_install_packages value, which is where the live ConfigMap's list actually comes from. In that case your change is a one-value append to an existing op, not a new file:

ls -la $deploy/site-config/sas-pyconfig/
grep -n -i pyconfig $deploy/kustomization.yaml

If the file already exists, append to its package-list op with a script rather than an editor, for the same reason as step 3, and take a backup first:

F=$deploy/site-config/sas-pyconfig/change-configuration.yaml
ENTRY="sasvi==<version>"
cp -a "$F" "$F.bak.$(date +%Y%m%d%H%M%S)"
python3 - "$F" "$ENTRY" <<'PYEOF'
import re, sys
path, entry = sys.argv[1], sys.argv[2]
s = open(path).read()
if 'sasvi==' in s:
print('ALREADY PRESENT - no change'); raise SystemExit
pat = re.compile(r'(path: /data/default_py\.pip_install_packages\n\s*value: ")([^"]*)(")')
m = pat.search(s)
if not m:
print('PATTERN NOT FOUND - aborting'); raise SystemExit(1)
open(path, 'w').write(s[:m.start()] + m.group(1) + m.group(2).strip() + ' ' + entry + m.group(3) + s[m.end():])
print('PATCHED')
PYEOF

Only if the file does not exist, create it and add it to transformers: in kustomization.yaml:

apiVersion: builtin
kind: PatchTransformer
metadata:
name: sas-pyconfig-custom-parameters
patch: |-
- op: replace
path: /data/default_py.pip_install_packages
value: "<your existing packages> sasvi==<version>"
target:
version: v1
kind: ConfigMap
name: sas-pyconfig-parameters

Three things to get right:

  • op: replace overwrites the whole value, so carry the full existing package list through. Read it from that deployment's live ConfigMap (step 3). Never take it from the example in sas-bases, whose list has drifted, and never from another deployment. Profiles vary widely; lists of 30 and of 55 entries are both normal. Pasting one deployment's list into another silently uninstalls whatever the target had extra.
  • Target the unsuffixed name sas-pyconfig-parameters. The hash is added at build time.
  • Reference the file from kustomization.yaml under transformers:.

Then rebuild and apply as usual. Delete any completed sas-pyconfig job first, because spec.template is immutable and a leftover job makes the apply fail:

kubectl -n viya delete job sas-pyconfig --ignore-not-found

With the deployment operator, the job runs on the next reconcile. On a manual deployment, rerun it as in step 4.

Upgrading to a new version​

Change the version in both places (the live ConfigMap if you are testing, and the site-config patch), then rerun the job. A profile that installs sasvi from a GitHub archive URL upgrades the same way: replace the URL with sasvi==<version>.

sas-pyconfig decides whether to reinstall by comparing an md5 of the package-list string against the previous run, which it stores on the persistent volume:

Config file /opt/sas/viya/home/sas-pyconfig/md5sum exists. Running comparison
of new vs running configuration if applicable
Pip install packages have changed, rebuilding packages: <md5>

The same string gives the same md5, so a bare sasvi entry would stay on the release it installed first. A new version changes the string, which makes the reinstall run. The changed path is directly observed in the log line above. The skip path is inferred from it.

Gotchas​

  • The cli extra is not needed. Its packages (typer, click and rich) only serve the sasvi command.
  • Silent version drift. Each entry installs in its own uv pip install --upgrade, so there is no shared resolution that could fail the job outright. The flip side is last-writer-wins on shared dependencies, with nothing logged. sasvi is installed last, so its pins win. This is worth knowing but rarely worth worrying about. Profiles routinely already contain conflicting entries such as a pinned numpy==1.26.4 followed later by a bare numpy, which overwrites the pin on every run regardless of sasvi.
  • pip_local_packages: "true" is not the answer. It is profile-wide, and SAS pairs it with pip_index_url: none, so enabling it forces every package in the profile to be staged as a local wheel. Only reach for it (or an absolute wheel path on the PVC) if the cluster loses HTTPS access to the package index.
  • Python version. sasvi requires 3.11 or later; the profile's python_tarball must match.

Using the SDK from SAS​

Once installed, a SAS session can hand its own bearer token to the SDK. See examples/sas_studio_example.py and the Authentication guide.