Metadata-Version: 2.1
Name: modzy-sdk
Version: 0.5.0
Summary: Modzy's Python SDK queries models, submits inference jobs and returns results directly to your editor.
Home-page: https://github.com/modzy/sdk-python
Author: Modzy
Author-email: support@modzy.com
License: UNKNOWN
Description: :!toc:
        :doctype: article
        :icons: font
        :source-highlighter: highlightjs
        :docname: Modzy Python SDK
        
        
        
        
        
        ++++
        <h1>Modzy Python SDK</h1>
        
        
        <div align="center">
        
        <br>
        <br>
        
        
        <img  src="https://www.modzy.com/wp-content/uploads/2019/10/modzy-logo-tm.svg" alt="Modzy" width="350" height="auto">
        
        <br>
        <br>
        <br>
        <br>
        
        
        
        
        
        <p><b>Modzy's Python SDK queries models, submits inference jobs and returns results directly to your editor.</b></p>
        
        
        <br>
        
        
        <img alt="GitHub contributors" src="https://img.shields.io/github/contributors/modzy/sdk-python">
        
        <img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/modzy/sdk-python">
        
        <img alt="GitHub Release Date" src="https://img.shields.io/github/issues-raw/modzy/sdk-python">
        
        </div>
        
        <br>
        <br>
        
        <div align="center">
        <a href=https://models.modzy.com/docs/how-to-guides/job-lifecycle style="text-decoration:none">The job lifecycle</a> |
        <a href=https://models.modzy.com/docs/how-to-guides/api-keys style="text-decoration:none">API keys</a> |
        <a href=/samples style="text-decoration:none">Samples</a> |
        <a href=https://models.modzy.com/docs style="text-decoration:none">Documentation</a>
        
        
        
        <br>
        <br>
        <br>
        <br>
        
        
        
        <br>
        
        <a href="https://asciinema.org/a/0lHaPxvXTrPTp1Bb6bNea1ZCG"><img src="install.gif" style="max-width:100%"/></a>
        
        </div>
        
        <br>
        
        
        
        ++++
        
        
        
        == Installation
        
        
        Clone the repository:
        
        - `$ git clone https://github.com/modzy/sdk-python.git`
        
        ++++
        <p>Use the package manager <a href=https://pip.pypa.io/en/stable/ style="text-decoration:none">pip</a> to install the SDK. </p>
        ++++
        
        - `$ pip install ./sdk-python`
        
        
        == Usage
        
        
        === Initialize
        
        Once you have a `model` and `version` identified, authenticate to Modzy with your API key:
        [source, py]
        ----
        from modzy import ApiClient, error
        client = ApiClient(base_url='https://modzy.example.com/api', api_key='my_key.modzy')
        ----
        
        === Basic usage
        
        The code below is applicable for `text/plain` input type.
        
        
        ++++
        <div align="center">
        
        <img src="python.gif" alt="basic usage" style="max-width:100%">
        
        </div>
        
        <br>
        ++++
        
        Submit a job providing the model, version, and input file:
        
        [source, py]
        ----
        job = client.jobs.submit_files('ed542963de', '0.0.27', {'input.txt': './some-file.txt'})
        ----
        
        Hold until the inference is complete and results become available:
        
        [source, py]
        ----
        result = client.results.block_until_complete(job, timeout=None)
        ----
        
        Get the output results:
        
        [source, py]
        ----
        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.
        
        [cols="1,3"]
        |===
        |`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`
        
        
        [source, python]
        ----
        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`
        [source, python]
        ----
        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`
        [source, python]
        ----
        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:
        
        :doc-pages: https://models.modzy.com/docs/
        [cols=3*, stripes=even]
        |===
        |Feature|Code|Api route
        
        |[small]#Retrieve all models#
        |[small]#client.models.get_all()#
        |[small]#link:{doc-pages}api-reference/marketplace/retrieve-models[api/models]#
        
        |[small]#Retrieve some models#
        |[small]#client.models.get_models()#
        |[small]#link:{doc-pages}api-reference/marketplace/retrieve-models[api/models]#
        
        |[small]#Retrieve model details#
        |[small]#client.models.get()#
        |[small]#link:{doc-pages}api-reference/marketplace/retrieve-model-details[api/models/:model-id]#
        
        |[small]#Retrieve model by name#
        |[small]#client.models.get_by_name()#
        |[small]#link:{doc-pages}api-reference/marketplace/retrieve-models[api/models]#
        
        |[small]#Retrieve related models#
        |[small]#client.models.get_related()#
        |[small]#link:{doc-pages}api-reference/marketplace/retrieve-related-models[api/models/:model-id/related-models]#
        
        |[small]#Retrieve model versions#
        |[small]#client.models.get_versions()#
        |[small]#link:{doc-pages}api-reference/marketplace/retrieve-versions[api/models/:model-id/versions]#
        
        |[small]#Retrieve model version details#
        |[small]#client.models.get_version()#
        |[small]#link:{doc-pages}api-reference/marketplace/retrieve-version-details[api/models/:model-id/versions/:version-id]#
        
        |[small]#Retrieve all tags#
        |[small]#client.tags.get_all()#
        |[small]#link:{doc-pages}api-reference/marketplace/retrieve-tags[api/models/tags]#
        
        |[small]#Retrieve Tags and Models#
        |[small]#client.tags.get_tags_and_models()#
        |[small]#link:{doc-pages}api-reference/marketplace/retrieve-models-by-tags[api/models/tags/:tag-id]#
        
        |[small]#Submit a Job (Single Text)#
        |[small]#client.jobs.submit_text()#
        |[small]#link:{doc-pages}api-reference/job-inputs/submit-job[api/jobs]#
        
        |[small]#Submit a Job (Multiple Text)#
        |[small]#client.jobs.submit_text_bulk()#
        |[small]#link:{doc-pages}api-reference/job-inputs/submit-job[api/jobs]#
        
        |[small]#Submit a Job (Single Embedded)#
        |[small]#client.jobs.submit_bytes()#
        |[small]#link:{doc-pages}api-reference/job-inputs/submit-job[api/jobs]#
        
        |[small]#Submit a Job (Multiple Embedded)#
        |[small]#client.jobs.submit_bytes_bulk()#
        |[small]#link:{doc-pages}api-reference/job-inputs/submit-job[api/jobs]#
        
        |[small]#Submit a Job (Single File)#
        |[small]#client.jobs.submit_files()#
        |[small]#link:{doc-pages}api-reference/job-inputs/submit-job[api/jobs]#
        
        |[small]#Submit a Job (Multiple Files)#
        |[small]#client.jobs.submit_files_bulk()#
        |[small]#link:{doc-pages}api-reference/job-inputs/submit-job[api/jobs]#
        
        |[small]#Submit a Job (Single AWS S3)#
        |[small]#client.jobs.submit_aws_s3()#
        |[small]#link:{doc-pages}api-reference/job-inputs/submit-job[api/jobs]#
        
        |[small]#Submit a Job (Multiple AWS S3)#
        |[small]#client.jobs.submit_aws_s3_bulk()#
        |[small]#link:{doc-pages}api-reference/job-inputs/submit-job[api/jobs]#
        
        |[small]#Submit a Job (JDBC)#
        |[small]#client.jobs.submit_jdbc()#
        |[small]#link:{doc-pages}api-reference/job-inputs/submit-job[api/jobs]#
        
        |[small]#Cancel job#
        |[small]#job.cancel()#
        |[small]#link:{doc-pages}api-reference/jobs/cancel-pending-job[api/jobs/:job-id]#
        
        |[small]#Hold until inference is complete#
        |[small]#job.block_until_complete()#
        |[small]#link:{doc-pages}api-reference/job-inputs/submit-job[api/jobs]#
        
        |[small]#Get Job details#
        |[small]#client.jobs.get()#
        |[small]#link:{doc-pages}api-reference/jobs/retrieve-job-details[api/jobs/:job-id]#
        
        |[small]#Retrieve results#
        |[small]#job.get_result()#
        |[small]#link:{doc-pages}api-reference/jobs/cancel-pending-job[api/jobs/:job-id]#
        
        |[small]#Retrieve Job History#
        |[small]#client.jobs.get_history()#
        |[small]#link:{doc-pages}api-reference/jobs/retrieve-job-history[api/jobs/history]#
        
        |===
        
        == Samples
        
        
        
        ++++
        <p>Check out our <a href=/samples style="text-decoration:none">samples</a> for details on specific use cases.
        </p>
        ++++
        
        Set the base url and api key in each sample file:
        
        [source, python]
        ----
        # TODO: set the base url of modzy api and you api key
        client = ApiClient(base_url=BASE_URL, api_key=API_KEY)
        ----
        ++++
        <p>Or follow the instructions <a href="/contributing.adoc#set-environment-variables-in-bash" style="text-decoration:none">here</a> to learn more.
        </p>
        ++++
        
        And then, you can:
        
        [source, bash]
        ----
        `$ py samples/job_with_text_input_sample.py`
        ----
        
        
        == Contributing
        
        ++++
        <p>We are happy to receive contributions from all of our users. Check out our <a href="/CONTRIBUTING.adoc" style="text-decoration:none">contributing file</a> to learn more.
        </p>
        ++++
        
        
        //For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
        
        
        ==== Code of conduct
        
        ++++
        <a href="/CODE_OF_CONDUCT.md" style="text-decoration:none">
            <img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Contributor Covenant" style="max-width:100%;">
        </a>
        ++++
        
        == Credits
        
        This package was bootstrapped with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
        
        
        =======
        History
        =======
        
        0.5.0
        ------------------
        * Update version to match Modzy version
        
        0.3.2 (2020-05-12)
        ------------------
        
        * Update model and version client
        * Added samples
        * Review readme file, contributing guide
        * Added .env support
        
        
        0.3.1 (2019-11-22)
        ------------------
        
        * Added basic logging.
        * Switched to `requests` library for HTTP requests.
        
        0.3.0 (2019-11-14)
        ------------------
        
        * Added Tag support.
        * Added ability to query job history.
        * Added ability to query related models.
        
        0.2.0 (2019-09-2)
        ------------------
        
        * Rename library to `modzy`.
        
        0.1.1 (2019-08-27)
        ------------------
        
        * Added docstrings.
        
        0.1.0 (2019-08-26)
        ------------------
        
        * Initial release.
        
Keywords: modzy,sdk
Platform: UNKNOWN
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Requires-Python: >=3.4
Description-Content-Type: text/markdown
