def get_library(gi, lib_name, lib_desc='', lib_synopsis='', create=True):
    """
    Get the id corresponding to given library, and create it if it doesn't exist yet
    """
    print("Looking for lib '" + lib_name + "'")
    libs = gi.libraries.get_libraries()
    found_lib = None
    for lib in libs:
        if not found_lib and lib['name'] == lib_name and lib['deleted'
            ] is False:
            print("Found library '" + lib_name + "'")
            found_lib = lib['id']
    if not found_lib:
        if create:
            print("Did not find library '" + lib_name + "', creating it")
            create = gi.libraries.create_library(lib_name, lib_desc,
                lib_synopsis)
            found_lib = create['id']
        else:
            raise Exception("Did not find library '" + lib_name + "'")
    return found_lib
