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.9+.

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.9 – 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.0.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.0.0
File Size Uploaded Provenance Actions
viyapy-3.0.0.tar.gz 21.8 kB With provenance Details for viyapy-3.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 47.2 kB

Release files / viyapy-3.0.0.tar.gz

Download URL viyapy-3.0.0.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8449552429fa2a7634ee4a73071f0d1b4b0f7eadd6c996a437db9b68bd1fcd5e
BLAKE2b-256 checksum
How to use checksums
ac58cfd69d1791db2350b4e09a4583b49e3fd639d9375468dedbb2ce026e1efb
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 4, 2026.

Transparency log

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

Download URL viyapy-3.0.0-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd535473f8df342fe6818d7c49372e7269d87e0508862172ff5e94995e322f39
BLAKE2b-256 checksum
How to use checksums
07cce47e4c900f04a8853869c1ada21dfc7cdd7f229ae10b2cfa38320cfc1a1f
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 4, 2026.

Transparency log

Security for viyapy 3.0.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.0.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 4, 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