How to get report data in python

I want to fetch report data in python code

> # Set the report name and filters
> report_name = "Test Report"
> filters = {
>     "warehouse": "Test Warehouse"
> }
> # Fetch the report data
> report = frappe.get_doc("Report", report_name)
> report_data = report.get_data()
> log(report_data)

it is working only when report doesn’t have any filters. how to pass filters? @shariquerik

Hi @Rehan_Ansari,

I think it should be the below example.

Please check the syntax and try it.

# Set the report name and filters
report_name = "Test Report"
filters = {
    "warehouse": "Test Warehouse"
}

# Fetch the report data
report_data = frappe.get_all(report_name, filters=filters)
print(report_data)

I hope this helps.
Thank You!

1 Like

but frappe.get_all is only for DocType But i want to fetch data from Reports in python.


this is the report which have date filters and i want to pass filters also to get report data in any frappe api or in python?

Hi,
report_data= report.get_data() will return a tuple which consist of (columns, data)
so report_data[0] will contain fields definition and report_data[1] will contain the data.
maybe you can try to filter it manualy with:
result = filter( lambda data: data[‘department’]==“DEPARTMENT”, report_data[1])
tuple( result )
here department is my field name and its one of the result field

Just try it on my own report though… it might not work with yours cause ‘warehouse’ is not one of the result fields but i hope it will help somehow…

regards,

@atprana
Hello
report_gl = frappe.get_doc(“Report”, “General Ledger”)
report_gl_filters = {“party_type”: “Customer”,“party”: customer }
columns_gl, data_gl = report_gl.get_data(limit=500, user=“Administrator”, filters=report_gl_filters, as_dict=True)
print(“data”,columns_gl)

when I print data I get emptry tuple
please help me
Actually I want to get data form General Ledger report when threre is one filter for customer name