Saving Category/Entry Information as csv file in Python

I am new to Kaltura and use of API to get/put data.
I followed the Workflow guides in Kaltura Developer website and manage to search for entries like by filter.creatorIdEqual = “someone”, and is able to list the results which contains rows of records in dictionary format.

I have 3 questions:

  1. How can I save the search results as a csv file? I tried to write the dictionary type search results to csv file using various methods but failed. Sample codes as follows.

  2. How to overcome the limits in the no. of records returned in the search results. Currently, I only see the most 30 records returned in the search results but in actual fact there are more than 200 entries belonging to the creatorId.

  3. Where can I find any information related to the filesize of an entry in Kaltura. I understand that an entry in Kaltura may have a few flavors, which with a different entryId. May I know where can I find out more about these flavors and their meta data like creation date and filesize.

Thank you.
Lay Kock :slightly_smiling_face:

The python codes I used to save the search research are as follows.

Find entries by CreatorId

filter = KalturaMediaEntryFilter()
filter.creatorIdEqual = “someone”;
pager = KalturaFilterPager()

result = client.media.list(filter, pager)
for item in result.objects:
print(item.dict); # this yields the search results with 30 records in dictionary type successfully

Write results to a csv file using Import Pandas as Pd

for item in result.objects:
df = pd.DataFrame.from_dict(item.dict, orient=“index”)
df.to_csv(‘entries_file.csv’, header=False)

The line df = pd.DataFrame.from_dict(item.dict, orient=“index”) yields an error AttributeError: ‘str’ object has no attribute ‘items’

Write results to a csv file using Import csv

with open(‘filename.csv’, ‘w’) as csv_file:
writer = csv.write(csv_file)
for item in result.objects:
write.writerow(item.dict);

This only yields the column headings for each records

Note: item.dict should have 2 underscores before and after ‘dict’. Somehow, the WYSIWYG editor change it to a bolded dict.

Just to add on. Followings are the python codes I used to write dictionary data to csv file. It works for a predefined dictionary data. However, the same codes could not be used to save the item.dict dictionary which contains the metadata info of an entry.

  1. Write dictionary data to a csv file using csv
    import csv
    mydict = {‘key1’: ‘value_a’, ‘key2’: ‘value_b’, ‘key3’: ‘value_c’}

with open(‘dict.csv’, ‘w’) as csv_file:
writer = csv.writer(csv_file)
for key, value in mydict.items():
writer.writerow([key, value])
csv_file.close()

  1. Write dictionary data to a csv file using Pandas
    import pandas as pd
    mydict = {‘key1’: ‘value_a’, ‘key2’: ‘value_b’, ‘key3’: ‘value_c’}

df = pd.DataFrame.from_dict(data=mydict, orient=‘index’)
df.to_csv(‘dict_file.csv’, header=False)

The type (class) of the item.dict is dict.
<class ‘dict’>