Skip to main content

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

Project description

Modzy Python SDK

Modzy Logo

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

GitHub contributors GitHub last commit GitHub Release Date

The job lifecycle | API Keys | Samples | Documentation

Installation

installation

Use the package manager pip to install the SDK:

  • $ pip install modzy-sdk

Usage

Get your API key

API keys are security credentials required to perform API requests to Modzy. Our API keys are composed of an ID that is split by a dot into two parts: a public and private part.

The public part is the API keys' visible part only used to identify the key and by itself, it’s unable to perform API requests.

The private part is the public part's complement and it’s required to perform API requests. Since it’s not stored on Modzy’s servers, it cannot be recovered. Make sure to save it securely. If lost, you can replace the API key.

Find your API key in your user profile. To get your full API key click on "Get key":

get key

Initialize

Once you have a model and version identified, get authenticated with your API key.

from modzy import ApiClient, error
client = ApiClient(base_url='https://modzy.example.com/api', api_key='API Key')

Basic usage

The code below is applicable for text/plain input type.

Basic Usage

Submit a job providing the model, version, and input file:

job = client.jobs.submit_file('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.

Error Description
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)

Features

Currently we support the following API routes:

Feature Code Api route
Get all models client.models.get_all() api/models
List models client.models.get_models() api/models
Get model details client.models.get() api/models/:model-id
List models by name client.models.get_by_name() api/models
List models by tag client.tags.get_tags_and_models() api/models/tags/:tag-id
Get related models client.models.get_related() api/models/:model-id/related-models
List a model's versions client.models.get_versions() api/models/:model-id/versions
Get a version's details client.models.get_version() api/models/:model-id/versions/:version-id
Update processing engines client.models.update_processing_engines() api/resource/models
Get minimum engines client.models.get_minimum_engines() api/models/processing-engines
List tags client.tags.get_all() api/models/tags
Submit a Job (Text) client.jobs.submit_text() api/jobs
Submit a Job (Embedded) client.jobs.submit_embedded() api/jobs
Submit a Job (File) client.jobs.submit_file() api/jobs
Submit a Job (AWS S3) client.jobs.submit_aws_s3() api/jobs
Submit a Job (JDBC) client.jobs.submit_jdbc() api/jobs
Cancel job job.cancel() api/jobs/:job-id
Hold until inference is complete job.block_until_complete() api/jobs/:job-id
Get job details client.jobs.get() api/jobs/:job-id
Get results job.get_result() api/results/:job-id
Get the job history client.jobs.get_history() api/jobs/history

Samples

Check out our samples for details on specific use cases.

To run samples:

Set the base url and api key in each sample file:

# TODO: set the base url of modzy api and you api key
client = ApiClient(base_url=BASE_URL, api_key=API_KEY)

Or follow the instructions here to learn more.

And then, you can:

`$ py samples/job_with_text_input_sample.py`

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modzy-sdk-0.6.0.tar.gz (30.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page