[Python] Python 365 how to pull items from a list on sharepoint online

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to get the row data from a SharePoint list in python.

    I am using python 365, and while I can get the field names, what I want after getting the field names is the row data to export it into excel.

    Here is what I have from the example, and I have been looking at the lists of examples but not finding anything related to getting the field value and row data from it much less move it to excel. how would I go about doing this?

    I have the site name and the view name.

    # Authentication
    credentials = ClientCredential(client_secret, client_id)

    site_url = "https://company.sharepoint.com/sites/RiskAssessment"
    list_title = "Risk Assessment Workflow"
    view_title = "1.4. Assign Work"

    ctx = ClientContext(site_url).with_credentials(credentials)

    list_object = ctx.web.lists.get_by_title(list_title)
    # 1. First request to retrieve view fields
    view_fields = (
    list_object.views.get_by_title(view_title).view_fields.get().execute_query()
    )
    # 2. Second request to retrieve fields
    fields = [
    list_object.fields.get_by_internal_name_or_title(field_name).get()
    for field_name in view_fields
    ]
    ctx.execute_batch() # From performance perspective prefer execute_batch over execute_query here

    fields_json = {f.internal_name: f.title for f in fields}
    print(json.dumps(fields_json))

    Continue reading...

Compartilhe esta Página