Change User Permission or role using python code

Change User Permission or role in server script.
ex:
i have created application(doc) with primary applicant (user 1) and secondary applicant (user 2 ) so when user 2 or secondary applicant logged in to the system that application(doc) should have read permission only for that single application(doc) but that applicant able to create its own application where that secondary applicant is that primary applicant to for that 2nd application.