paperap.models.document.queryset module

Document QuerySet module for Paperless-ngx API interactions.

This module provides specialized QuerySet classes for Document and DocumentNote models, with methods for filtering, searching, and performing bulk operations on documents.

class paperap.models.document.queryset.CustomFieldQuery(field: str, operation: _OperationType, value: Any)[source]

Bases: NamedTuple

A named tuple representing a custom field query.

Used to construct complex queries for document custom fields.

field

The name of the custom field to query.

operation

The operation to perform (e.g., “exact”, “contains”, “range”).

value

The value to compare against.

field: str

Alias for field number 0

operation: Union[str, CustomFieldQuery, tuple[str, Union[str, _QueryParam], Any]]

Alias for field number 1

value: Any

Alias for field number 2

class paperap.models.document.queryset.DocumentNoteQuerySet(resource, filters=None, _cache=None, _fetch_all=False, _next_url=None, _last_response=None, _iter=None, _urls_fetched=None)[source]

Bases: StandardQuerySet[DocumentNote]

QuerySet for document notes.

Provides standard querying capabilities for DocumentNote objects. Inherits all functionality from StandardQuerySet without additional specialization.

Parameters:
  • resource (BaseResource[_Model, Self])

  • filters (dict[str, Any] | None)

  • _cache (list[_Model] | None)

  • _fetch_all (bool)

  • _next_url (str | None)

  • _last_response (ClientResponse)

  • _iter (Iterator[_Model] | None)

  • _urls_fetched (list[str] | None)

class paperap.models.document.queryset.DocumentQuerySet(resource, filters=None, _cache=None, _fetch_all=False, _next_url=None, _last_response=None, _iter=None, _urls_fetched=None)[source]

Bases: StandardQuerySet[Document], HasOwner

QuerySet for Paperless-ngx documents with specialized filtering methods.

This class extends StandardQuerySet to provide document-specific filtering, searching, and bulk operations. It includes methods for filtering by document metadata, content, custom fields, and more, as well as bulk operations like merging, rotating, and updating document properties.

Examples

>>> # Search for documents
>>> docs = client.documents().search("invoice")
>>> for doc in docs:
...     print(doc.title)
>>> # Find documents similar to a specific document
>>> similar_docs = client.documents().more_like(42)
>>> for doc in similar_docs:
...     print(doc.title)
>>> # Filter by correspondent and document type
>>> filtered_docs = client.documents().correspondent(5).document_type("Invoice")
>>> for doc in filtered_docs:
...     print(f"{doc.title} - {doc.created}")
Parameters:
  • resource (BaseResource[_Model, Self])

  • filters (dict[str, Any] | None)

  • _cache (list[_Model] | None)

  • _fetch_all (bool)

  • _next_url (str | None)

  • _last_response (ClientResponse)

  • _iter (Iterator[_Model] | None)

  • _urls_fetched (list[str] | None)

resource: DocumentResource
tag_id(tag_id)[source]

Filter documents that have the specified tag ID(s).

Parameters:

tag_id (int | list[int]) – A single tag ID or list of tag IDs.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Filter by a single tag ID
>>> docs = client.documents().tag_id(5)
>>>
>>> # Filter by multiple tag IDs
>>> docs = client.documents().tag_id([5, 7, 9])
tag_name(tag_name, *, exact=True, case_insensitive=True)[source]

Filter documents that have a tag with the specified name.

Parameters:
  • tag_name (str) – The name of the tag to filter by.

  • exact (bool) – If True, match the exact tag name, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Exact match (default)
>>> docs = client.documents().tag_name("Tax")
>>>
>>> # Contains match
>>> docs = client.documents().tag_name("invoice", exact=False)
>>>
>>> # Case-sensitive match
>>> docs = client.documents().tag_name("Receipt", case_insensitive=False)
title(title, *, exact=True, case_insensitive=True)[source]

Filter documents by title.

Parameters:
  • title (str) – The document title to filter by.

  • exact (bool) – If True, match the exact title, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Exact match (default)
>>> docs = client.documents().title("Electric Bill March 2023")
>>>
>>> # Contains match
>>> docs = client.documents().title("invoice", exact=False)
search(query)[source]

Search for documents using a query string.

This method uses the Paperless-ngx full-text search functionality to find documents matching the query string in their content or metadata.

Parameters:

query (str) – The search query string.

Return type:

DocumentQuerySet

Returns:

A queryset with the search results.

Examples

>>> # Search for documents containing "invoice"
>>> docs = client.documents().search("invoice")
>>> for doc in docs:
...     print(doc.title)
>>>
>>> # Search with multiple terms
>>> docs = client.documents().search("electric bill 2023")
more_like(document_id)[source]

Find documents similar to the specified document.

Uses Paperless-ngx’s similarity algorithm to find documents with content or metadata similar to the specified document.

Parameters:

document_id (int) – The ID of the document to find similar documents for.

Return type:

DocumentQuerySet

Returns:

A queryset with similar documents.

Examples

>>> # Find documents similar to document with ID 42
>>> similar_docs = client.documents().more_like(42)
>>> for doc in similar_docs:
...     print(doc.title)
>>>
>>> # Chain with other filters
>>> recent_similar = client.documents().more_like(42).created_after("2023-01-01")
correspondent(value=None, *, exact=True, case_insensitive=True, **kwargs)[source]

Filter documents by correspondent.

This method provides a flexible interface for filtering documents by correspondent, supporting filtering by ID, name, or slug, with options for exact or partial matching.

Any number of filter arguments can be provided, but at least one must be specified.

Parameters:
  • value (int | str | None) – The correspondent ID or name to filter by.

  • exact (bool) – If True, match the exact value, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching for string values.

  • **kwargs (Any) – Additional filters (slug, id, name).

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Raises:
  • ValueError – If no valid filters are provided.

  • TypeError – If value is not an int or str.

Examples

>>> # Filter by ID
>>> client.documents().correspondent(1)
>>> client.documents().correspondent(id=1)
>>>
>>> # Filter by name
>>> client.documents().correspondent("John Doe")
>>> client.documents().correspondent(name="John Doe")
>>>
>>> # Filter by name (partial match)
>>> client.documents().correspondent("John", exact=False)
>>>
>>> # Filter by slug
>>> client.documents().correspondent(slug="john-doe")
>>>
>>> # Filter by ID and name
>>> client.documents().correspondent(1, name="John Doe")
correspondent_id(correspondent_id)[source]

Filter documents by correspondent ID.

Parameters:

correspondent_id (int) – The correspondent ID to filter by.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Filter documents with correspondent ID 5
>>> docs = client.documents().correspondent_id(5)
correspondent_name(name, *, exact=True, case_insensitive=True)[source]

Filter documents by correspondent name.

Parameters:
  • name (str) – The correspondent name to filter by.

  • exact (bool) – If True, match the exact name, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Exact match (default)
>>> docs = client.documents().correspondent_name("Electric Company")
>>>
>>> # Contains match
>>> docs = client.documents().correspondent_name("Electric", exact=False)
correspondent_slug(slug, *, exact=True, case_insensitive=True)[source]

Filter documents by correspondent slug.

Parameters:
  • slug (str) – The correspondent slug to filter by.

  • exact (bool) – If True, match the exact slug, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Exact match (default)
>>> docs = client.documents().correspondent_slug("electric-company")
>>>
>>> # Contains match
>>> docs = client.documents().correspondent_slug("electric", exact=False)
document_type(value=None, *, exact=True, case_insensitive=True, **kwargs)[source]

Filter documents by document type.

This method provides a flexible interface for filtering documents by document type, supporting filtering by ID or name, with options for exact or partial matching.

Any number of filter arguments can be provided, but at least one must be specified.

Parameters:
  • value (int | str | None) – The document type ID or name to filter by.

  • exact (bool) – If True, match the exact value, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching for string values.

  • **kwargs (Any) – Additional filters (id, name).

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Raises:
  • ValueError – If no valid filters are provided.

  • TypeError – If value is not an int or str.

Examples

>>> # Filter by ID
>>> client.documents().document_type(1)
>>> client.documents().document_type(id=1)
>>>
>>> # Filter by name
>>> client.documents().document_type("Invoice")
>>> client.documents().document_type(name="Invoice")
>>>
>>> # Filter by name (partial match)
>>> client.documents().document_type("Inv", exact=False)
>>>
>>> # Filter by ID and name
>>> client.documents().document_type(1, name="Invoice")
document_type_id(document_type_id)[source]

Filter documents by document type ID.

Parameters:

document_type_id (int) – The document type ID to filter by.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Filter documents with document type ID 3
>>> docs = client.documents().document_type_id(3)
document_type_name(name, *, exact=True, case_insensitive=True)[source]

Filter documents by document type name.

Parameters:
  • name (str) – The document type name to filter by.

  • exact (bool) – If True, match the exact name, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Exact match (default)
>>> docs = client.documents().document_type_name("Invoice")
>>>
>>> # Contains match
>>> docs = client.documents().document_type_name("bill", exact=False)
storage_path(value=None, *, exact=True, case_insensitive=True, **kwargs)[source]

Filter documents by storage path.

This method provides a flexible interface for filtering documents by storage path, supporting filtering by ID or name, with options for exact or partial matching.

Any number of filter arguments can be provided, but at least one must be specified.

Parameters:
  • value (int | str | None) – The storage path ID or name to filter by.

  • exact (bool) – If True, match the exact value, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching for string values.

  • **kwargs (Any) – Additional filters (id, name).

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Raises:
  • ValueError – If no valid filters are provided.

  • TypeError – If value is not an int or str.

Examples

>>> # Filter by ID
>>> client.documents().storage_path(1)
>>> client.documents().storage_path(id=1)
>>>
>>> # Filter by name
>>> client.documents().storage_path("Invoices")
>>> client.documents().storage_path(name="Invoices")
>>>
>>> # Filter by name (partial match)
>>> client.documents().storage_path("Tax", exact=False)
>>>
>>> # Filter by ID and name
>>> client.documents().storage_path(1, name="Invoices")
storage_path_id(storage_path_id)[source]

Filter documents by storage path ID.

Parameters:

storage_path_id (int) – The storage path ID to filter by.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Filter documents with storage path ID 2
>>> docs = client.documents().storage_path_id(2)
storage_path_name(name, *, exact=True, case_insensitive=True)[source]

Filter documents by storage path name.

Parameters:
  • name (str) – The storage path name to filter by.

  • exact (bool) – If True, match the exact name, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Exact match (default)
>>> docs = client.documents().storage_path_name("Tax Documents")
>>>
>>> # Contains match
>>> docs = client.documents().storage_path_name("Tax", exact=False)
content(text)[source]

Filter documents whose content contains the specified text.

This method searches the OCR-extracted text content of documents.

Parameters:

text (str) – The text to search for in document content.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Find documents containing "invoice amount"
>>> docs = client.documents().content("invoice amount")
>>>
>>> # Chain with other filters
>>> recent_with_text = client.documents().content("tax").created_after("2023-01-01")
added_after(date_str)[source]

Filter documents added after the specified date.

Parameters:

date_str (str) – ISO format date string (YYYY-MM-DD).

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Find documents added after January 1, 2023
>>> docs = client.documents().added_after("2023-01-01")
added_before(date_str)[source]

Filter documents added before the specified date.

Parameters:

date_str (str) – ISO format date string (YYYY-MM-DD).

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Find documents added before December 31, 2022
>>> docs = client.documents().added_before("2022-12-31")
asn(value, *, exact=True, case_insensitive=True)[source]

Filter documents by archive serial number (ASN).

The archive serial number is a unique identifier assigned to documents in Paperless-ngx, often used for referencing physical documents.

Parameters:
  • value (str) – The archive serial number to filter by.

  • exact (bool) – If True, match the exact value, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Exact match (default)
>>> docs = client.documents().asn("2023-0042")
>>>
>>> # Contains match
>>> docs = client.documents().asn("2023", exact=False)
original_filename(name, *, exact=True, case_insensitive=True)[source]

Filter documents by original file name.

This filters based on the original filename of the document when it was uploaded.

Parameters:
  • name (str) – The original file name to filter by.

  • exact (bool) – If True, match the exact name, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Exact match (default)
>>> docs = client.documents().original_filename("scan_001.pdf")
>>>
>>> # Contains match
>>> docs = client.documents().original_filename("invoice", exact=False)
user_can_change(value)[source]

Filter documents by user change permission.

This filter is useful for finding documents that the current authenticated user has permission to modify.

Parameters:

value (bool) – True to filter documents the user can change, False for those they cannot.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Find documents the current user can change
>>> docs = client.documents().user_can_change(True)
>>>
>>> # Find documents the current user cannot change
>>> docs = client.documents().user_can_change(False)
custom_field_fullsearch(value, *, case_insensitive=True)[source]

Filter documents by searching through both custom field name and value.

This method searches across all custom fields (both names and values) for the specified text.

Parameters:
  • value (str) – The search string to look for in custom fields.

  • case_insensitive (bool) – If True, perform case-insensitive matching.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Raises:

NotImplementedError – If case_insensitive is False, as Paperless NGX doesn’t support case-sensitive custom field search.

Examples

>>> # Find documents with custom fields containing "reference"
>>> docs = client.documents().custom_field_fullsearch("reference")
custom_field(field, value, *, exact=False, case_insensitive=True)[source]

Filter documents by custom field.

This method filters documents based on a specific custom field’s value.

Parameters:
  • field (str) – The name of the custom field to filter by.

  • value (Any) – The value to filter by.

  • exact (bool) – If True, match the exact value, otherwise use contains.

  • case_insensitive (bool) – If True, perform case-insensitive matching for string values.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Contains match (default)
>>> docs = client.documents().custom_field("Reference Number", "INV")
>>>
>>> # Exact match
>>> docs = client.documents().custom_field("Status", "Paid", exact=True)
>>>
>>> # Case-sensitive contains match
>>> docs = client.documents().custom_field("Notes", "Important",
...                                      case_insensitive=False)
has_custom_field_id(pk, *, exact=False)[source]

Filter documents that have a custom field with the specified ID(s).

This method filters documents based on the presence of specific custom fields, regardless of their values.

Parameters:
  • pk (int | list[int]) – A single custom field ID or list of custom field IDs.

  • exact (bool) – If True, return results that have exactly these IDs and no others. If False, return results that have at least these IDs.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Documents with custom field ID 5
>>> docs = client.documents().has_custom_field_id(5)
>>>
>>> # Documents with custom field IDs 5 and 7
>>> docs = client.documents().has_custom_field_id([5, 7])
>>>
>>> # Documents with exactly custom field IDs 5 and 7 and no others
>>> docs = client.documents().has_custom_field_id([5, 7], exact=True)
custom_field_query(*args, **kwargs)[source]

Filter documents by custom field query.

Parameters:
Return type:

Self

custom_field_range(field, start, end)[source]

Filter documents with a custom field value within a specified range.

This is particularly useful for date or numeric custom fields.

Parameters:
  • field (str) – The name of the custom field.

  • start (str) – The start value of the range.

  • end (str) – The end value of the range.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Date range
>>> docs = client.documents().custom_field_range("Invoice Date", "2023-01-01", "2023-12-31")
>>>
>>> # Numeric range
>>> docs = client.documents().custom_field_range("Amount", "100", "500")
custom_field_exact(field, value)[source]

Filter documents with a custom field value that matches exactly.

This method is a shorthand for custom_field_query with the “exact” operation.

Parameters:
  • field (str) – The name of the custom field.

  • value (Any) – The exact value to match.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Match exact status
>>> docs = client.documents().custom_field_exact("Status", "Paid")
>>>
>>> # Match exact date
>>> docs = client.documents().custom_field_exact("Due Date", "2023-04-15")
custom_field_in(field, values)[source]

Filter documents with a custom field value in a list of values.

This method is a shorthand for custom_field_query with the “in” operation.

Parameters:
  • field (str) – The name of the custom field.

  • values (list[Any]) – The list of values to match against.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Match documents with status in a list
>>> docs = client.documents().custom_field_in("Status", ["Paid", "Pending"])
>>>
>>> # Match documents with specific reference numbers
>>> docs = client.documents().custom_field_in("Reference", ["INV-001", "INV-002", "INV-003"])
custom_field_isnull(field)[source]

Filter documents with a custom field that is null or empty.

This method finds documents where the specified custom field either doesn’t exist or has an empty value.

Parameters:

field (str) – The name of the custom field.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Find documents with missing or empty "Status" field
>>> docs = client.documents().custom_field_isnull("Status")
>>>
>>> # Chain with other filters
>>> recent_missing_field = client.documents().custom_field_isnull("Priority").created_after("2023-01-01")
custom_field_exists(field, exists=True)[source]

Filter documents based on the existence of a custom field.

This method is a shorthand for custom_field_query with the “exists” operation.

Parameters:
  • field (str) – The name of the custom field.

  • exists (bool) – True to filter documents where the field exists, False otherwise.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Find documents that have the "Priority" field
>>> docs = client.documents().custom_field_exists("Priority")
>>>
>>> # Find documents that don't have the "Review Date" field
>>> docs = client.documents().custom_field_exists("Review Date", exists=False)
custom_field_contains(field, values)[source]

Filter documents with a custom field that contains all specified values.

This method is useful for custom fields that can hold multiple values, such as array or list-type fields.

Parameters:
  • field (str) – The name of the custom field.

  • values (list[Any]) – The list of values that the field should contain.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Find documents with tags field containing both "important" and "tax"
>>> docs = client.documents().custom_field_contains("Tags", ["important", "tax"])
>>>
>>> # Find documents with categories containing specific values
>>> docs = client.documents().custom_field_contains("Categories", ["Finance", "Tax"])
has_custom_fields()[source]

Filter documents that have any custom fields.

This method returns documents that have at least one custom field defined, regardless of the field name or value.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Find all documents with any custom fields
>>> docs = client.documents().has_custom_fields()
no_custom_fields()[source]

Filter documents that do not have any custom fields.

This method returns documents that have no custom fields defined.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Find all documents without any custom fields
>>> docs = client.documents().no_custom_fields()
notes(text)[source]

Filter documents whose notes contain the specified text.

This method searches through the document notes for the specified text.

Parameters:

text (str) – The text to search for in document notes.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Find documents with "follow up" in notes
>>> docs = client.documents().notes("follow up")
>>>
>>> # Chain with other filters
>>> important_notes = client.documents().notes("important").tag_name("tax")
created_before(date)[source]

Filter models created before a given date.

This method filters documents based on their creation date in Paperless-ngx.

Parameters:

date (datetime | str) – The date to filter by. Can be a datetime object or an ISO format string.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Using string date
>>> docs = client.documents().created_before("2023-01-01")
>>>
>>> # Using datetime object
>>> from datetime import datetime
>>> date = datetime(2023, 1, 1)
>>> docs = client.documents().created_before(date)
created_after(date)[source]

Filter models created after a given date.

This method filters documents based on their creation date in Paperless-ngx.

Parameters:

date (datetime | str) – The date to filter by. Can be a datetime object or an ISO format string.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Using string date
>>> docs = client.documents().created_after("2023-01-01")
>>>
>>> # Using datetime object
>>> from datetime import datetime
>>> date = datetime(2023, 1, 1)
>>> docs = client.documents().created_after(date)
created_between(start, end)[source]

Filter models created between two dates.

This method filters documents with creation dates falling within the specified range.

Parameters:
  • start (datetime | str) – The start date to filter by. Can be a datetime object or an ISO format string.

  • end (datetime | str) – The end date to filter by. Can be a datetime object or an ISO format string.

Return type:

Self

Returns:

Filtered DocumentQuerySet.

Examples

>>> # Using string dates
>>> docs = client.documents().created_between("2023-01-01", "2023-12-31")
>>>
>>> # Using datetime objects
>>> from datetime import datetime
>>> start = datetime(2023, 1, 1)
>>> end = datetime(2023, 12, 31)
>>> docs = client.documents().created_between(start, end)
delete()[source]

Delete all documents in the current queryset.

This method performs a bulk delete operation on all documents matching the current queryset filters.

Returns:

The API response from the bulk delete operation. None if there are no documents to delete.

Return type:

ClientResponse

Examples

>>> # Delete all documents with "invoice" in title
>>> client.documents().title("invoice", exact=False).delete()
>>>
>>> # Delete old documents
>>> client.documents().created_before("2020-01-01").delete()
reprocess()[source]

Reprocess all documents in the current queryset.

This method triggers Paperless-ngx to re-run OCR and classification on all documents matching the current queryset filters.

Returns:

The API response from the bulk reprocess operation. None if there are no documents to reprocess.

Return type:

ClientResponse

Examples

>>> # Reprocess documents added in the last week
>>> from datetime import datetime, timedelta
>>> week_ago = datetime.now() - timedelta(days=7)
>>> client.documents().added_after(week_ago.strftime("%Y-%m-%d")).reprocess()
>>>
>>> # Reprocess documents with empty content
>>> client.documents().filter(content="").reprocess()
merge(metadata_document_id=None, delete_originals=False)[source]

Merge all documents in the current queryset into a single document.

This method combines multiple documents into a single PDF document.

Parameters:
  • metadata_document_id (int | None) – Apply metadata from this document to the merged document. If None, metadata from the first document will be used.

  • delete_originals (bool) – Whether to delete the original documents after merging.

Returns:

True if submitting the merge succeeded, False if there are no documents to merge.

Return type:

bool

Raises:

Examples

>>> # Merge all documents with tag "merge_me"
>>> client.documents().tag_name("merge_me").merge(delete_originals=True)
>>>
>>> # Merge documents and use metadata from document ID 42
>>> client.documents().correspondent_name("Electric Company").merge(
...     metadata_document_id=42, delete_originals=False
... )
rotate(degrees)[source]

Rotate all documents in the current queryset.

This method rotates the PDF files of all documents matching the current queryset filters.

Parameters:

degrees (int) – Degrees to rotate (must be 90, 180, or 270).

Returns:

The API response from the bulk rotate operation. None if there are no documents to rotate.

Return type:

ClientResponse

Examples

>>> # Rotate all documents with "sideways" in title by 90 degrees
>>> client.documents().title("sideways", exact=False).rotate(90)
>>>
>>> # Rotate upside-down documents by 180 degrees
>>> client.documents().tag_name("upside-down").rotate(180)
update(*, correspondent=None, document_type=None, storage_path=None, owner=None)[source]

Perform bulk updates on all documents in the current queryset.

This method allows for updating multiple document metadata fields in a single API call for all documents matching the current queryset filters.

Parameters:
  • correspondent (Correspondent | int | None) – Set correspondent for all documents. Can be a Correspondent object or ID.

  • document_type (DocumentType | int | None) – Set document type for all documents. Can be a DocumentType object or ID.

  • storage_path (StoragePath | int | None) – Set storage path for all documents. Can be a StoragePath object or ID.

  • owner (int | None) – Owner ID to assign to all documents.

Returns:

The current queryset for method chaining.

Return type:

Self

Examples

>>> # Update correspondent for all invoices
>>> client.documents().title("invoice", exact=False).update(
...     correspondent=5,
...     document_type=3
... )
>>>
>>> # Set owner for documents without an owner
>>> client.documents().filter(owner__isnull=True).update(owner=1)
modify_custom_fields(add_custom_fields=None, remove_custom_fields=None)[source]

Modify custom fields on all documents in the current queryset.

This method allows for adding, updating, and removing custom fields in bulk for all documents matching the current queryset filters.

Parameters:
  • add_custom_fields (dict[int, Any] | None) – Dictionary of custom field ID to value pairs to add or update.

  • remove_custom_fields (list[int] | None) – List of custom field IDs to remove.

Returns:

The current queryset for method chaining.

Return type:

Self

Examples

>>> # Add a custom field to documents with "invoice" in title
>>> client.documents().title("invoice", exact=False).modify_custom_fields(
...     add_custom_fields={5: "Processed"}
... )
>>>
>>> # Add one field and remove another
>>> client.documents().correspondent_id(3).modify_custom_fields(
...     add_custom_fields={7: "2023-04-15"},
...     remove_custom_fields=[9]
... )
modify_tags(add_tags=None, remove_tags=None)[source]

Modify tags on all documents in the current queryset.

This method allows for adding and removing tags in bulk for all documents matching the current queryset filters.

Parameters:
  • add_tags (list[int] | None) – List of tag IDs to add to the documents.

  • remove_tags (list[int] | None) – List of tag IDs to remove from the documents.

Returns:

The current queryset for method chaining.

Return type:

Self

Examples

>>> # Add tag 3 and remove tag 4 from all documents with "invoice" in title
>>> client.documents().title("invoice", exact=False).modify_tags(
...     add_tags=[3], remove_tags=[4]
... )
>>>
>>> # Add multiple tags to recent documents
>>> from datetime import datetime, timedelta
>>> month_ago = datetime.now() - timedelta(days=30)
>>> client.documents().created_after(month_ago.strftime("%Y-%m-%d")).modify_tags(
...     add_tags=[5, 7, 9]
... )
add_tag(tag_id)[source]

Add a tag to all documents in the current queryset.

This is a convenience method that calls modify_tags with a single tag ID to add.

Parameters:

tag_id (int) – Tag ID to add to all documents in the queryset.

Returns:

The current queryset for method chaining.

Return type:

Self

Examples

>>> # Add tag 3 to all documents with "invoice" in title
>>> client.documents().title("invoice", exact=False).add_tag(3)
>>>
>>> # Add tag to documents from a specific correspondent
>>> client.documents().correspondent_name("Electric Company").add_tag(5)
filters: dict[str, Any]
remove_tag(tag_id)[source]

Remove a tag from all documents in the current queryset.

This is a convenience method that calls modify_tags with a single tag ID to remove.

Parameters:

tag_id (int) – Tag ID to remove from all documents in the queryset.

Returns:

The current queryset for method chaining.

Return type:

Self

Examples

>>> # Remove tag 4 from all documents with "invoice" in title
>>> client.documents().title("invoice", exact=False).remove_tag(4)
>>>
>>> # Remove tag from old documents
>>> client.documents().created_before("2020-01-01").remove_tag(7)
set_permissions(permissions=None, owner_id=None, merge=False)[source]

Set permissions for all documents in the current queryset.

This method allows for updating document permissions in bulk for all documents matching the current queryset filters.

Parameters:
  • permissions (dict[str, Any] | None) – Permissions object defining user and group permissions.

  • owner_id (int | None) – Owner ID to assign to the documents.

  • merge (bool) – Whether to merge with existing permissions (True) or replace them (False).

Returns:

The current queryset for method chaining.

Return type:

Self

Examples

>>> # Set owner to user 2 for all documents with "invoice" in title
>>> client.documents().title("invoice", exact=False).set_permissions(owner_id=2)
>>>
>>> # Set complex permissions
>>> permissions = {
...     "view": {"users": [1, 2], "groups": [1]},
...     "change": {"users": [1], "groups": []}
... }
>>> client.documents().tag_name("confidential").set_permissions(
...     permissions=permissions,
...     owner_id=1,
...     merge=True
... )