Skip to main content

Python library for interacting with the Paperless NGX REST API

Project description

Paperap

Python library for interacting with the Paperless NGX REST API

Overview

Paperap (pronounced like "paperwrap") is a Python client library for interacting with the Paperless-NGX REST API. It provides an object-oriented interface for managing documents, tags, correspondents, and other resources within Paperless-NGX.

Status

The library is in active development, and is not ready for production use.

Features

  • Authentication via API token or username/password
  • Object-oriented interface with lazy-loaded querysets
  • Pagination and filtering support
  • Strongly typed models with Pydantic
  • Intended to be easily integrated with existing Python applications

Installation

pip install paperap

Quick Start

Documentation: https://paperap.readthedocs.io

Creating a Client

Using API Token:

from paperap import PaperlessClient

client = PaperlessClient(
    base_url="https://paperless.example.com",
    token="your-token"
)

Using Username and Password:

client = PaperlessClient(
    base_url="https://paperless.example.com",
    username="user",
    password="pass"
)

Loading Settings from Environment Variables:

Set the following environment variables:

  • PAPERLESS_BASE_URL
  • PAPERLESS_TOKEN or both PAPERLESS_USERNAME and PAPERLESS_PASSWORD

Then create a client without arguments:

client = PaperlessClient()

Working with Documents

Listing Documents:

for doc in client.documents.all():
    print(doc.title)

Filtering Documents:

docs = client.documents.filter(title__contains="invoice")
for doc in docs:
    print(doc.title)

Getting a Single Document:

doc = client.documents.get(123)
print(doc.title)

Tags, Correspondents, and Other Resources

The same interface applies to other resources like tags, correspondents, and document types:

for tag in client.tags.all():
    print(tag.name)

Error Handling

Paperap raises exceptions for API errors:

  • PaperlessError - Base exception
  • APIError - Error when contacting the Paperless NGX API
  • AuthenticationError - Error when authentication fails
  • ObjectNotFoundError - Error when a single object is requested but not found
  • MultipleObjectsFoundError - Error when a single object is requested but multiple objects are found
from paperap.exceptions import ObjectNotFoundError

try:
    doc = client.documents.get(9999)  # Nonexistent document
except ObjectNotFoundError as e:
    print(f"Error: {e}")

Contributing

I welcome contributions! Please open an issue or submit a pull request on GitHub.

Run tests with either of the following cli commands:

bun run test
uv run python -m unittest discover -s tests

Setup dev environment:

uv venv
source .venv/bin/activate
uv sync --all-groups

Setup env vars:

cp env-sample .env

Run pre-commit:

pre-commit run --all-files

TODO

  • increase test coverage (currently around 85%)
  • Make integration tests easier to setup for other users (wip)
  • Deleting tags, custom fields, etc via document.tags = None
  • devcontainer (wip)
  • cli tools (1 done)
  • updating permissions, ownership, sharing, etc
  • changing settings
  • local queryset filtering on fields not supported by api
  • unit tests for additional edge cases
  • immutability (resources, response dicts, (optionally) for models)
  • hypothesis testing (additional models)
  • factories create relationships in db
  • Lazy Document Evaluation after upload/download async
  • Remove validators that pydantic handles natively
  • factories create unique names
  • git action to distribute to pypi
  • batch editing
  • Empty trash
  • publish sphinx docs
  • Compile sphinx documentation
  • async model updates
  • uploading documents
  • raise errors for intuitive features unsupported by api (partially done)
  • enforce read-only fields
  • migrate to pytest
  • Replace yarl with pydantic urls
  • fetch each model synchronously and validate data types
  • lazy loading querysets
  • relationships between models using querysets
  • saving data to paperless
  • vscode tasks

Known Bugs

  • Looping over a queryset and deleting items will not modify the next page of the queryset
  • Running unit tests and integration tests together causes errors, meaning something is not being cleaned up properly

License

Paperap is released under the MIT License.

Author

Jess Mann - jess@jmann.me

Related Projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paperap-0.0.12.tar.gz (16.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paperap-0.0.12-py3-none-any.whl (217.1 kB view details)

Uploaded Python 3

File details

Details for the file paperap-0.0.12.tar.gz.

File metadata

  • Download URL: paperap-0.0.12.tar.gz
  • Upload date:
  • Size: 16.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.18

File hashes

Hashes for paperap-0.0.12.tar.gz
Algorithm Hash digest
SHA256 d3949a3d100e25fa962e7010bc8028e1b64e83521f6934a98b509d9c2b7f9bcd
MD5 a23923e515ff1ba84f09cb2102ec5c37
BLAKE2b-256 2851de8f8e2846fd3ca8c3f438222f5dcc3d70cb198c8bae1a052cb8e4eee113

See more details on using hashes here.

File details

Details for the file paperap-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: paperap-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 217.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.18

File hashes

Hashes for paperap-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 101fe76f645a6a08349d816236e15c14c4de005b8558853dc15ec0ffefc1afb0
MD5 2e973a4ab63f768b76bb475dc932468c
BLAKE2b-256 e755cca352947df6e957765bae4155303f7eda073d36e6cb4e4262f5813529d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page