Home:ALL Converter>flask project compile in cython then deploy or run

flask project compile in cython then deploy or run

Ask Time:2018-10-07T19:15:01         Author:Ferdous Wahid

Json Formatter

I have a Python flask app and I need to compile with cython and then deploy or run it. Following this guide, I can compile simple python application. I need to do the same thing to a simple flask app and then run it. my Flask==1.0.2

flaskPractise.py:

#!flask/bin/python3

from flask import Flask, url_for
app = Flask(__name__)

@app.route('/')
def api_root():
    return 'Welcome'

@app.route('/articles/<articleid>')
def api_article(articleid):
    return 'You are reading ' + articleid

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

compile.py :

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [
    Extension("flaskPractise", ["flaskPractise.py"])
]
setup(
    name = 'My Program Name',
    cmdclass = {'build_ext': build_ext},
    ext_modules = ext_modules
)

main.py:

from logic import main
main()

after running python3 compile.py build_ext --inplace command flaskPractise.c file and flaskPractise.cpython-37m-x86_64-linux-gnu.so is created.now how do i run this?

Author:Ferdous Wahid,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52687929/flask-project-compile-in-cython-then-deploy-or-run
yy