Thanks to visit codestin.com
Credit goes to github.com

Skip to content

rfcasallasm/sdk-python

 
 

Repository files navigation

Modzy Python SDK



Modzy



Modzy's Python SDK queries models, submits inference jobs and returns results directly to your editor.


GitHub contributors GitHub last commit GitHub Release Date



Installation

Clone the repository:

Use the package manager pip to install the SDK.

  • $ pip install ./sdk-python

Usage

Initialize

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')

Basic usage

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)

Fetch errors

Errors may arise for different reasons. Fetch errors to know what is their cause and how to fix them.

NetworkError

The SDK is unable to connect.

ResponseError

The API returned an error code.

Timeout

The model is not finished running before the timeout elapsed.

ResultsError

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)

Samples

Check out our samples for details on specific use cases.

Contributing

We are happy to receive contributions from all of our users. Check out our contributing file to learn more.

Code of conduct

Contributor Covenant

Credits

This package was bootstrapped with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

About

The official Python SDK for the Modzy Platform.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.4%
  • Makefile 2.6%