paperap.resources.base module
METADATA:
- File: base.py
Project: paperap
- Created: 2025-03-21
Version: 0.0.10
Author: Jess Mann Email: jess@jmann.me
Copyright (c) 2025 Jess Mann
LAST MODIFIED:
2025-03-21 By Jess Mann
- class paperap.resources.base.BaseResource(client)[source]
Bases:
ABC,Generic[_BaseModel,_BaseQuerySet]Base class for API resources.
- Parameters:
client (
PaperlessClient) – The PaperlessClient instance.endpoint – The API endpoint for this resource.
model_class – The model class for this resource.
-
endpoints:
ClassVar[dict[Union[Literal['list','detail','create','update','delete'],str],Template]]
- __init__(client)[source]
- Parameters:
client (
PaperlessClient)
-
client:
PaperlessClient
- all()[source]
Return a QuerySet representing all objects of this resource type.
- Return type:
TypeVar(_BaseQuerySet, bound= BaseQuerySet[Any])- Returns:
A QuerySet for this resource
- get(*args, **kwargs)[source]
Get a model by ID.
Raises NotImplementedError. Subclasses may implement this.
- Raises:
NotImplementedError – Unless implemented by a subclass.
- Return type:
TypeVar(_BaseModel, bound= BaseModel)- Returns:
The model retrieved.
- Parameters:
- parse_to_model(item)[source]
Parse an item dictionary into a model instance, handling date parsing.
- transform_data_output(model=None, exclude_unset=True, **data)[source]
Transform data before sending it to the API.
- request_raw(url=None, method='GET', params=None, data=None)[source]
Make an HTTP request to the API, and return the raw json response.
- Parameters:
- Return type:
- Returns:
The JSON-decoded response from the API
- handle_dict_response(**response)[source]
Handle a response from the API and yield results.
Override in subclasses to implement custom response logic.
- handle_results(results)[source]
Yield parsed models from a list of results.
Override in subclasses to implement custom result handling.
- class paperap.resources.base.StandardResource(client)[source]
Bases:
BaseResource[_StandardModel,_StandardQuerySet]Base class for API resources.
- Parameters:
client (
PaperlessClient) – The PaperlessClient instance.endpoint – The API endpoint for this resource.
model_class – The model class for this resource.
- class paperap.resources.base.BulkEditing[source]
Bases:
object- bulk_edit_objects(object_type, ids, operation, permissions=None, owner_id=None, merge=False)[source]
Bulk edit non-document objects (tags, correspondents, document types, storage paths).
- Parameters:
object_type (
str) – Type of objects to edit (‘tags’, ‘correspondents’, ‘document_types’, ‘storage_paths’)operation (
str) – Operation to perform (‘set_permissions’ or ‘delete’)permissions (
dict[str,Any] |None) – Permissions object for ‘set_permissions’ operationmerge (
bool) – Whether to merge permissions with existing ones (True) or replace them (False)self (
BaseResource)
- Return type:
- Returns:
The API response
- Raises:
ValueError – If operation is not valid
ConfigurationError – If the bulk edit endpoint is not defined