bson – Tools for working with BSON in Python

Tools for dealing with Mongo’s BSON data representation.

Generally not needed to be used by application developers.

class pymongo.bson.BSON

Bases: str

BSON data.

Represents binary data storable in and retrievable from Mongo.

classmethod from_dict(dct, check_keys=False)

Create a new BSON instance from a mapping type (like dict).

Raises TypeError if dct is not a mapping type, or contains keys that are not instances of basestring. Raises InvalidDocument if dct cannot be converted to BSON.

  • dct: mapping type representing a document
  • check_keys (optional): check if keys start with ‘$’ or contain ‘.’, raising InvalidName in either case
Get the dictionary representation of this data.

Check that the given string represents valid BSON data.

Raises TypeError if bson is not an instance of str. Returns True if bson is valid BSON, False otherwise.

  • bson: the data to be validated

Previous topic

objectid – Tools for working with MongoDB ObjectIds

Next topic

message – Tools for creating messages to be sent to MongoDB

This Page