Drake can rest a little easier for the next few years, now that a judge has granted his request to prevent an allegedly deranged fan from contacting him or his family.

According to new legal docs obtained by TMZ Hip Hop … Drake’s attorneys, Larry Stein and Ashley Yeargan, were in court for Tuesday’s hearing, which ended with the judge approving a 3-year restraining order.

The alleged stalker was not in court, but will be served the order. As we reported, Drake’s been dealing with this woman for a while now – she was arrested for trespassing at his Hollywood Hills estate in 2017, and she even attempted to file a $4 billion defamation suit against him … as if the Certified Lover Boy was the one harassing her.

The court determined the woman was “given timely and proper notice” to give her side of the story – for instance, explaining the email she allegedly sent Drake, saying “put a bullet through your head now bitch.”

To this point, she hasn’t provided any such explanation … and, as it stands, the restraining order requires her to say at least 100 yards away from Drizzy and his family.