Skip to content

eguven/mongo-python-driver-py3k

 
 

Repository files navigation

PyMongo3

Info

See the mongo site for more information. See github for the latest source.

Author

Mike Dirolf <mike@10gen.com>

About

This is a semi-official port of PyMongo 1.9+ to Python 3.x. Semantics are mostly compatible with the official PyMongo branch, except for a few things listed in the next section. This port can currently only be used on Python 3.1 or later. Compatibility with Python 2.6+ may be added in the future.

The PyMongo distribution contains tools for interacting with MongoDB database from Python. The bson package is an implementation of the BSON format for Python. The pymongo package is a native Python driver for MongoDB. The gridfs package is a gridfs implementation on top of pymongo.

About the Py3K port

Byte strings and unicode strings were clearly separated in Python 3. PyMongo3 adapts to these changes by decoding Binary of subtype 0 to the "bytes" type. There has been considerable effort to make things work the way developers would expect them to, with regards to the new semantics of Python 3. If you feel that the new semantics don't match your expectations, feel free to ask on the mailing list or create a new issue on github (see the next section for that).

Issues / Questions / Feedback

Any issues with, questions about, or feedback for PyMongo3 should be sent to the mongodb-user list on Google Groups. For confirmed issues or feature requests, open a case on github. Please do not e-mail any of the PyMongo developers directly with issues or questions - you're more likely to get an answer on the list.

Installation

If you have distribute installed you should be able to do easy_install pymongo3 to install PyMongo. Otherwise you can download the project source and do python setup.py install to install.

Dependencies

The PyMongo3 distribution is supported and tested on Python 3.x, where x >= 1.

Additional dependencies are:

  • (to generate documentation) sphinx
  • (to auto-discover tests) nose

Examples

Here's a basic example (for more see the examples section of the docs):

>>> import pymongo >>> connection = pymongo.Connection("localhost", 27017) >>> db = connection.test >>> db.name() 'test' >>> db.my_collection Collection(Database(Connection('localhost', 27017), 'test'), 'my_collection') >>> db.my_collection.save({"x": 10}) ObjectId('4aba15ebe23f6b53b0000000') >>> db.my_collection.save({"x": 8}) ObjectId('4aba160ee23f6b543e000000') >>> db.my_collection.save({"x": 11}) ObjectId('4aba160ee23f6b543e000002') >>> db.my_collection.find_one() {'x': 10, '_id': ObjectId('4aba15ebe23f6b53b0000000')} >>> for item in db.my_collection.find(): ... print item["x"] ... 10 8 11 >>> db.my_collection.create_index("x") 'x_1' >>> for item in db.my_collection.find().sort("x", pymongo.ASCENDING): ... print item["x"] ... 8 10 11 >>> [item["x"] for item in db.my_collection.find().limit(2).skip(1)] [8, 11]

Documentation

You will need sphinx installed to generate the documentation. Documentation can be generated by running python setup.py doc. Generated documentation can be found in the doc/build/html/ directory.

Testing

The easiest way to run the tests is to install the Python 3.x compatible fork of nosetests, nose3 and run nosetests3 or python setup.py test in the root of the distribution. Tests are located in the test/ directory.

About

PyMongo - the Python driver for MongoDB

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 81.7%
  • C 17.8%
  • Shell 0.5%