Event model

The DDJVU API provides for efficiently decoding and displaying DjVu documents. It provides for displaying images without waiting for the complete DjVu data. Images can be displayed as soon as sufficient data is available. A higher quality image might later be displayed when further data is available. The DjVu library achieves this using a complicated scheme involving multiple threads. The DDJVU API hides this complexity with a familiar event model.


Version of the DDJVU API.

class djvu.decode.Context(argv0)

This method is called, in a separate thread, for every received message, before any blocking method finishes.

By default do something roughly equivalent to:

if message.job is not None:
elif message.document is not None:

You may want to override this method to change this behaviour.

All exceptions raised by this method will be ignored.


Return the internal message queue.


Get message from the internal context queue.

Returns:a Message instance
Returns:None if wait is false and no message is available.
new_document(uri[, cache=True])

Creates a decoder for a DjVu document and starts decoding. This method returns immediately. The decoding job then generates messages to request the raw data and to indicate the state of the decoding process.

uri specifies an optional URI for the document. The URI follows the usual syntax (protocol://machine/path). It should not end with a slash. It only serves two purposes:

  • The URI is used as a key for the cache of decoded pages.
  • The URI is used to document NewStreamMessage messages.

Setting argument cache to a true value indicates that decoded pages should be cached when possible.

It is important to understand that the URI is not used to access the data. The document generates NewStreamMessage messages to indicate which data is needed. The caller must then provide the raw data using a NewStreamMessage.stream object.

class djvu.decode.FileUri(filename)

To open a local file, provide a FileUri instance as an uri.

Localized characters in uri should be in URI-encoded.

Return type:Document
Raises:JobFailed – on failure.
class djvu.decode.Job

A job.


Get message from the internal job queue.

Returns:a Message instance.
Returns:None if wait is false and no message is available.

Indicate whether the decoding job is done.


Indicate whether the decoding job is done.

Returns:the internal message queue.
Returns:a JobException subclass indicating the job status.

Attempt to cancel the job.

This is a best effort method. There no guarantee that the job will actually stop.


Wait until the job is done.