from flask import Flask, jsonify, request
import jedi

app = Flask( __name__ )


@app.route( '/healthy' )
def healthy():
    return jsonify()


@app.route( '/ready' )
def ready():
    return jsonify()


@app.route( '/completions', methods=['POST'] )
def completion():
    script = _GetJediScript( request.get_json() )
    return jsonify( {
        'completions': [
            {
                'name':        completion.name,
                'description': completion.description,
                'docstring':   completion.docstring()
            } for completion in script.completions() ]
        } )


def _GetJediScript( request_data ):
    filename = request_data[ 'filepath' ]
    contents = request_data[ 'contents' ]
    line     = request_data[ 'line_num' ]
    column   = request_data[ 'column_num' ]

    return jedi.Script( contents, line, column, filename )

import os
import sys

third_party_dir = os.path.join( os.path.dirname( __file__ ), 'third_party' )
for folder in os.listdir( third_party_dir ):
    sys.path.insert( 0, os.path.realpath( os.path.join( third_party_dir,
                                                        folder ) ) )

from flask import Flask, jsonify, request
import jedi


app = Flask( __name__ )


@app.route( '/healthy' )
def healthy():
    return jsonify()


@app.route( '/ready' )
def ready():
    return jsonify()


@app.route( '/completions', methods=['POST'] )
def completion():
    script = _GetJediScript( request.get_json() )
    return jsonify( {
        'completions': [
            {
                'name':        completion.name,
                'description': completion.description,
                'docstring':   completion.docstring()
            } for completion in script.completions() ]
        } )


def _GetJediScript( request_data ):
    filename = request_data[ 'filepath' ]
    contents = request_data[ 'contents' ]
    line     = request_data[ 'line_num' ]
    column   = request_data[ 'column_num' ]

    return jedi.Script( contents, line, column, filename )

Use vendored library