multi signature – P2SH address as a product of public keys

Assuming the multisig 2 of 3, if I do have extended public keys (xpub) for all 3 cosigners (with proper derivations), can I somewhat get the result address (P2SH)? How to calculate the “script” out of these public keys?

Would be cool to have scheme for doing so or a code/pseudocode in python if possible.