def METHOD_NAME(key):
    """Save the current session under key."""
    settings = sessionSettings(key)
    ## save current named session name
    import sessions
    settings.setValue('session_name', sessions.currentSession() or "")
    ## save the list of open documents
    settings.setValue('numdocuments', len(app.documents))
    for index, d in enumerate(app.documents):
        settings.beginGroup(f"document{index}")
        settings.setValue("url", d.url())
        settings.endGroup()
    ## save windows
    settings.setValue('numwindows', len(app.windows))
    for index, win in enumerate(app.windows):
        settings.beginGroup(f"mainwindow{index}")
        win.writeSessionSettings(settings)
        settings.setValue("active_document", win.currentDocument().url())
        settings.endGroup()
    settings.sync()