Skip to main content

Python REST API wrapper for cloud convert

Project description

cloudconvert-python

This is the official Python SDK for the CloudConvert API v2.

Tests PyPI PyPI - Downloads

Installation

 pip install cloudconvert

Creating API Client

 import cloudconvert

cloudconvert.configure(api_key='API_KEY', sandbox=False)

Or set the environment variable CLOUDCONVERT_API_KEY and use:

 import cloudconvert

cloudconvert.default()

Creating Jobs

 import cloudconvert

cloudconvert.configure(api_key='API_KEY')

cloudconvert.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

CloudConvert 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 = cloudconvert.Task.wait(id=exported_url_task_id)  # Wait for job completion
file = res.get("result").get("files")[0]
res = cloudconvert.download(filename=file['filename'], url=file['url'])
print(res)

Uploading Files

Uploads to CloudConvert are done via import/upload tasks (see the docs). This SDK offers a convenient upload method:

job = cloudconvert.Job.create(payload={
    'tasks': {
        'upload-my-file': {
            'operation': 'import/upload'
        }
    }
})

upload_task_id = job['tasks'][0]['id']

upload_task = cloudconvert.Task.find(id=upload_task_id)
res = cloudconvert.Task.upload(file_name='path/to/sample.pdf', task=upload_task)

res = cloudconvert.Task.find(id=upload_task_id)

Webhook Signing

The node SDK allows to verify webhook requests received from CloudConvert.

payloadString = '...';  # The JSON string from the raw request body.
signature = '...';  # The value of the "CloudConvert-Signature" header.
signingSecret = '...';  # You can find it in your webhook settings.

isValid = cloudconvert.Webhook.verify(payloadString, signature, signingSecret);  # returns true or false

Signed URLs

Signed URLs allow converting files on demand only using URL query parameters. The Python SDK allows to generate such URLs. Therefore, you need to obtain a signed URL base and a signing secret on the CloudConvert Dashboard.

base = 'https://s.cloudconvert.com/...'  # You can find it in your signed URL settings.
signing_secret = '...'  # You can find it in your signed URL settings.
cache_key = 'cache-key'  # Allows caching of the result file for 24h

job = {
    "tasks": {
        "import-file": {
            "operation": "import/url",
            "url": "https://github.com/cloudconvert/cloudconvert-php/raw/master/tests/Integration/files/input.pdf"
        },
        "export-file": {
            "operation": "export/url",
            "input": "import-file"
        }
    }
}

url = cloudconvert.SignedUrl.sign(base, signing_secret, job, cache_key);  # returns the URL

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


Download files

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

Source Distribution

cloudconvert-2.1.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

cloudconvert-2.1.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file cloudconvert-2.1.0.tar.gz.

File metadata

  • Download URL: cloudconvert-2.1.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.61.1 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for cloudconvert-2.1.0.tar.gz
Algorithm Hash digest
SHA256 2de51626baebb7a6096475795c6e2f188a3733e4aca110ff3c51355e9a0953af
MD5 16e41ce5a5f21304c9d47b9619a13b49
BLAKE2b-256 9fd22e979509ccfe079ecef6c8ee9f9a4b2dedfac766bb6508dcb9d0d898dc8e

See more details on using hashes here.

File details

Details for the file cloudconvert-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: cloudconvert-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.61.1 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for cloudconvert-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70736187f3e05eb233971428d1c423581967ef855e0a9e37a5e2b7eea14c3b3b
MD5 20385c2c32134e720340a45228619940
BLAKE2b-256 921f707afd29b28898ed1bf415cb80fa64d08d55b0b92402ac53a279b79a824d

See more details on using hashes here.

Supported by

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