Processing
To upload and start processing a batch, you must use the Deepomatic API.
When it comes to the batch processing, there are two ways to use the Deepomatic API: Python script or Deepomatic CLI.
Python script
Run the python script below with the following arguments:
endpoint: it corresponds to the deployment site and has the following URL:
https://api.{site-id}.customers.deepomatic.com
. For more information on how to retrieve, please refer to the Authentication documentation.filename: it corresponds to the local path of the archive with the format specified here.
python3 upload.py endpoint filename
import sys
import requests
CHUNK_SIZE = 262144 * 2
def upload(endpoint: str, filepath: str):
# Setup base headers with auth token
headers = {
'Authorization': f'Token {os.getenv("CUSTOMER_API_KEY")}',
'content-type': 'application/json'
}
# Use endpoint to get a resumable url
try:
response = requests.post(
f"{endpoint}/v0.2/batches",
headers=headers
)
# check for bad answers
response.raise_for_status()
resumable_url = response.json()["upload_url"]
except Exception as err:
print(err)
sys.exit(1)
print(f"Using resumable_url: {resumable_url}")
# Setup chunk tracking variables
index = 0
offset = 0
content_size = os.stat(filepath).st_size
# No more auth on the resumable_url.
# Setting content-type
headers = {
'content-type': 'application/octet-stream'
}
with open(filepath, "rb") as archive:
while True:
chunk = archive.read(CHUNK_SIZE)
if not chunk:
break
offset = index + len(chunk)
headers['Content-Range'] = 'bytes %s-%s/%s' % (index, offset - 1, content_size)
index = offset
try:
response = requests.put(resumable_url, data=chunk, headers=headers)
print("response: %s, Content-Range: %s" % (response, headers['Content-Range']))
print(response.text)
response.raise_for_status()
except Exception as err:
print(err)
if __name__ == "__main__":
if "--help" in sys.argv or len(sys.argv) != 3:
print(
"Usage:"
" upload.py <endpoint> <filepath>"
)
upload(sys.argv[1], sys.argv[2])
Deepomatic CLI
Use the following command and specify:
either the batch id if you have already created the batch via the GUI or the upload url if this is not the case
the archive path
deepo site work_order batch upload -i batch_id -u upload_url -f archive_path
Was this helpful?