I'm not sure that 3-of-5 needs to be much different than 2-of-3 but here's some code that'll do it. This is from Rein (
http://reinproject.org) which generates 2-of-3 addresses to escrow freelancing transactions.
from bitcoin.core import b2x, lx, x
from bitcoin.core.script import CScript, OP_CHECKMULTISIG, OP_CHECKSIGVERIFY
from bitcoin.wallet import CBitcoinAddress
pubkeys = ['0304B9F99B92F1DB45423A741B12DD59F92666865A6FC348C4BC23685A4E3EE871',
'02B4F0BF69C91018259127008EAC434E79ACD7EF47A0D100F4E76C73498E63D029',
'026933041E0B3EF4382CFFA5B2ADCB9D8A45A450827BEF8F14E6154013C0DEE77C',
'028898A9805506DBD73DF96DD6186E651F41FC89DE6973730E0EF03C7CA75F4890',
'030BD98B6B6A4228E47A23A34CE339655BF234791171B76C985219E5BC656CD057']
def build_3_of_5(pubkeys):
txin_redeemScript = CScript([3, x(pubkeys[0]), x(pubkeys[1]), x(pubkeys[2]), x(pubkeys[3]), x(pubkeys[4]), 5, OP_CHECKMULTISIG])
txin_scriptPubKey = txin_redeemScript.to_p2sh_scriptPubKey()
txin_p2sh_address = CBitcoinAddress.from_scriptPubKey(txin_scriptPubKey)
return (b2x(txin_redeemScript), str(txin_p2sh_address))
At least the redeem script this generated checked out ok with
https://coinb.inoutput:
('53210304b9f99b92f1db45423a741b12dd59f92666865a6fc348c4bc23685a4e3ee8712102b4f0bf69c91018259127008eac434e79acd7ef47a0d100f4e76c73498e63d02921026933041e0b3ef4382cffa5b2adcb9d8a45a450827bef8f14e6154013c0dee77c21028898a9805506dbd73df96dd6186e651f41fc89de6973730e0ef03c7ca75f489021030bd98b6b6a4228e47a23a34ce339655bf234791171b76c985219e5bc656cd05755ae',
'3HHn8SQPUrpeynkYP4ZqodGDpTsxiJMVDN')