|
1 |
| -# python-sasctl |
2 |
| -The sasctl package enables easy communication between the SAS Viya platform and a Python runtime. |
| 1 | +# sasctl |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The sasctl package enables easy communication between the SAS Viya |
| 6 | +platform and a Python runtime. It can be used as a module or as a command line interface. |
| 7 | +``` |
| 8 | +sasctl.folders.list_folders() |
| 9 | +``` |
| 10 | + |
| 11 | +``` |
| 12 | +sasctl folders list |
| 13 | +``` |
| 14 | + |
| 15 | + |
| 16 | +### Prerequisites |
| 17 | + |
| 18 | +sasctl requires the following Python packages be installed. |
| 19 | +If not already present, these packages will be downloaded and installed automatically. |
| 20 | +- requests |
| 21 | +- six |
| 22 | + |
| 23 | +The following additional packages are recommended for full functionality: |
| 24 | +- swat |
| 25 | +- kerberos / winkerberos |
| 26 | + |
| 27 | + |
| 28 | +All required and recommended packages are listed in `requirements.txt` and can be installed easily with |
| 29 | +``` |
| 30 | +pip install -r requirements.txt |
| 31 | +``` |
| 32 | + |
| 33 | +### Installation |
| 34 | + |
| 35 | +``` |
| 36 | +pip install git+https://github.com/sassoftware/python-sasctl |
| 37 | +``` |
| 38 | + |
| 39 | + |
| 40 | +## Getting Started |
| 41 | + |
| 42 | +Read the full documentation here: [http://xeno.glpages.sas.com/python-sasctl](http://xeno.glpages.sas.com/python-sasctl) |
| 43 | + |
| 44 | +Once the sasctl package has been installed and you have a SAS Viya server to connect to, |
| 45 | +the first step is to establish a session: |
| 46 | +``` |
| 47 | +>>> from sasctl import Session |
| 48 | +
|
| 49 | +>>> with Session(host, username, password): |
| 50 | +... pass # do something |
| 51 | +``` |
| 52 | +``` |
| 53 | +sasctl --help |
| 54 | +``` |
| 55 | + |
| 56 | + |
| 57 | +Once a session has been created, all commands target that environment. |
| 58 | +The easiest way to use sasctl is often to use a pre-defined task, |
| 59 | +which can handle all necessary communication with the SAS Viya server: |
| 60 | +``` |
| 61 | +>>> from sasctl import Session, register_model |
| 62 | +>>> from sklearn import linear_model as lm |
| 63 | +
|
| 64 | +>>> with Session('example.com', authinfo=<authinfo file>): |
| 65 | +... model = lm.LogisticRegression() |
| 66 | +... register_model('Sklearn Model', model, 'My Project') |
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | +A slightly more low-level way to interact with the environment is to use |
| 71 | +the service methods directly: |
| 72 | +``` |
| 73 | +>>> from pprint import pprint |
| 74 | +>>> from sasctl import Session, folders |
| 75 | +
|
| 76 | +>>> with Session(host, username, password): |
| 77 | +... folders = folders.list_folders() |
| 78 | +... pprint(folders) |
| 79 | + |
| 80 | +{'links': [{'href': '/folders/folders', |
| 81 | + 'method': 'GET', |
| 82 | + 'rel': 'folders', |
| 83 | + 'type': 'application/vnd.sas.collection', |
| 84 | + 'uri': '/folders/folders'}, |
| 85 | + {'href': '/folders/folders', |
| 86 | + 'method': 'POST', |
| 87 | + 'rel': 'createFolder', |
| 88 | +
|
| 89 | +... # truncated for clarity |
| 90 | +
|
| 91 | + 'rel': 'createSubfolder', |
| 92 | + 'type': 'application/vnd.sas.content.folder', |
| 93 | + 'uri': '/folders/folders?parentFolderUri=/folders/folders/{parentId}'}], |
| 94 | + 'version': 1} |
| 95 | +``` |
| 96 | + |
| 97 | + |
| 98 | +The most basic way to interact with the server is simply to call REST |
| 99 | +functions directly, though in general, this is not recommended. |
| 100 | +``` |
| 101 | +>>> from pprint import pprint |
| 102 | +>>> from sasctl import Session, get |
| 103 | +
|
| 104 | +>>> with Session(host, username, password): |
| 105 | +... folders = get('/folders') |
| 106 | +... pprint(folders) |
| 107 | + |
| 108 | +{'links': [{'href': '/folders/folders', |
| 109 | + 'method': 'GET', |
| 110 | + 'rel': 'folders', |
| 111 | + 'type': 'application/vnd.sas.collection', |
| 112 | + 'uri': '/folders/folders'}, |
| 113 | + {'href': '/folders/folders', |
| 114 | + 'method': 'POST', |
| 115 | + 'rel': 'createFolder', |
| 116 | +
|
| 117 | +... # truncated for clarity |
| 118 | +
|
| 119 | + 'rel': 'createSubfolder', |
| 120 | + 'type': 'application/vnd.sas.content.folder', |
| 121 | + 'uri': '/folders/folders?parentFolderUri=/folders/folders/{parentId}'}], |
| 122 | + 'version': 1} |
| 123 | +``` |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +### Examples |
| 129 | + |
| 130 | +A few simple examples of common scenarios are listed below. For more |
| 131 | +complete examples see the [examples](examples) folder. |
| 132 | + |
| 133 | +Show models currently in Model Manager: |
| 134 | +``` |
| 135 | +>>> from sasctl import Session, model_repository |
| 136 | +
|
| 137 | +>>> with Session(host, username, password): |
| 138 | +... models = model_repository.list_models() |
| 139 | +``` |
| 140 | + |
| 141 | +Register a pure Python model in Model Manager: |
| 142 | +``` |
| 143 | +>>> from sasctl import Session, register_model |
| 144 | +>>> from sklearn import linear_model as lm |
| 145 | +
|
| 146 | +>>> with Session(host, authinfo=<authinfo file>): |
| 147 | +... model = lm.LogisticRegression() |
| 148 | +... register_model('Sklearn Model', model, 'My Project') |
| 149 | +``` |
| 150 | + |
| 151 | +Register a CAS model in Model Manager: |
| 152 | +``` |
| 153 | +>>> import swat |
| 154 | +>>> from sasctl import Session |
| 155 | +>>> from sasctl.tasks import register_model |
| 156 | +
|
| 157 | +>>> s = swat.CAS(host, authinfo=<authinfo file>) |
| 158 | +>>> astore = s.CASTable('some_astore') |
| 159 | +
|
| 160 | +>>> with Session(s): |
| 161 | +... register_model('SAS Model', astore, 'My Project') |
| 162 | +``` |
| 163 | + |
| 164 | +## Contributing |
| 165 | + |
| 166 | +We welcome contributions! |
| 167 | + |
| 168 | +Please read [CONTRIBUTING.md](CONTRIBUTING.md) |
| 169 | +for details on how to submit contributions to this project. |
| 170 | + |
| 171 | +## License |
| 172 | + |
| 173 | +See the [LICENSE](LICENSE) file for details. |
| 174 | + |
| 175 | +## Additional Resources |
| 176 | + |
| 177 | +* [SAS Viya REST Documentation](https://developer.sas.com/apis/rest/) |
| 178 | +* [SAS Developer Community](https://communities.sas.com/t5/Developers/bd-p/developers) |
| 179 | + |
0 commit comments