Export Data LimeSurvey Menggunakan Python Citric

Sebenarnya saya sudah banyak membahas tentang Python Citric pada blog ini. Dan bahkan saya telah membuat skrip untuk mengambil data dari LimeSurvey dengan Python Citric dan menyimpannya dalam sqlite baik struktur maupun datanya.

Nah tadi ada kebutuhan sekedar mengambil data responses dari LimeSuryey yang barisnya melebihi 12.000 baris. Dalam database memang kalau kolomnya banyak menjadi agak berat, apalagi barisnya juga banyak.

Diambil lewat menu pada Limesurvey ternyata gagal. Mungkin karena terbentur limitasi memori pada setting PHP atau LiteSpeed, saya sendiri kurang paham, atau bisa jadi kena timeout. Namun ketika diambil menggunakan jalur API, data berhasil diambil dengan sempurna.

Oke skrip ini sangat tergantung dengan library pandas dan citric. Maka langkah pertama adalah neginstall library pandas dan citric.

pip install citric pandas

Kemudian install juga xlsx writer biar bisa nulis ke excel

pip install openpyxl

Jika sudah, kita tinggal membuka editor text copas  code dibawah ini, dan atur beberapa nilai variabelnya.

"""
Script created by Edy Santoso ([email protected])
Modified on: 2025-10-07
Purpose: Export LimeSurvey responses directly to XLSX
"""

from citric import Client
import io
import pandas as pd
import datetime

# Ganti sesuai survey kamu
SURVEY_ID = 811491

# Inisialisasi koneksi LimeSurvey
client = Client(
    'https://alamat_limesurvey_kamu/index.php/admin/remotecontrol',
    'username_kamu',
    'password_kamu'
)

# Buat nama file berdasarkan waktu sekarang
current_time = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
output_file = f"responses_{SURVEY_ID}_{current_time}.xlsx"

print("Downloading responses...")

# Ambil data responses dalam format CSV (lebih stabil lalu diubah ke XLSX)
with io.BytesIO() as file:
    file.write(client.export_responses(
        SURVEY_ID,
        file_format="csv",          # ambil dalam bentuk CSV dulu
        heading_type='code',        # gunakan code pertanyaan
        response_type='long',       # isi teks panjang
        completion_status='all'     # ambil semua, termasuk incomplete
    ))
    file.seek(0)

    # Baca CSV ke DataFrame pandas
    responses_df = pd.read_csv(file, delimiter=";", low_memory=False)

# Simpan ke Excel
responses_df.to_excel(output_file, index=False)
print(f"Responses saved as {output_file}")

Simpan file tersebut dan beri nama misalnya getDataXLSX.py

Nantinya kamu tinggal mausk ke folder yang bersangkutan dan jalankan dengan perintah:

python getDataXLSX.py

Tunggu beberapa saat, dan kita akan mendapatkan data dalam bentuk xlsx…

Update 2025-10-27:

Tadi ada laporan dari analis yang mencoba mendownload data, namun ada error. Setelah saya analisis karena data terlalu besar. Akhirnya saya memodifikasi skrip agar bisa download data dari id sekian ke id sekian. Nanti digabungkan sendiri

 

"""
Script created by Edy Santoso ([email protected])
Modified on: 2025-10-27
Purpose: Export LimeSurvey responses directly to XLSX
"""

from citric import Client
import io
import pandas as pd
import datetime

# Ganti sesuai survey kamu
SURVEY_ID = 811491
ID_START = 5001
ID_END = 5010

# Inisialisasi koneksi LimeSurvey
client = Client(
    'https://alamat_limesurvey_kamu/index.php/admin/remotecontrol',
    'username_kamu',
    'password_kamu'
)

# Buat nama file berdasarkan waktu sekarang
current_time = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
output_file = f"responses_{SURVEY_ID}_{current_time}.xlsx"

print("Downloading responses...")

# Ambil data responses dalam format CSV (lebih stabil lalu diubah ke XLSX)
with io.BytesIO() as file:
    file.write(client.export_responses(
        SURVEY_ID,
        file_format="csv",          # ambil dalam bentuk CSV dulu
        heading_type='code',        # gunakan code pertanyaan
        response_type='long',       # isi teks panjang
        completion_status='all'     # ambil semua, termasuk incomplete
        from_response_id=ID_START,  # id start
        to_response_id=ID_END       # id end 
    ))
    file.seek(0)

    # Baca CSV ke DataFrame pandas
    responses_df = pd.read_csv(file, delimiter=";", low_memory=False)

# Simpan ke Excel
responses_df.to_excel(output_file, index=False)
print(f"Responses saved as {output_file}")

Berikut parameter pada export_responses() jika ingin melakukan modifikasi output:

survey_id (int) – Survey to add the response to.
token (str | None) – Optional participant token to get responses for.
file_format (str | citric.enums.ResponsesExportFormat) – Type of export. One of PDF, CSV, XLS, DOC or JSON.
language (str | None) – Export responses made to this language version of the survey.
completion_status (str | citric.enums.SurveyCompletionStatus) – Incomplete, complete or all.
heading_type (str | citric.enums.HeadingType) – Use response codes, long or abbreviated titles.
response_type (str | citric.enums.ResponseType) – Export long or short text responses.
from_response_id (int | None) – First response to export.
to_response_id (int | None) – Last response to export.
fields (collections.abc.Sequence[str] | None) – Which response fields to export. If none, exports all fields.
additional_options (citric.types.ExportAdditionalOptions | None) – Dictionary of additional options to format the export.

Okey demikian

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.