Welcome to WEBP.to API documentation
To get a developer key please go todeveloper portal
Authorization: <api_key>
Convert from WebP
WebP to DOCX
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-docx',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.docx
To make multiple simply put more files in your list
WebP to DOC
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-doc',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.doc
To make multiple simply put more files in your list
WebP to JPG
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-jpg',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.jpg
To make multiple simply put more files in your list
WebP to JPEG
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-jpeg',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.jpeg
To make multiple simply put more files in your list
WebP to PDF
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-pdf',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.pdf
To make multiple simply put more files in your list
WebP to TIFF
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-tiff',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.tiff
To make multiple simply put more files in your list
WebP to BMP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-bmp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.bmp
To make multiple simply put more files in your list
WebP to MP4
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-mp4'
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.mp4
To make multiple simply put more files in your list
WebP to WebM
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-webm'
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webm
To make multiple simply put more files in your list
WebP to SVG
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-svg',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.svg
To make multiple simply put more files in your list
WebP to ZIP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-zip',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.zip
To make multiple simply put more files in your list
WebP to PNG
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-png',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.png
To make multiple simply put more files in your list
WebP to GIF
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-gif',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.gif
To make multiple simply put more files in your list
WebP to PSD
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'webp-psd',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.psd
To make multiple simply put more files in your list
Convert to WebP
DOCX to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.docx', 'testfiles/blah.docx', 'testfiles/blah.docx']
params = {
'lang': 'en',
'convert_to': 'docx-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
PDF to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.pdf', 'testfiles/blah.pdf', 'testfiles/blah.pdf']
params = {
'lang': 'en',
'convert_to': 'pdf-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.pdf
To make multiple simply put more files in your list
DOC to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'doc-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
JPG to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'jpg-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
JPEG to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webp', 'testfiles/blah.webp', 'testfiles/blah.webp']
params = {
'lang': 'en',
'convert_to': 'jpeg-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
BMP to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.bmp', 'testfiles/blah.bmp', 'testfiles/blah.bmp']
params = {
'lang': 'en',
'convert_to': 'bmp-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
SVG to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.svg', 'testfiles/blah.svg', 'testfiles/blah.svg']
params = {
'lang': 'en',
'convert_to': 'svg-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
TIFF to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.tiff', 'testfiles/blah.tiff', 'testfiles/blah.tiff']
params = {
'lang': 'en',
'convert_to': 'tiff-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
PNG to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.png', 'testfiles/blah.png', 'testfiles/blah.png']
params = {
'lang': 'en',
'convert_to': 'png-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
GIF to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.gif', 'testfiles/blah.gif', 'testfiles/blah.gif']
params = {
'lang': 'en',
'convert_to': 'gif-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
PSD to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.psd', 'testfiles/blah.psd', 'testfiles/blah.psd']
params = {
'lang': 'en',
'convert_to': 'psd-webp',
'ocr': False
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
MP4 to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.mp4', 'testfiles/blah.mp4', 'testfiles/blah.mp4']
params = {
'lang': 'en',
'convert_to': 'mp4-webp'
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list
WebM to WebP
import requests
import time
import shutil
import json
headers = {'Authorization': 'f134382194a844c8bb589af58ef283e9'}
file_list = ['testfiles/blah.webm', 'testfiles/blah.webm', 'testfiles/blah.webm']
params = {
'lang': 'en',
'convert_to': 'webm-webp'
}
api_url = 'https://api.webp.to/v1/convert/'
results_url = 'https://api.webp.to/v1/results/'
def download_file(url, local_filename):
with requests.get("https://api.webp.to/%s" % url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
return local_filename
def convert_files(api_url, params, headers):
files = [eval(f'("files", open("{file}", "rb"))') for file in file_list]
print(files)
r = requests.post(
url=api_url,
files=files,
data=params,
headers=headers
)
return r.json()
def get_results(params):
if params.get('error'):
return params.get('error')
r = requests.post(
url=results_url,
data=params
)
data = r.json()
finished = data.get('finished')
while not finished:
if int(data.get('queue_count')) > 0:
print('queue: %s' % data.get('queue_count'))
time.sleep(5)
results = get_results(params)
print(results)
results = json.dumps(results)
if results:
break
if finished:
print(data.get('files'))
for f in data.get('files'):
print(f.get('url'))
download_file("%s" % f.get('url'), "%s" % f.get('filename'))
return {"finished": "files downloaded"}
return r.json()
get_results(convert_files(api_url, params, headers))
Will return
/path/to/local/file_processed.webp
To make multiple simply put more files in your list