Package: skylab-studio
Skylab Studio Python ClientSkylabTech Studio Python client.studio.skylabtech.aiRequirementsPython requests libraryInstallation$pipinstallskylab_studioExample usage# CREATE PROFILEpayload={"name":"profile name",}api.create_profile(payload=payload)# CREATE JOBpayload={"name":"job name","profile_id":profile_id}job=api.create_job(payload)# UPLOAD JOB PHOTO(S)filePath="/path/to/photo"api.upload_job_photo(filePath,job.id)# QUEUE JOBpayload={"callback_url"="YOUR_CALLBACK_ENDPOINT"}api.queue_job(job.id,payload)# NOTE: Once the job is queued, it will get processed then complete# We will send a response to the specified callback_url with the output photo download urlsUsageFor all examples, assume:importskylab_studioapi=skylab_studio.api(api_key='YOUR-API-KEY')Error HandlingBy default, the API calls return a response object no matter the type of response.EndpointsList all jobsapi.list_jobs()Create jobpayload={'profile_id':1}api.create_job(payload=payload)For all payload options, consult theAPI documentation.Get jobapi.get_job(job_id)Update jobpayload={'profile_id':2}api.update_job(job_id,payload=payload)For all payload options, consult theAPI documentation.Queue jobpayload={"callback_url":"desired_callback_url"}api.queue_job(job_id,payload)Delete jobapi.delete_job(job_id)Cancel jobapi.cancel_job(job_id)Jobs in frontUse after queueing job to check number of jobs ahead of yoursapi.fetch_jobs_in_front(job_id)List all profilesapi.list_profiles()Create profilepayload={'name':'My profile'}api.create_profile(payload=payload)For all payload options, consult theAPI documentation.Get profileapi.get_profile(profile_id)Update profilepayload={'name':'My profile'}api.update_profile(profile_id,payload=payload)For all payload options, consult theAPI documentation.List all photosapi.list_photos()Get photoapi.get_photo(photo_id)Upload job photoThis function handles validating a photo, creating a photo object and uploading it to your job/profile's s3 bucket. If the bucket upload process fails, it retries 3 times and if failures persist, the photo object is deleted.api.upload_job_photo(photo_path,job_id)Upload profile photoThis function handles validating a background photo for a profile. Note: enable_extract and replace_background (profile attributes) MUST be true in order to create background photos. Follows the same upload process as upload_job_photo.api.upload_profile_photo(photo_path,profile_id)Returns: { photo: { photo_object }, upload_response: bucket_upload_response_status }If upload fails, the photo object is deleted for you. If upload succeeds and you later decide you no longer want to include that image, use delete_photo to remove it.Delete photoThis will remove the photo from the job/profile's bucket. Useful for when you've accidentally uploaded an image that you'd like removed.api.delete_photo(photo_id)Validate hmac headersApplicable if you utilize the job callback url. Use to validate the job payload integrity.secret_key (string): Obtain from Skylabjob_json (string): Stringified json object obtained from callback PATCH requestrequest_timestamp (string): Obtained from callback PATCH request header 'X-Skylab-Timestamp'signature (string): Signature generated by Skylab to compare. Obtained from callback PATCH request header 'X-Skylab-Signature'ReturnsTrueorFalsebased on whether or not the signatures match.api.validate_hmac_headers(secret_key,job_json,request_timestamp,signature)Expected ResponsesSuccess>>>response.status_code200>>>response.json().get('success')True>>>response.json().get('status')u'OK'>>>response.json().get('profile_id')u'numeric-profile-id'ErrorMalformed request>>>response.status_code422Bad API key>>>response.status_code403TroubleshootingGeneral TroubleshootingEnable debug modeMake sure you're using the latest Python clientCapture the response data and check your logs — often this will have the exact errorEnable Debug ModeDebug mode prints out the underlying request information as well as the data
payload that gets sent to Studio. You will most likely find this information
in your logs. To enable it, simply putdebug=Trueas a parameter when instantiating
the API object. Use the debug mode to compare the data payload getting
sent toStudio' API docs.importskylab_studioapi=skylab_studio.api(api_key='YOUR-API-KEY',debug=True)Response RangesStudio' API typically sends responses back in these ranges:2xx – Successful Request4xx – Failed Request (Client error)5xx – Failed Request (Server error)If you're receiving an error in the 400 response range follow these steps:Double check the data and ID's getting passed to StudioEnsure your API key is correctLog and check the body of the responseDistributionTo package:python-mbuildpython-mtwineuploaddist/*