ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

Can i import libraries in server side scripting?

i want to import some libraries in server side scripting like import date or something else and it didn’t work for me is the any help ?

I think you will need to whitelist your scripts (not a “normal” API script). See:

i didn’t found answer for my question there so i asked here but thanks to your respond

What you should have is something like the following:
you should create a file (e.g. date_info.py) on the server that should start with the following:

import frappe
import datetime
import whaterver_other_library

@frappe.whitelist()

def retrive_date():

	return(datetime.timedelta(microseconds=-1).microseconds)

and if you need a client script to call it:

frappe.call({
	method: "path.to.date_info.py.retrive_date", //path should have dot (.)
\\instead of forwardslashes and its root should be:
//  /home/frappe_user/frappe-bench/apps/name_of_default_app (i think)
// for example see below
	freeze: true,
	callback: (r) => {
		frm.set_value('whatever_field_in_your_doctype',r.message);
	}
});

/home/frappe/frappe-bench/apps/bitum_laboratory/bitum_laboratory/bitum_laboratory/doctype/comparison_report
example of a path:
/home/frappe_user/frappe-bench/apps/app_name/app_name/app_name/doctype/test_doctype/date_info.py
with retrive_date function defind would become:
method:"app_name.app_name.doctype.test_doctype.date_info.retrive_date"

Thanks , it worked now

Those external files will disappear (unless you have manual backups) if you have to reinstall erpnext or server crashes in future.

Better option is to create Apps, and backed up in version control system. App installation is easier and risk free compared to manually creating those files again.