how to issue a "show dbs" from pymongo

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()

as today it's

from pymongo import MongoClient
# client = MongoClient('host', port_number)
client = MongoClient('localhost', 27017)
cursor = client.list_databases()
for db in cursor:
    print(db)

or

from pymongo import MongoClient
# client = MongoClient('host', port_number)
client = MongoClient('localhost', 27017)
for db in client.list_databases():
    print(db)

If you use database_names, you will get "DeprecationWarning: database_names is deprecated. Use list_database_names instead."


With Python3.5, you can try this way

from pymongo import MongoClient
client = MongoClient('localhost', 27017)
print(client.list_database_names())