May I recommend you take a look at scikit-learn? This is a very well regarded library in the Python community with a very simple a consistent API. They have also implemented a cosine similarity metric. This is an example taken from here of how you could do it in 3 lines of code:
>>> from sklearn.feature_extraction.text import TfidfVectorizer
>>> vect = TfidfVectorizer(min_df=1)
>>> tfidf = vect.fit_transform(["I'd like an apple",
... "An apple a day keeps the doctor away",
... "Never compare an apple to an orange",
... "I prefer scikit-learn to Orange"])
>>> (tfidf * tfidf.T).A
array([[ 1. , 0.25082859, 0.39482963, 0. ],
[ 0.25082859, 1. , 0.22057609, 0. ],
[ 0.39482963, 0.22057609, 1. , 0.26264139],
[ 0. , 0. , 0.26264139, 1. ]])