Skip to main content

SAS Viya REST Client

Project description

sasctl

A user-friendly REST client for SAS Viya.

SAS Viya Version Python Version
Full documentation: https://sassoftware.github.io/python-sasctl

Overview

The sasctl package enables easy communication between the SAS Viya platform and a Python runtime. It can be used as a module or as a command line interface.

sasctl.folders.list_folders()
sasctl folders list

Prerequisites

sasctl requires the following Python packages be installed. If not already present, these packages will be downloaded and installed automatically.

  • requests
  • six
  • futures (Python 2.7 only)

The following additional packages are recommended for full functionality:

  • swat
  • kerberos

Installation

pip install sasctl

Functionality that depends on additional packages can be installed using the following:

  • pip install sasctl[swat]
  • pip install sasctl[kerberos]
  • pip install sasctl[all]

Getting Started

Once the sasctl package has been installed and you have a SAS Viya server to connect to, the first step is to establish a session:

>>> from sasctl import Session

>>> with Session(host, username, password):
...     pass  # do something
sasctl --help 

Once a session has been created, all commands target that environment. The easiest way to use sasctl is often to use a pre-defined task, which can handle all necessary communication with the SAS Viya server:

>>> from sasctl import Session, register_model
>>> from sklearn import linear_model as lm

>>> with Session('example.com', authinfo=<authinfo file>):
...    model = lm.LogisticRegression()
...    register_model(model, 'Sklearn Model', 'My Project')

A slightly more low-level way to interact with the environment is to use the service methods directly:

>>> from sasctl import Session
>>> from sasctl.services import folders

>>> with Session(host, username, password):
...    for f in folders.list_folders():
...        print(f)

Public
Projects
ESP Projects
Risk Environments

...  # truncated for clarity

My Folder
My History
My Favorites
SAS Environment Manager

The most basic way to interact with the server is simply to call REST functions directly, though in general, this is not recommended.

>>> from pprint import pprint
>>> from sasctl import Session, get

>>> with Session(host, username, password):
...    folders = get('/folders')
...    pprint(folders)

{'links': [{'href': '/folders/folders',
            'method': 'GET',
            'rel': 'folders',
            'type': 'application/vnd.sas.collection',
            'uri': '/folders/folders'},
           {'href': '/folders/folders',
            'method': 'POST',
            'rel': 'createFolder',

...  # truncated for clarity

            'rel': 'createSubfolder',
            'type': 'application/vnd.sas.content.folder',
            'uri': '/folders/folders?parentFolderUri=/folders/folders/{parentId}'}],
 'version': 1}

Examples

A few simple examples of common scenarios are listed below. For more complete examples see the examples folder.

Show models currently in Model Manager:

>>> from sasctl import Session
>>> from sasctl.services import model_repository

>>> with Session(host, username, password):
...    models = model_repository.list_models()

Register a pure Python model in Model Manager:

>>> from sasctl import Session, register_model
>>> from sklearn import linear_model as lm

>>> with Session(host, authinfo=<authinfo file>):
...    model = lm.LogisticRegression()
...    register_model(model, 'Sklearn Model', 'My Project')

Register a CAS model in Model Manager:

>>> import swat
>>> from sasctl import Session
>>> from sasctl.tasks import register_model

>>> s = swat.CAS(host, authinfo=<authinfo file>)
>>> astore = s.CASTable('some_astore')

>>> with Session(s):
...    register_model(astore, 'SAS Model', 'My Project')

Contributing

We welcome contributions!

Please read CONTRIBUTING.md for details on how to submit contributions to this project.

License

See the LICENSE file for details.

Additional Resources

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sasctl-1.5.1.tar.gz (80.3 kB view details)

Uploaded Source

Built Distribution

sasctl-1.5.1-py3-none-any.whl (101.2 kB view details)

Uploaded Python 3

File details

Details for the file sasctl-1.5.1.tar.gz.

File metadata

  • Download URL: sasctl-1.5.1.tar.gz
  • Upload date:
  • Size: 80.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7

File hashes

Hashes for sasctl-1.5.1.tar.gz
Algorithm Hash digest
SHA256 024a53f10a7d6f0cc486ab23cb0ea6462e8898b8e13b1b8710b34867233cdc3c
MD5 71e595464928bfa0288cb3be5c405da2
BLAKE2b-256 f4c09cb63d67253743c1a3c4535f0c0b2d2af6d1be8efe55f7d35ea66bcf1e4c

See more details on using hashes here.

File details

Details for the file sasctl-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: sasctl-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 101.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7

File hashes

Hashes for sasctl-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2e62e4b32919f54dd2855ca6ab5c78d893aa37b2103fc6e89dfa1a5d8a4f1de
MD5 07f43d6a35879c8e5fe7eb4631828626
BLAKE2b-256 dbe8ebfb138a84dbbbd304860c4113160db5a066bfe81c46480372eb4f08c9c0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page