Skylab Studio python client
Project description
Skylab Studio Python Client
SkylabTech Studio Python client.
Requirements
Installation
$ pip install skylab_studio
Usage
For all examples, assume:
import skylab_studio
api = skylab_studio.api(api_key='YOUR-API-KEY')
Error Handling
By default, the API calls return a response object no matter the type of response.
Endpoints
List all jobs
api.list_jobs()
Create job
payload = {
'profile_id': 1
}
api.create_job(payload=payload)
For all payload options, consult the API documentation.
Get job
api.get_job(job_id)
Update job
payload = {
'profile_id': 2
}
api.create_job(job_id, payload=payload)
For all payload options, consult the API documentation.
Delete job
api.delete_job(job_id)
Cancel job
api.cancel_job(job_id)
List all profiles
api.list_profiles()
Create profile
payload = {
'name': 'My profile'
}
api.create_profile(payload=payload)
For all payload options, consult the API documentation.
Get profile
api.get_profile(profile_id)
Update profile
payload = {
'name': 'My profile'
}
api.create_profile(profile_id, payload=payload)
For all payload options, consult the API documentation.
List all photos
api.list_photos()
Create photo
payload = {
'image': 'some-base64-string'
}
api.create_photo(payload=payload)
For all payload options, consult the API documentation.
Get photo
api.get_photo(photo_id)
Upload photo
upload_photo(photo_path, model, model_id, skip_cache=True)
model can either be 'job' or 'profile'
model_id is the jobs/profiles respective id
api.upload_photo('/path/to/photo', 'job', job_id)
Update photo
payload = {
'image': 'some-base64-string'
}
api.create_photo(photo_id, payload=payload)
For all payload options, consult the API documentation.
Delete photo
api.delete_photo(photo_id)
Validate hmac headers
Applicable if you utilize the job callback url. Use to validate the job payload integrity.
-
secret_key (string): Obtain from Skylab
-
job_json (string): Stringified json object obtained from callback PATCH request
-
request_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'
Returns True or False based on whether or not the signatures match.
api.validate_hmac_headers(secret_key, job_json, request_timestamp, signature)
Expected Responses
Success
>>> response.status_code
200
>>> response.json().get('success')
True
>>> response.json().get('status')
u'OK'
>>> response.json().get('profile_id')
u'numeric-profile-id'
Error
- Malformed request
>>> response.status_code
422
- Bad API key
>>> response.status_code
403
Testing
To run the test suite:
pytest
To run the test suite with code coverage metrics:
pytest --cov-report --cov=skylab_studio
Troubleshooting
General Troubleshooting
- Enable debug mode
- Make sure you're using the latest Python client
- Capture the response data and check your logs — often this will have the exact error
Enable Debug Mode
Debug 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 put debug=True
as a parameter when instantiating
the API object. Use the debug mode to compare the data payload getting
sent to Studio' API docs.
import skylab_studio
api = skylab_studio.api(api_key='YOUR-API-KEY', debug=True)
Response Ranges
Studio' API typically sends responses back in these ranges:
- 2xx – Successful Request
- 4xx – 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 Studio
- Ensure your API key is correct
- Log and check the body of the response
Distribution
To package:
python setup.py sdist bdist_wheel
python -m twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for skylab_studio-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa7ead0b84567b029ef33b4b9cf69a13d39ebe42a20618ce2b94f2ea82bab412 |
|
MD5 | 34daf4b67bcb4fcb32567e9355421bb2 |
|
BLAKE2b-256 | 1da62d001e3d23b244e43b231fc5e493969e8a72790ceb3a04d19205999c1a67 |