Python REST API wrapper for docsdk
Project description
docsdk-python
This is the official Python SDK v2 for the DocSDK API v2. For API v1, please use v1 branch of this repository.
Installation
pip install docsdk
Creating API Client
import docsdk
docsdk.configure(api_key = 'API_KEY', sandbox = False)
Or set the environment variable DOCSDK_API_KEY and use:
import docsdk
docSDK.default()
Creating Jobs
import docSDK
docsdk.configure(api_key = 'API_KEY')
docsdk.Job.create(payload={
"tasks": {
'import-my-file': {
'operation': 'import/url',
'url': 'https://my-url'
},
'convert-my-file': {
'operation': 'convert',
'input': 'import-my-file',
'output_format': 'pdf',
'some_other_option': 'value'
},
'export-my-file': {
'operation': 'export/url',
'input': 'convert-my-file'
}
}
})
Downloading Files
DocSDK can generate public URLs for using export/url tasks. You can use these URLs to download output files.
exported_url_task_id = "84e872fc-d823-4363-baab-eade2e05ee54"
res = docsdk.Task.wait(id=exported_url_task_id) # Wait for job completion
file = res.get("result").get("files")[0]
res = docsdk.download(filename=file['filename'], url=file['url'])
print(res)
Uploading Files
Uploads to DocSDK are done via import/upload tasks (see the docs). This SDK offers a convenient upload method:
job = docsdk.Job.create(payload={
'tasks': {
'upload-my-file': {
'operation': 'import/upload'
}
}
})
upload_task_id = job['tasks'][0]['id']
upload_task = docsdk.Task.find(id=upload_task_id)
res = docsdk.Task.upload(file_name='path/to/sample.pdf', task=upload_task)
res = docsdk.Task.find(id=upload_task_id)
Webhook Signing
The node SDK allows to verify webhook requests received from DocSDK.
payloadString = '...'; # The JSON string from the raw request body.
signature = '...'; # The value of the "DocSDK-Signature" header.
signingSecret = '...'; # You can find it in your webhook settings.
isValid = docsdk.Webhook.verify(payloadString, signature, signingSecret); # returns true or false
Unit Tests
# Run Task tests
$ python tests/unit/testTask.py
# Run Job tests
$ python tests/unit/testJob.py
# Run Webhook tests
$ python tests/unit/testWebhookSignature.py
Integration Tests
# Run Integration test for task
$ python tests/integration/testTasks.py
# Run Integration test for Job
$ python tests/integration/testJobs.py
Resources
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 docsdk-2.0.2.tar.gz.
File metadata
- Download URL: docsdk-2.0.2.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66b4f1b075625b82258cee39b811736846411608cefaa18258167bcf7fea16ea
|
|
| MD5 |
07474d6a106ea9d75ad6bac24bb3b44e
|
|
| BLAKE2b-256 |
055f37d34f6f723108d1ec590eb76e7231127b46138bc702641be4dd6bcc49f8
|
File details
Details for the file docsdk-2.0.2-py2.py3-none-any.whl.
File metadata
- Download URL: docsdk-2.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
363e614535fb1c97df40803d911e2c8c1ef593349427b8b02a8bc41dc16c9e03
|
|
| MD5 |
09144f92e90813e9b5bcba1acb30f228
|
|
| BLAKE2b-256 |
dc57fb1b0ae7b4d1931b891bda59d029505e7a8c8906dbb017f5d921ecae1bfc
|