Google App Engine

The BlobReader Class

A Python application can read Blobstore values through a file-like interface, implemented by the BlobReader class. The reader implementation streams data from the Blobstore as needed, so values larger than 1 megabyte can be read, using multiple service calls behind the scenes. This interface is read-only: Blobstore values cannot be modified directly by the application.

BlobReader is provided by the google.appengine.ext.blobstore module.

  1. Introduction
  2. BlobReader()
  3. Instance Methods
  4. Instance properties:


An application can read data from Blobstore values using an interface similar to a Python file object. This interface can start reading a value at any byte position, and uses multiple service calls and buffering, so an application can access the full size of the value despite the limit on the size of a single service call response.

The BlobReader class can take one of three values as an argument to its constructor:

The object implements the familiar file methods for reading the value. The application cannot modify the Blobstore value; file methods for writing are not implemented.

from google.appengine.ext import blobstore

# blob_key = ...

# Instantiate a BlobReader for a given Blobstore value.
blob_reader = blobstore.BlobReader(blob_key)

# Instantiate a BlobReader for a given Blobstore value, setting the
# buffer size to 1 MB.
blob_reader = blobstore.BlobReader(blob_key, buffer_size=1048576)

# Instantiate a BlobReader for a given Blobstore value, setting the
# initial read position.
blob_reader = blobstore.BlobReader(blob_key, position=4194304)

# Read the entire value into memory. This may take a while depending
# on the size of the value and the size of the read buffer, and is not
# recommended for large values.
value =

# Set the read position, then read 100 bytes.
data =

# Read the value, one line (up to and including a '\n' character) at a time.
for line in blob_reader:
    # ...


class BlobReader(blob_key, buffer_size=131072, position=0)

A file-like interface for reading a Blobstore value.


The BlobInfo, BlobKey, or string form of a blob key of the Blobstore value to read. Required.
The size of the input buffer, as a number of bytes. The default is 128 kilobytes (131,072 bytes). The buffer size cannot exceed 1 megabyte (1,048,576 bytes).
The byte position of the first byte to read. The default is to start reading at the beginning of the value (byte position 0).

Instance Methods

A BlobReader instance has methods and properties similar to a Python file object. Methods that would modify a file (such as write()) are not implemented, and raise an IOError. You can pass a BlobReader object to code expecting a (read-only) file interface (such as the zipfile module).

Methods and interfaces include:

  • iterator and iterable interfaces
  • interfaces to support serialization of BlobReader state via pickle
  • close()
  • read(size=-1)
  • readline(size=-1)
  • readlines(sizehint=None)
  • seek(offset, whence=SEEK_SET)
  • tell()
  • the closed property

Instance Properties

In addition to the file-like interface, the BlobReader class provides read-only access to a Blobstore value's BlobInfo object through the blob_info property.

The BlobInfo object for the instance's Blobstore value.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.