from pymongo import MongoClient
# Assuming youre running mongod on 'localhost' with port 27017
c = MongoClient('localhost',27017)
c.database_names()
Update 2020:
DeprecationWarning: database_names is deprecated
Use the following:
c.list_database_names()