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_URLPAPERLESS_TOKENor bothPAPERLESS_USERNAMEandPAPERLESS_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 exceptionAPIError- Error when contacting the Paperless NGX APIAuthenticationError- Error when authentication failsObjectNotFoundError- Error when a single object is requested but not foundMultipleObjectsFoundError- 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
- Paperless-NGX
- pypaperless - async client that is more mature
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3949a3d100e25fa962e7010bc8028e1b64e83521f6934a98b509d9c2b7f9bcd
|
|
| MD5 |
a23923e515ff1ba84f09cb2102ec5c37
|
|
| BLAKE2b-256 |
2851de8f8e2846fd3ca8c3f438222f5dcc3d70cb198c8bae1a052cb8e4eee113
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
101fe76f645a6a08349d816236e15c14c4de005b8558853dc15ec0ffefc1afb0
|
|
| MD5 |
2e973a4ab63f768b76bb475dc932468c
|
|
| BLAKE2b-256 |
e755cca352947df6e957765bae4155303f7eda073d36e6cb4e4262f5813529d1
|