title: Read BSON file in Python?
body: <p>I want to read a BSON format Mongo dump in Python and process the data. I am using the Python <a href="https://github.com/martinkou/bson" rel="noreferrer">bson package</a> (which I'd prefer to use rather than have a pymongo dependency), but it doesn't explain how to read from a file.</p>
  
  <p>This is what I'm trying: </p>
  
  <pre><code>bson_file = open('statistics.bson', 'rb')
  b = bson.loads(bson_file)
  print b[0]
  </code></pre>
  
  <p>But I get:</p>
  
  <pre><code>Traceback (most recent call last):
    File "test.py", line 11, in &lt;module&gt;
      b = bson.loads(bson_file)
    File "/Library/Python/2.7/site-packages/bson/__init__.py", line 75, in loads
      return decode_document(data, 0)[1]
    File "/Library/Python/2.7/site-packages/bson/codec.py", line 235, in decode_document
      length = struct.unpack("&lt;i", data[base:base + 4])[0]
  TypeError: 'file' object has no attribute '__getitem__'
  </code></pre>
  
  <p>What am I doing wrong?</p>