Create new user in server script

I have a server script (in python) (DocType (the name of the DocType is Student)- before insert, but I think it doesn’t matter).
I would like to add a new user (an instance of User DocType) when a Student is added.
How can I do it? I would like to send an email with the registration details, too.

Solved, with this code:

NewUser = frappe.get_doc({
'doctype': 'User',


Hello There edemsz,
your code is not complete, I am trying to do the same and I get an error. Asking me about First Name field

Could you please paste your complete code?

I solved with this :slight_smile:
doc was the the document where I was pulling data from
doctype = ‘User’,
email = doc.email_id,
name = doc.email_id,
last_name =doc.last_name,
first_name = doc.first_name
frappe.msgprint("A user was created with email "+ doc.email_id);

1 Like