Skip to content

Commit 866c87a

Browse files
committed
v2 initial commit
1 parent e4b8787 commit 866c87a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1870
-787
lines changed

.gitignore

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
# execution artefacts
2-
*.pyc
3-
.coverage
4-
.DS_Store
5-
6-
# dist artefacts
7-
build/
1+
.idea
82
dist/
3+
build/
94
cloudconvert.egg-info/
10-
*.egg
11-
12-
# dev artefacts
13-
.idea
14-
test.py
5+
*.egg

.travis.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
language: python
22
python:
3-
- "2.7"
4-
- "3.2"
5-
- "3.3"
6-
- "3.4"
7-
- "3.5"
3+
- '3.7'
4+
- '3.6'
5+
- '3.5'
6+
- '2.7'
7+
88
install:
9-
- pip install .
10-
- pip install -r requirements-dev.txt
11-
script: nosetests
12-
sudo: false
9+
- pip install -r requirements.txt
10+
11+
script: python tests/unit/testTask.py || python tests/unit/testJob.py || python tests/unit/testWebhookSignature.py

LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The License (MIT)
2+
3+
Copyright (c) 2020 Josias Montag <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
## cloudconvert-python
2+
3+
This is the official Python SDK v2 for the [CloudConvert](https://cloudconvert.com/api/v2) _API v2_.
4+
For API v1, please use [v1 branch](https://github.com/cloudconvert/cloudconvert-python/tree/v1) of this repository.
5+
6+
7+
[![Build Status](https://travis-ci.com/cloudconvert/cloudconvert-python.svg?branch=master)](https://travis-ci.com/cloudconvert/cloudconvert-python)
8+
## Installation
9+
10+
```
11+
pip install cloudconvert
12+
```
13+
14+
## Creating API Client
15+
16+
```
17+
import cloudconvert
18+
19+
cloudconvert.configure(api_key = 'API_KEY', sandbox = False)
20+
```
21+
22+
Or set the environment variable `CLOUDCONVERT_API_KEY` and use:
23+
24+
```
25+
import cloudconvert
26+
27+
cloudconvert.default()
28+
```
29+
30+
## Creating Jobs
31+
32+
```js
33+
import cloudconvert
34+
35+
cloudconvert.configure(api_key = 'API_KEY')
36+
37+
cloudconvert.Job.create(payload={
38+
"tasks": {
39+
'import-my-file': {
40+
'operation': 'import/url',
41+
'url': 'https://my-url'
42+
},
43+
'convert-my-file': {
44+
'operation': 'convert',
45+
'input': 'import-my-file',
46+
'output_format': 'pdf',
47+
'some_other_option': 'value'
48+
},
49+
'export-my-file': {
50+
'operation': 'export/url',
51+
'input': 'convert-my-file'
52+
}
53+
}
54+
})
55+
56+
```
57+
58+
## Downloading Files
59+
60+
CloudConvert can generate public URLs for using `export/url` tasks. You can use these URLs to download output files.
61+
62+
```js
63+
exported_url_task_id = "84e872fc-d823-4363-baab-eade2e05ee54"
64+
res = cloudconvert.Task.wait(id=exported_url_task_id) # Wait for job completion
65+
file = res.get("result").get("files")[0]
66+
res = cloudconvert.download(filename=file['filename'], url=file['url'])
67+
print(res)
68+
```
69+
70+
## Uploading Files
71+
72+
Uploads to CloudConvert are done via `import/upload` tasks (see the [docs](https://cloudconvert.com/api/v2/import#import-upload-tasks)). This SDK offers a convenient upload method:
73+
74+
```js
75+
job = cloudconvert.Job.create(payload={
76+
'tasks': {
77+
'upload-my-file': {
78+
'operation': 'import/upload'
79+
}
80+
}
81+
})
82+
83+
upload_task_id = job['tasks'][0]['id']
84+
85+
upload_task = cloudconvert.Task.find(id=upload_task_id)
86+
res = cloudconvert.Task.upload(file_name='path/to/sample.pdf', task=upload_task)
87+
88+
res = cloudconvert.Task.find(id=upload_task_id)
89+
```
90+
## Webhook Signing
91+
92+
The node SDK allows to verify webhook requests received from CloudConvert.
93+
94+
```js
95+
payloadString = '...'; # The JSON string from the raw request body.
96+
signature = '...'; # The value of the "CloudConvert-Signature" header.
97+
signingSecret = '...'; # You can find it in your webhook settings.
98+
99+
isValid = cloudconvert.Webhook.verify(payloadString, signature, signingSecret); # returns true or false
100+
```
101+
102+
## Unit Tests
103+
104+
```
105+
# Run Task tests
106+
$ python tests/unit/testTask.py
107+
108+
# Run Job tests
109+
$ python tests/unit/testJob.py
110+
111+
# Run Webhook tests
112+
$ python tests/unit/testWebhookSignature.py
113+
114+
```
115+
116+
117+
## Integration Tests
118+
```
119+
# Run Integration test for task
120+
$ python tests/integration/testTasks.py
121+
122+
# Run Integration test for Job
123+
$ python tests/integration/testJobs.py
124+
125+
```
126+
127+
128+
## Resources
129+
130+
* [API v2 Documentation](https://cloudconvert.com/api/v2)
131+
* [CloudConvert Blog](https://cloudconvert.com/blog)

README.rst

Lines changed: 0 additions & 96 deletions
This file was deleted.

cloudconvert/__init__.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
from .api import Api
2-
from .api import Process
3-
from .exceptions import (
4-
APIError, HTTPError, BadRequest, ConversionFailed, TemporaryUnavailable, InvalidResponse, InvalidParameterException
5-
)
1+
from cloudconvert.cloudconvertrestclient import *
2+
from cloudconvert.task import Task
3+
from cloudconvert.job import Job
4+
from cloudconvert.webhook import Webhook
5+
6+
def configure(**config):
7+
"""
8+
Configure the REST Client With Latest API Key and Mode
9+
:return:
10+
"""
11+
set_config(**config)
12+
13+
14+
def default():
15+
"""
16+
Configure the REST Client With Default API Key and Mode
17+
:return:
18+
"""
19+
default_client()
20+

0 commit comments

Comments
 (0)