Python helper library functions

The Guardium® Python helper library (gpylib) contains several useful functions that you can use to add logging, make REST API calls, and convert JSON objects to Python dictionaries.

All functions that you import into your app's views.py file can be called globally.

The following table describes functions that you can import into your app's views.py file.

Function Format Description
log(0)
def log(message, level='info'):

Here's an example:

from gpylib import gpylib 
.. 
#in precedence order from lowest level to highest 
log('debug message' ,'debug') 
log('info message' ,'info') 
log('warning message' ,'warning') 
log('error message' ,'error') 
log('critical message' ,'critical')| Copy Copy
Import the gpylib helper library into your app's views.py to use the log() function. This function writes messages at your chosen log level to the /store/log/app.log file. By default, logging is turned on and set to INFO level. Lower level logging messages are ignored. Use the POST /log_level endpoint to change
set_log_level(log_level)
def set_log_level(log_level='info'):
Set the current log level. Used by the POST /log_level endpoint but can also be called programmatically.
REST()
def REST( RESTtype, requestURL, headers={}, 
data=None, params=None, json=None, version=None ):

for example

try:
  headers = {'content-type' : 'text/plain'}
  arielOptions = gpylib.REST( 'get',
                 '/api/ariel/databases', headers = headers )
except Exception as e:
  gpylib.log( "Error "  + str(e) )
  raise
Import the gpylib library to use this function to make calls to the Guardium REST API endpoints. The endpoint takes care of authentication and authorization by reusing the security tokens that are passed on the request from Guardium.
to_json_dict(JSON)
def to_json_dict(python_obj):
Converts a JSON object in to a Python dictionary.