A Python SDK for calling BYU REST web services.
Project description
byu-ws-python-sdk
=================
A Python SDK for authenticating to BYU REST web services. To do this, the library provides methods to generate the
required Authorization HTTP header for your REST web service calls.
The sdk now supports both Python 2.7 and Python 3.3.
Here is an ipython session showing the API. I wrapped some of the output for readability.
Pauls-MacBook-Pro:~ paul$ ipython
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import byu_ws_sdk as sdk
In [2]: url='https://ws.byu.edu/example/authentication/hmac/services/v1/exampleWS'
In [3]: key = 'your-api-key'
In [4]: shared_secret = 'your-shared-secret'
In [5]: headerVal = sdk.get_http_authorization_header(key, shared_secret, sdk.KEY_TYPE_API, sdk.ENCODING_URL,
url=url, actor='pd123', httpMethod=sdk.HTTP_METHOD_GET, actorInHash=True)
In [6]: import requests
In [7]: res = requests.get(url, headers={'Authorization': headerVal})
In [8]: res.status_code
Out[8]: 200
In [9]: res.content
Out[9]: '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<message xmlns="http://ws.byu.edu/namespaces/authentication/example/v1">
<greeting>Hello There Paul Eden</greeting></message>'
In [10]: sdk.<tab>
sdk.ENCODING_NONCE sdk.get_pretty_xml
sdk.ENCODING_URL sdk.get_ws_session
sdk.HTTP_METHOD_DELETE sdk.hashlib
sdk.HTTP_METHOD_GET sdk.hmac
sdk.HTTP_METHOD_POST sdk.make_sha512_mac
sdk.HTTP_METHOD_PUT sdk.nonce_encode
sdk.KEY_TYPE_API sdk.os
sdk.KEY_TYPE_WSSESSION sdk.requests
sdk.VALID_ENCODING_TYPES sdk.requests_config
sdk.VALID_HTTP_METHODS sdk.send_ws_request
sdk.VALID_KEY_TYPES sdk.simplejson
sdk.base64 sdk.time
sdk.base64encode_string sdk.url_encode
sdk.core sdk.valid_encoding_types
sdk.get_body_from_file sdk.valid_http_method
sdk.get_formatted_response sdk.valid_key_type
sdk.get_http_authorization_header sdk.xml
sdk.get_nonce
In [10]: help(sdk.get_http_authorization_header)
Help on function get_http_authorization_header in module byu_ws_sdk.core:
get_http_authorization_header(apiKey, sharedSecret, keyType, encodingType, url='',
requestBody=None, actor=None, contentType=None, httpMethod=None,
demo=False, actorInHash=False)
Encode the request to get the Authorization header value.
An example return value type is (for wsSession keys (the ones that expire in less than a day))
URL-Encoded-WsSession-Key Xh348rh4YbfYH9H9IMwv,2iJdLY/nY...MA...EM9V+/P229jBCcOUuw==,2011-08-19 09:02:30
In [11]: help(sdk.get_ws_session)
Help on function get_ws_session in module byu_ws_sdk.core:
get_ws_session(casNetId, casPassword, timeout=1)
get a wsSession keypair (apiKey/wsId and sharedSecret)
timeout is the number of minutes before the wsSession key expires.
valid values for timeout are 1 to 480 in minutes (480 minutes = 8 hours)
return value example is
{'personId': '123456789', 'apiKey': '5f_TzU3jdjX6s7DklHA8',
'expireDate': '2011-07-07 19:12:43',
'sharedSecret': 'gKLR8oDsNK4jyvKyWZtsFoiwuvLhwWpsBDTNJo_D'}
In [12]: help(sdk.get_nonce)
Help on function get_nonce in module byu_ws_sdk.core:
get_nonce(apiKey, actor='')
get a nonce key and value from the api-key
Note, that the nonce returned here, at least currently, has a 5 minute hard-coded expiration.
return value example is
{'nonceKey': '57921',
'nonceValue': 'G4qPJr5L3xI3KjXPw0g1mgWY8bzInQts7uctUfTAINm5ov3WCbXqRrTlFyECiiY/8rKGIqGUNDMxI9HlFvDEKg=='}
=================
A Python SDK for authenticating to BYU REST web services. To do this, the library provides methods to generate the
required Authorization HTTP header for your REST web service calls.
The sdk now supports both Python 2.7 and Python 3.3.
Here is an ipython session showing the API. I wrapped some of the output for readability.
Pauls-MacBook-Pro:~ paul$ ipython
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import byu_ws_sdk as sdk
In [2]: url='https://ws.byu.edu/example/authentication/hmac/services/v1/exampleWS'
In [3]: key = 'your-api-key'
In [4]: shared_secret = 'your-shared-secret'
In [5]: headerVal = sdk.get_http_authorization_header(key, shared_secret, sdk.KEY_TYPE_API, sdk.ENCODING_URL,
url=url, actor='pd123', httpMethod=sdk.HTTP_METHOD_GET, actorInHash=True)
In [6]: import requests
In [7]: res = requests.get(url, headers={'Authorization': headerVal})
In [8]: res.status_code
Out[8]: 200
In [9]: res.content
Out[9]: '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<message xmlns="http://ws.byu.edu/namespaces/authentication/example/v1">
<greeting>Hello There Paul Eden</greeting></message>'
In [10]: sdk.<tab>
sdk.ENCODING_NONCE sdk.get_pretty_xml
sdk.ENCODING_URL sdk.get_ws_session
sdk.HTTP_METHOD_DELETE sdk.hashlib
sdk.HTTP_METHOD_GET sdk.hmac
sdk.HTTP_METHOD_POST sdk.make_sha512_mac
sdk.HTTP_METHOD_PUT sdk.nonce_encode
sdk.KEY_TYPE_API sdk.os
sdk.KEY_TYPE_WSSESSION sdk.requests
sdk.VALID_ENCODING_TYPES sdk.requests_config
sdk.VALID_HTTP_METHODS sdk.send_ws_request
sdk.VALID_KEY_TYPES sdk.simplejson
sdk.base64 sdk.time
sdk.base64encode_string sdk.url_encode
sdk.core sdk.valid_encoding_types
sdk.get_body_from_file sdk.valid_http_method
sdk.get_formatted_response sdk.valid_key_type
sdk.get_http_authorization_header sdk.xml
sdk.get_nonce
In [10]: help(sdk.get_http_authorization_header)
Help on function get_http_authorization_header in module byu_ws_sdk.core:
get_http_authorization_header(apiKey, sharedSecret, keyType, encodingType, url='',
requestBody=None, actor=None, contentType=None, httpMethod=None,
demo=False, actorInHash=False)
Encode the request to get the Authorization header value.
An example return value type is (for wsSession keys (the ones that expire in less than a day))
URL-Encoded-WsSession-Key Xh348rh4YbfYH9H9IMwv,2iJdLY/nY...MA...EM9V+/P229jBCcOUuw==,2011-08-19 09:02:30
In [11]: help(sdk.get_ws_session)
Help on function get_ws_session in module byu_ws_sdk.core:
get_ws_session(casNetId, casPassword, timeout=1)
get a wsSession keypair (apiKey/wsId and sharedSecret)
timeout is the number of minutes before the wsSession key expires.
valid values for timeout are 1 to 480 in minutes (480 minutes = 8 hours)
return value example is
{'personId': '123456789', 'apiKey': '5f_TzU3jdjX6s7DklHA8',
'expireDate': '2011-07-07 19:12:43',
'sharedSecret': 'gKLR8oDsNK4jyvKyWZtsFoiwuvLhwWpsBDTNJo_D'}
In [12]: help(sdk.get_nonce)
Help on function get_nonce in module byu_ws_sdk.core:
get_nonce(apiKey, actor='')
get a nonce key and value from the api-key
Note, that the nonce returned here, at least currently, has a 5 minute hard-coded expiration.
return value example is
{'nonceKey': '57921',
'nonceValue': 'G4qPJr5L3xI3KjXPw0g1mgWY8bzInQts7uctUfTAINm5ov3WCbXqRrTlFyECiiY/8rKGIqGUNDMxI9HlFvDEKg=='}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
byu_ws_sdk-0.10.0.tar.gz
(9.3 kB
view details)
Built Distributions
byu_ws_sdk-0.10.0-py3.4.egg
(33.2 kB
view details)
byu_ws_sdk-0.10.0-py2.7.egg
(32.7 kB
view details)
File details
Details for the file byu_ws_sdk-0.10.0.tar.gz
.
File metadata
- Download URL: byu_ws_sdk-0.10.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc5293e45a6815b6a3a181289b82379743f1256e2ad503c5076deef3c7b87fa3 |
|
MD5 | 6744cdf75293800b09b7169af89f1997 |
|
BLAKE2b-256 | 73a8dace1f841f427656f558e68aa92ca2877707991cf36bbc8484a7f25efa95 |
File details
Details for the file byu_ws_sdk-0.10.0-py3.4.egg
.
File metadata
- Download URL: byu_ws_sdk-0.10.0-py3.4.egg
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b8bbab6576e4e92ce27bfbeb6581ba51a0f9e57cd9a4dfcbe1b09f50367b0e4 |
|
MD5 | e52b70ee53cbe1f0b385ba9cc406497e |
|
BLAKE2b-256 | 33190a906b061d238d163bdc4dd749d7949f8ed0095a1ee1776649599912201b |
File details
Details for the file byu_ws_sdk-0.10.0-py2.7.egg
.
File metadata
- Download URL: byu_ws_sdk-0.10.0-py2.7.egg
- Upload date:
- Size: 32.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43951782344ab7d2f63c9d5b6e77501cc7a038766f3e25ce42a22c3cc38671af |
|
MD5 | f83b52181132da881c2eb670f151bf11 |
|
BLAKE2b-256 | 38973f9f2da7f05a93c63f60de83e4e86fde3f6fff2faeca2c011bad25a1de0f |