tokenize = CountVectorizer().build_tokenizer()

def features(document):
    terms = tokenize(document)
d = {'text_length': len(terms), 'text_spam': whatever_this_means}
for t in terms:
    d[t] = d.get(t, 0) + 1
return d
vect = DictVectorizer()
X_train = vect.fit_transform(features(d) for d in documents)
Concatenate custom features with CountVectorizer