Little api wrapper for the paperless(-ngx) dms.
Project description
PyPaperless
Little api client for Paperless-ngx! Find out more here:
- Project: https://docs.paperless-ngx.com
- REST API: https://docs.paperless-ngx.com/api/
Features
- Depends on aiohttp.
- Token authentication, note that credentials aren't supported anymore.
- list requests all object ids of resources.
- get methods for each resources. Accepts page parameters and Django filters and is thus very powerful.
- iterate for each paginated endpoint, you may want to apply some Django filters here, as well.
- create, update, delete methods for documents and their master data endpoints.
- Paperless makes use of pagination. We use that too. You have the full control over how much data to fetch.
- pypaperless is meant to be only the transportation layer. Store and reduce/aggregate data on your own.
Examples
Handling a session.
import asyncio
from pypaperless import Paperless
paperless = Paperless("localhost:8000", "your-secret-token")
async def main():
paperless.initialize()
# do something
paperless.close()
# or just use it in a context
async with paperless:
# do something
asyncio.run(main())
Actually request something
# requests one page
documents = await paperless.documents.get(page=1)
for item in documents.items:
print(f"document #{item.id} has the following content: {item.content}")
Request all items of specific document types and iterate over them
doc_types = [
"3", # salary
"8", # contract
"11", # bank account
]
# iterates over all pages
async for item in paperless.documents.iterate(document_type__id__in=",".join(doc_types)):
print(f"document #{item.id} has the following content: {item.content}")
Request a specific item
correspondent = await paperless.correspondents.one(23)
Create a new correspondent
from pypaperless.models import CorrespondentPost
from pypaperless.models.shared import MatchingAlgorithm
new_correspondent = CorrespondentPost(
name="Salty Correspondent",
match="Give me all your money",
matching_algorithm=MatchingAlgorithm.ALL,
)
# watch out, the result is a Correspondent object...
created_correspondent = paperless.correspondents.create(new_correspondent)
print(created_correspondent.id)
# >> 1337
And delete that salty guy again, including all of his god damn documents!
[!CAUTION] That code actually requests Paperless to physically delete that data! There is no point of return!
# ... async for item in paperless.documents.iterate(correspondent__id=1337): await paperless.documents.delete(item) await paperless.correspondents.delete(created_correspondent)
Thanks to
- The Paperless-ngx Team
- The Home Assistant Community
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
pypaperless-2.0.1.tar.gz
(16.3 kB
view hashes)
Built Distribution
Close
Hashes for pypaperless-2.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e35f3e49eec3e6842231c0d7810f7ed3d672e43edd20515c1e512f31ea1f6cb |
|
MD5 | 79d5281be7147c21b6ff401677985b1f |
|
BLAKE2b-256 | 3b4b03fd2dc1d104fe6ae06dd27658685502a015b349918b96d49c6f33a1daf3 |