Skip to main content

viyapy

PyPI Python versions License: MIT CI Coverage

A typed Python client for SAS Viya Intelligent Decisioning — inspect decision flows and execute Micro Analytic Score (MAS) modules over the REST API. It supports both Viya 3.5 and Viya 4 (LTS and Stable) through a version/dialect layer, and is built for production use: one hardened HTTP stack with mandatory timeouts and retries, a typed exception hierarchy, bearer-token redaction in the library's logs and repr, and full type hints (py.typed).

Install

Pre-release note: the ViyaClient API documented below ships in viyapy 3.0, which is not yet published to PyPI (the current PyPI release predates this API). Until 3.0 is released, install from source: pip install "git+https://github.com/Shai-Alit/viyapy@main".

Once 3.0 is published, the usual install applies:

pip install viyapy

Requires Python 3.10+.

Quickstart

import os

from viyapy import ViyaClient

my_token = os.environ["VIYA_TOKEN"]  # your OAuth2 bearer token
client = ViyaClient("https://viya.example.com", token=my_token)

# Inspect a decision flow and its models
decision = client.decisions.get("my-decision-id")
for model in decision.models:
    print(model.name, model.modified_by)

# Execute a published decision's MAS module against a feature dict
result = client.mas.execute("api_tester1_0", {"input_string": "this is a test"})
print(result.outputs["output_string"])

ViyaClient is also a context manager (with ViyaClient(...) as client: ...), which closes the underlying HTTP session on exit.

Choosing the Viya generation

The client targets Viya 4 by default. For a Viya 3.5 deployment, pass viya_version:

client = ViyaClient("https://viya.example.com", token=my_token, viya_version="3.5")

The dialect layer handles the endpoint, media-type, and response-shape differences (including the MAS output vs outputs key) for you.

Authentication

Provide credentials with exactly one of token or auth.

A static bearer token:

client = ViyaClient("https://viya.example.com", token=os.environ["VIYA_TOKEN"])

Or an auth token provider — a zero-argument callable returning the current token, called on every request. A provider that refreshes and caches internally gives transparent token rotation:

def bearer() -> str:
    return my_oauth_session.current_access_token()  # refreshes as needed

client = ViyaClient("https://viya.example.com", auth=bearer)

TLS verification is on by default; pass verify="/path/to/ca-bundle.pem" for a custom CA, and see the docs before ever disabling it. The library does not write the bearer token to its logs or repr; a redaction filter additionally scrubs any Bearer <token> pattern from log records as a backstop. (A custom auth provider is responsible for not leaking the token in its own exceptions/logs.)

Error handling

Every failure raises a typed ViyaError subclass — the library never prints, never swallows exceptions, and never returns None to signal failure. API errors (ViyaAPIError and its subclasses) carry the HTTP status, the SAS Viya error code and details, and a correlation id when the server provides one; local configuration errors (ViyaConfigError) and malformed-response errors (ViyaResponseError) carry their own context instead. Catch broadly or precisely:

from viyapy import ViyaError, ViyaNotFoundError, ViyaRateLimitError

try:
    result = client.mas.execute("api_tester1_0", {"input_string": "x"})
except ViyaNotFoundError:
    ...  # the module or step does not exist
except ViyaRateLimitError as exc:
    retry_after = exc.retry_after
except ViyaError as exc:
    logger.error("Viya call failed: %s", exc)  # base class catches everything

Documentation

Full guides and the autodoc API reference are built with MkDocs (published in a later release). In the meantime:

Supported versions

  • Python: 3.10 – 3.13
  • SAS Viya: 3.5 and Viya 4 (LTS and Stable tracks). Viya 3.5 revision 24w44 (October 2024) or later, deployed on a supported Linux distribution, holds Standard Support through October 1, 2027; older revisions and other platforms fall under Limited Support. Confirm your deployment against SAS's current Viya support policy.

License

MIT © Sean Ford. See LICENSE.

References

  1. SAS Institute Inc. 2020. SAS® Intelligent Decisioning: Decision Management REST API Examples. Cary, NC: SAS Institute Inc.
  2. SAS Developer — Decision Management REST API

Metadata

Release files for viyapy 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for viyapy 3.1.0
File Size Uploaded Provenance Actions
viyapy-3.1.0.tar.gz 29.6 kB With provenance Details for viyapy-3.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for viyapy 3.1.0
File Interpreter ABI Platform Actions
viyapy-3.1.0-py3-none-any.whl Python 3 none any Details for viyapy-3.1.0-py3-none-any.whl

Total release size: 63.5 kB

Release files / viyapy-3.1.0.tar.gz

Download URL viyapy-3.1.0.tar.gz
Size 29.6 kB
Tags Source
SHA-256 checksum
How to use checksums
588bc64b11ac3e9699a6bb4fba20045977daa2d1e5fbd986fdab00760a3f654c
BLAKE2b-256 checksum
How to use checksums
7087c46925f0295cb2489777acaed32365b4be2a47eef3fb3e80d940d792fa54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.

Transparency log

Release files / viyapy-3.1.0-py3-none-any.whl

Download URL viyapy-3.1.0-py3-none-any.whl
Size 34.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd7814f77e787a790f77801f1bc10410a4809398ef63a7e7fbfeb19036d6a696
BLAKE2b-256 checksum
How to use checksums
d01792b9942c361ce2dc8a7e9d39c689aa78183e11714724b6fa21ec428a08f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.

Transparency log

Security for viyapy 3.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for viyapy-3.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page