Disable duplicate check for apex class?

I think you can bypass duplicate check with DMLOptions.DuplicateRuleHeader Class: documentation

Sample:

Database.DMLOptions dml = new Database.DMLOptions();
dml.DuplicateRuleHeader.AllowSave = true; 
Account duplicateAccount = new Account(Name='dupe'); 
Database.SaveResult sr = Database.insert(duplicateAccount, dml); 
if (sr.isSuccess()) {   
 System.debug('Duplicate account has been inserted in Salesforce!'); 
}

Apparently the AllowSave only works if the duplicate rule is an Alert rule, not a Block rule.

When you try to save a record that’s identified as a duplicate record by a duplicate rule, you’ll receive a duplicate error. If the duplicate rule contains the Allow action, an attempt will be made to bypass the error.

Documentation