Skip to main content

Provide non-intrusive and one-click machine learning api release tool.

Project description

Flask-autoapi

This project is mainly for machine learning projects. Sometimes a machine learning service is written, but it requires a lot of additional code to deploy. Is there any way to register a service to restful api for deployment without changing all the code of the machine learning service? flask-autoapi gives the answer.

First, you need to put the entire code of your machine learning service into a directory to become a module (actually add the __init__.py file in this directory), and then specify which python file in the directory contains Service, and then specify which function of this file provides the service. Turn the above into a config and directly call flask_autoapi.launch(config) to deploy the service directly.

Dependencies

flask-1.1.2
flask-RESTFUL-0.3.8

Example

Step1: Suppose you have a local service named service2, and you want to provide service2.service as a restful service.

Step2: Make the service2 directory as a python module first.

The example service2 may have its own dependcies, not worry, you don’t need to change any codes.

services/service2/service2:

from dependencies import add, mul

def service2(param1, param2, param3):
    param1 = int(param1)
    param2 = int(param2)
    param3 = int(param3)

    ans1 = add(param1, param2, param3)
    ans2 = mul(param1, param2, param3)

    return str(ans1), str(ans2)

It should be noted that the input parameters and output parameters of the interface functions that provide services must be in the type of strings, of course, there is no limit to the parameter number.

Step3: Make such a config dictionary:

service_config = {
    'service_dir'               : './services/service2', # Service root directory
    'service_python_filename'   : 'service2',            # service2.py
    'service_python_interface'  : 'service2',            # service2 is the interface function

    'service_input_params' : {                           # interface input params are defined here
        'param1': 'param1 describe here',
        'param2': 'param2 describe here',
        'param3': 'param3 describe here',
    },

    'service_output_params' : {                          # interface output params are defined here
        'add_result': 'value describe here',
        'mul_result': 'value describe here'
    },

    'deploy_mode'   : 'restful', # c++ deploy            # now only has restful deploy
    'deploy_port'   : '12345',                           # service port
    'service_route' : '/test_service'                    # service route
}

It should be noted that the input and output parameters of the interface must be written in the configuration dict in the same form, and the keys of service_input_params or service_output_params will be the http request parameter and the response keys respectively. The values of service_input_params and service_output_params are describes to those parameters.

Step4: Then launch this service api:

import flask_autoapi
flask_autoapi.launch(service_config)

Step5: The service will be running:

* Running on http://127.0.0.1:12345/ (Press CTRL+C to quit)
* Serving Flask app "flask_autoapi.restful_service_enroll" (lazy loading)
* Environment: production
  WARNING: This is a development server. Do not use it in a production deployment.
  Use a production WSGI server instead.
* Debug mode: off

The test url:

http://127.0.0.1:12345/test_service?param1=1&param2=2&param3=3

The response:

{"status": 200, "add_result": "6", "mul_result": "6"}

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

flask_auto_api-1.0.8.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

flask_auto_api-1.0.8-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file flask_auto_api-1.0.8.tar.gz.

File metadata

  • Download URL: flask_auto_api-1.0.8.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.10

File hashes

Hashes for flask_auto_api-1.0.8.tar.gz
Algorithm Hash digest
SHA256 d956d7a70b670c8cb0172203b3d99a4d7715b628f3b2305cc1adf1577a970447
MD5 8c903115d1b29bca8c299dd53a4cf276
BLAKE2b-256 724ec8e783001da47d45f53f242c15679ccd47e51d21c21029dd09f626b92b63

See more details on using hashes here.

File details

Details for the file flask_auto_api-1.0.8-py2.py3-none-any.whl.

File metadata

  • Download URL: flask_auto_api-1.0.8-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.10

File hashes

Hashes for flask_auto_api-1.0.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2abf9474904777448b0f27c4c5333712a3aa56dd092faaa7f3be7b37fbbd9f5c
MD5 95efe5fdfec4f2b5d5de9b3c08a9612d
BLAKE2b-256 54548908d384eee3437c82da3539d3098c6339b173b94cb5db8d603e3819779c

See more details on using hashes here.

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