paperap.models.document.download.model module

Document download functionality for Paperless-NgX documents.

This module provides classes for handling document file downloads from a Paperless-NgX server, including different retrieval modes (download, preview, thumbnail) and metadata about the downloaded files.

class paperap.models.document.download.model.RetrieveFileMode(*values)[source]

Bases: str, Enum

Enum for document file retrieval modes.

This enum defines the different ways a document can be retrieved from the Paperless-NgX server, each corresponding to a different endpoint and potentially different file format.

DOWNLOAD

Retrieve the full document file for downloading.

PREVIEW

Retrieve a preview version of the document (typically PDF).

THUMBNAIL

Retrieve a thumbnail image of the document.

DOWNLOAD = 'download'
PREVIEW = 'preview'
THUMBNAIL = 'thumbnail'
class paperap.models.document.download.model.DownloadedDocument(**data)[source]

Bases: StandardModel

Represents a downloaded Paperless-NgX document file.

This model stores both the binary content of a downloaded document file and metadata about the file, such as its content type and suggested filename. It is typically used as a return value from document download operations.

mode

The retrieval mode used (download, preview, or thumbnail). Determines which endpoint was used to retrieve the file.

Type:

RetrieveFileMode | None

original

Whether to retrieve the original file (True) or the archived version (False). Only applicable for DOWNLOAD mode.

Type:

bool

content

The binary content of the downloaded file.

Type:

bytes | None

content_type

The MIME type of the file (e.g., “application/pdf”).

Type:

str | None

disposition_filename

The suggested filename from the Content-Disposition header.

Type:

str | None

disposition_type

The disposition type from the Content-Disposition header (typically “attachment” or “inline”).

Type:

str | None

Examples

>>> # Download a document
>>> doc = client.documents.get(123)
>>> downloaded = doc.download_content()
>>> print(f"Downloaded {len(downloaded.content)} bytes")
>>> print(f"File type: {downloaded.content_type}")
>>> print(f"Filename: {downloaded.disposition_filename}")
Parameters:

data (Any)

mode: RetrieveFileMode | None
original: bool
content: bytes | None
content_type: str | None
disposition_filename: str | None
disposition_type: str | None
class Meta(model)[source]

Bases: Meta

Metadata for the DownloadedDocument model.

Defines which fields are read-only and should not be modified by the client.

Parameters:

model (type[_Self])

read_only_fields: ClassVar[set[str]] = {'content', 'content_type', 'disposition_filename', 'disposition_type', 'id'}
blacklist_filtering_params: ClassVar[set[str]] = {}
field_map: dict[str, str] = {}
filtering_disabled: ClassVar[set[str]] = {}
filtering_fields: ClassVar[set[str]] = {'_resource', 'content', 'content_type', 'disposition_filename', 'disposition_type', 'id', 'mode', 'original'}
supported_filtering_params: ClassVar[set[str]] = {'id', 'id__in', 'limit'}
model: type[_Self]
name: str
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'ignore', 'populate_by_name': True, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

We need to both initialize private attributes and call the user-defined model_post_init method.

Parameters:
Return type:

None

id: int