Skip to main content

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"}

Metadata

Release files for flask-auto-api 1.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-auto-api 1.0.8
File Size Uploaded Provenance Actions
flask_auto_api-1.0.8.tar.gz 4.5 kB Without provenance Details for flask_auto_api-1.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flask-auto-api 1.0.8
File Interpreter ABI Platform Actions
flask_auto_api-1.0.8-py2.py3-none-any.whl Python 2, Python 3 none any Details for flask_auto_api-1.0.8-py2.py3-none-any.whl

Total release size: 9.6 kB

Release files / flask_auto_api-1.0.8.tar.gz

Download URL flask_auto_api-1.0.8.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d956d7a70b670c8cb0172203b3d99a4d7715b628f3b2305cc1adf1577a970447
BLAKE2b-256 checksum
How to use checksums
724ec8e783001da47d45f53f242c15679ccd47e51d21c21029dd09f626b92b63
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / flask_auto_api-1.0.8-py2.py3-none-any.whl

Download URL flask_auto_api-1.0.8-py2.py3-none-any.whl
Size 5.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2abf9474904777448b0f27c4c5333712a3aa56dd092faaa7f3be7b37fbbd9f5c
BLAKE2b-256 checksum
How to use checksums
54548908d384eee3437c82da3539d3098c6339b173b94cb5db8d603e3819779c
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for flask-auto-api 1.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page