Giter Club home page Giter Club logo

python-sasctl's Introduction

sasctl

A user-friendly Python interface for SAS Viya.

SAS Viya Version Python Version

Table of Contents

  1. Overview
  2. Prerequisites
  3. Installation
  4. Getting Started
  5. Examples
  6. Contributing
  7. License
  8. Additional Resources

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.services.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.

  • pandas
  • requests
  • pyyaml
  • packaging

The following additional packages are recommended for full functionality:

  • swat
  • kerberos
  • GitPython
  • numpy
  • scikit-learn

Installation

Installing the latest version is as easy as:

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]

If you want the latest functionality and can't wait on an official release, you can also install the latest source code:

pip install git+https://github.com/sassoftware/python-sasctl

Alternatively, if you're using Anaconda you can install with:

conda install -c sas-institute sasctl

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

python-sasctl's People

Contributors

smlindauer avatar jlwalke2 avatar djm21 avatar emcfalls avatar sophiarowland avatar silvestristefano avatar invalidpointer avatar namera9 avatar jameskochubasas avatar brtieu avatar xavierbizoux avatar pinduzera avatar jefurbee avatar tsej avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.