10.3.7.3 List Available User-Defined Python Functions

Use the oml.script.dir function to list the user-defined Python functions in the OML4Py script repository.

The syntax of the oml.script.dir function is the following:

oml.script.dir(name=None, regex_match=False, sctype=’user’)

The name argument is a string that specifies the name of a user-defined Python function or a regular expression to match to the names of user-defined Python functions in the script repository. When name is None, this function returns the type of user-defined Python functions specified by argument sctype.

The regex_match argument is a boolean that indicates whether argument name is a regular expression to match. The default value is False.

The sctype argument is a string that specifies the type of user-defined Python function to list. The value may be one of the following.

  • user, to specify the user-defined Python functions available to the current user only.

  • grant, to specify the user-defined Python functions to which the read and execute privilege have been granted by the current user to other users.

  • granted, to specify the user-defined Python functions to which the read and execute privilege have been granted by other users to the current user.

  • global, to specify all of the global user-defined Python functions created by the current user.

  • all, to specify all of the user-defined Python functions available to the current user.

The oml.script.dir function returns a pandas.DataFrame that contains the columns NAME and SCRIPT and, optionally, the columns OWNER and GRANTEE.

Example 10-12 Using the oml.script.dir Function

This example lists the contents of the script repository using different arguments to the oml.script.dir function. For the creation of the user-defined Python functions, see Example 10-11.

import oml

# List the user-defined Python functions in the script 
# repository available to the current user only.
oml.script.dir()

# List all of the user-defined Python functions available 
# to the current user.
oml.script.dir(sctype='all')

# List the user-defined Python functions available to all users.
oml.script.dir(sctype='global')

# List the user-defined Python functions that contain the letters
# BL and that are available to all users.
oml.script.dir(name="BL", regex_match=True, sctype='all')

Listing for This Example

>>> import oml
>>>
>>> # List the user-defined Python functions in the script 
... # repository available to the current user only.
... oml.script.dir()
   NAME                                             SCRIPT
0  MYLM  def build_lm1(dat):\n    from sklearn import l...
>>> 
>>> # List all of the user-defined Python functions available
... to the current user.
... oml.script.dir(sctype='all')
     OWNER    NAME                                             SCRIPT
0    PYQSYS  GLBLM  def build_lm2(dat):\n    from sklearn import l...
1  OML_USER   MYLM  def build_lm1(dat):\n    from sklearn import l...
>>>
>>> # List the user-defined Python functions available to all users.
>>> oml.script.dir(sctype='global')
    NAME                                             SCRIPT
0  GLBLM  def build_lm2(dat):\n    from sklearn import l...
>>>
>>> # List the user-defined Python functions that contain the letters 
... # BL and that are available to all users.
... oml.script.dir(name="BL", regex_match=True, sctype='all')
    OWNER   NAME                                             SCRIPT
0  PYQSYS  GLBLM  def build_lm2(dat):\n    from sklearn import l...