This is example code to explore and later on retrieve metadata from a catalogue service for the web (CSW) using Python.

#load dependencies
import sys
from owslib.csw import CatalogueServiceWeb

# support function
def showhelp():
    astring = """
    description:
    - First attempt to retrieve the metadata in a CSW.
    
    versions:
    - v0.1 gives a list of datasets available
    
    usage:
    - python getCSWdata.py urltoCSW
    
    for instance the PMR CSW
    url = 'http://pmr-geoserver.deltares.nl/geonetwork/srv/eng/csw?'
    """
    print astring

# give listing of available datasets
def displayrecords(url):
    try:
        csw = CatalogueServiceWeb(url,skip_caps=True)
        csw.getrecords2()
        csw.results
        for rec in csw.records:
            print csw.records[rec].title
    except:
        print 'something went wrong'


def nextstep(url):
    msg = """
    Right now you get a listing of the available datasets in the {u} committed. 
    Next step would be te rectrieve the complete metadata. This is not implemented yet.""".format(u=url)
    print msg
    return

if __name__ == '__main__':
    if len(sys.argv) <= 1:
        showhelp()
        sys.exit()
    if sys.argv[1] =='?':
        showhelp()    
        sys.exit()

    url = sys.argv[1]
    nextstep(url)
    displayrecords(url)