pymongo – Python driver for MongoDB — PyMongo 2.5 documentation

### Navigation

- index
- modules |
- next |
- previous |
- PyMongo 2.5 documentation »
- API Documentation »

# `pymongo` – Python driver for MongoDB

Python driver for MongoDB.

`pymongo.``version` = '2.5'

  Current version of PyMongo.

`pymongo.``MongoClient`

  Alias for `pymongo.mongo_client.MongoClient`.

`pymongo.``MongoReplicaSetClient`

  Alias for `pymongo.mongo_replica_set_client.MongoReplicaSetClient`.

class `pymongo.read_preferences.``ReadPreference`

  An enum that defines the read preference modes supported by PyMongo. Used in three cases:

  `MongoClient` connected to a single host:

  - PRIMARY: Queries are allowed if the host is standalone or the replica set primary.
  - All other modes allow queries to standalone servers, to the primary, or to secondaries.

  `MongoClient` connected to a mongos, with a sharded cluster of replica sets:

  - PRIMARY: Queries are sent to the primary of a shard.
  - PRIMARY_PREFERRED: Queries are sent to the primary if available, otherwise a secondary.
  - SECONDARY: Queries are distributed among shard secondaries. An error is raised if no secondaries are available.
  - SECONDARY_PREFERRED: Queries are distributed among shard secondaries, or the primary if no secondary is available.
  - NEAREST: Queries are distributed among all members of a shard.

  `MongoReplicaSetClient`:

  - PRIMARY: Queries are sent to the primary of the replica set.
  - PRIMARY_PREFERRED: Queries are sent to the primary if available, otherwise a secondary.
  - SECONDARY: Queries are distributed among secondaries. An error is raised if no secondaries are available.
  - SECONDARY_PREFERRED: Queries are distributed among secondaries, or the primary if no secondary is available.
  - NEAREST: Queries are distributed among all members.

`pymongo.``has_c`()

  Is the C extension installed?

  New in version 1.5.

Sub-modules:

- `connection` – Tools for connecting to MongoDB
- `database` – Database level operations
- `collection` – Collection level operations
- `cursor` – Tools for iterating over MongoDB query results
- `errors` – Exceptions raised by the `pymongo` package
- `master_slave_connection` – Master-slave connection to MongoDB
- `message` – Tools for creating messages to be sent to MongoDB
- `mongo_client` – Tools for connecting to MongoDB
- `mongo_replica_set_client` – Tools for connecting to a MongoDB replica set
- `pool` – Pool module for use with a MongoDB client.
- `replica_set_connection` – Tools for connecting to a MongoDB replica set
- `son_manipulator` – Manipulators that can edit SON documents as they are saved or retrieved
- `cursor_manager` – Managers to handle when cursors are killed after being closed – DEPRECATED
- `uri_parser` – Tools to parse and validate a MongoDB URI

### Navigation

- index
- modules |
- next |
- previous |
- PyMongo 2.5 documentation »
- API Documentation »