paperap.models.share_links.model module

Module for managing share links in Paperless-NgX.

This module provides the ShareLinks model for creating, retrieving, and managing document share links in Paperless-NgX. Share links allow documents to be shared with users who don’t have access to the Paperless-NgX instance.

Bases: StandardModel

Model representing a share link in Paperless-NgX.

Share links allow documents to be shared with users who don’t have access to the Paperless-NgX instance. Each share link has a unique slug that can be used to access the document without authentication.

expiration

When the share link expires. If None, the link never expires.

Type:

datetime | None

slug

Unique identifier for the share link URL.

Type:

str | None

document

ID of the document being shared.

Type:

int | None

created

When the share link was created.

Type:

datetime | None

file_version

Which version of the document to share.

Type:

ShareLinkFileVersionType | None

owner

ID of the user who created the share link.

Type:

int | None

Examples

>>> # Create a new share link for document with ID 123
>>> share_link = client.share_links.create(document=123)
>>> print(f"Share link created: {share_link.slug}")
>>>
>>> # Create a share link that expires in 7 days
>>> from datetime import datetime, timedelta
>>> expiry = datetime.now() + timedelta(days=7)
>>> share_link = client.share_links.create(
...     document=123,
...     expiration=expiry
... )
Parameters:

data (Any)

expiration: datetime | None
slug: str | None
document: int | None
created: datetime | None
file_version: ShareLinkFileVersionType | None
owner: int | None
class Meta(model)[source]

Bases: Meta

Metadata for the ShareLinks model.

This class defines the queryset class to use for ShareLinks queries.

Parameters:

model (type[_Self])

queryset

alias of ShareLinksQuerySet

blacklist_filtering_params: ClassVar[set[str]] = {}
field_map: dict[str, str] = {}
filtering_disabled: ClassVar[set[str]] = {}
filtering_fields: ClassVar[set[str]] = {'_resource', 'created', 'document', 'expiration', 'file_version', 'id', 'owner', 'slug'}
read_only_fields: ClassVar[set[str]] = {'id'}
supported_filtering_params: ClassVar[set[str]] = {'id', 'id__in', 'limit'}
model: type[_Self]
name: str
serialize_datetime(value)[source]

Serialize a datetime object to an ISO 8601 formatted string.

This serializer converts datetime objects to ISO 8601 formatted strings for JSON serialization when sending data to the Paperless-NgX API.

Parameters:

value (datetime | None) – The datetime object to serialize.

Returns:

The ISO 8601 formatted string representation of the datetime,

or None if the input is None.

Return type:

str | None

Examples

>>> share_link = ShareLinks()
>>> from datetime import datetime
>>> dt = datetime(2023, 1, 15, 12, 30, 45)
>>> share_link.serialize_datetime(dt)
'2023-01-15T12:30:45'
>>> share_link.serialize_datetime(None)
None
get_document()[source]

Get the document associated with this share link.

Retrieves the full Document object associated with this share link by querying the Paperless-NgX API using the document ID stored in this share link.

Returns:

The document object associated with this share link.

Return type:

Document

Raises:

Examples

>>> share_link = client.share_links.get(5)
>>> document = share_link.get_document()
>>> print(f"Shared document title: {document.title}")
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