Modzy's Python SDK queries models, submits inference jobs and returns results directly to your editor.
Clone the repository:
-
$ git clone https://github.com/modzy/sdk-python.git
Use the package manager pip to install the SDK.
-
$ pip install ./sdk-python
Once you have a model
and version
identified, authenticate to Modzy with your API key:
from modzy import ApiClient, error
client = ApiClient(base_url='https://modzy.example.com/api', api_key='my_key.modzy')
Submit a job providing the model, version, and input file:
job = client.jobs.submit_files('ed542963de', '0.0.27', {'input.txt': './some-file.txt'})
Hold until the inference is complete and results become available:
result = client.results.block_until_complete(job, timeout=None)
Get the output results:
results_json = result.get_first_outputs()['results.json']
print(results_json)
Errors may arise for different reasons. Fetch errors to know what is their cause and how to fix them.
|
The SDK is unable to connect. |
|
The API returned an error code. |
|
The model is not finished running before the timeout elapsed. |
|
The model returns an error during the inference job. |
Submitting jobs:
NetworkError
, ResponseError
try:
job = client.jobs.submit_files('ed542963de', '0.0.27', {'input.txt': './some-file.txt'})
except error.NetworkError as ex:
print('Could not connect to the API:', ex)
raise
except error.ResponseError as ex:
print('We got an error response from the API:', ex)
raise
While the model completes inference:
NetworkError
, ResponseError
, Timeout
timeout = 600
try:
result = client.results.block_until_complete(job, timeout=timeout)
except error.Timeout as ex:
print('Job still not finished after %d seconds' % timeout)
raise
except error.NetworkError as ex:
print('Could not connect to the API:', ex)
raise
except error.ResponseError as ex:
print('We got an error response from the API:', ex)
raise
Retrieving results:
ResultsError
try:
outputs = result.get_first_outputs()
except error.ResultsError as ex:
print('the model returned an error:', ex)
raise
results_json = outputs['results.json']
print(results_json)
Check out our samples for details on specific use cases.
We are happy to receive contributions from all of our users. Check out our contributing file to learn more.