With a lot of help from this answer, I did it!
I know op probably moved past this, but this answer is nowhere in the internet, so here's the solution, for posterity's sake!
from OpenSSL import crypto
with open(cert) as cert_file:
cert_buf = cert_file.read()
with open(key) as key_file:
key_buf = key_file.read()
pkey = crypto.load_privatekey(crypto.FILETYPE_PEM, key_buf)
signcert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_buf)
bio_in = crypto._new_mem_buf(text.encode())
PKCS7_NOSIGS = 0x4 # defined in pkcs7.h
pkcs7 = crypto._lib.PKCS7_sign(signcert._x509, pkey._pkey, crypto._ffi.NULL, bio_in, PKCS7_NOSIGS) # noqa
bio_out = crypto._new_mem_buf()
crypto._lib.i2d_PKCS7_bio(bio_out, pkcs7)
sigbytes = crypto._bio_to_string(bio_out)
Keep in mind, it uses some undocumented pyopenssl functions.