GithubHelp home page GithubHelp logo

claudep / cloudconvert-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloudconvert/cloudconvert-python

0.0 2.0 0.0 271 KB

Python SDK for the CloudConvert API

License: Other

Python 100.00%

cloudconvert-python's Introduction

cloudconvert-python

This is the official Python SDK v2 for the CloudConvert API v2. For API v1, please use v1 branch of this repository.

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

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

cloudconvert-python's People

Contributors

josiasmontag avatar kreusada avatar renatgalimov avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.