You can use the command interface in pymongo to do this. Here's a
simple example with two hosts:
Start up two hosts on your local machine:
mongod --dbpath ~/data/replica/repl0/db0 --replSet repl0
mongod --dbpath ~/data/replica/repl0/db1 --replSet repl0 --port 27018
Then in the python shell:
>>> import pymongo
>>> c = pymongo.Connection()
>>> conf = {'_id': 'repl0', 'members': [{'_id': 0, 'host': 'localhost:27017'}, {'_id': 1, 'host': 'localhost:27018'}]}
>>> c.admin.command('replSetInitiate', conf)
{u'info': u'Config now saved locally. Should come online in about a
minute.', u'ok': 1.0}
That's all there is to it.
Note: this config is just a simple example. In a production deployment
you would want at least 3 active data nodes or 2 active data nodes and
an arbiter.
> I know replica sets can be setup using commands like (fromhttp://
api.mongodb.org/python/current/examples/replica_set.html):