How to use the uvicorn.run function in uvicorn

To help you get started, we’ve selected a few uvicorn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytest-docker-compose / pytest-docker-compose / tests / pytest_docker_compose_tests / my_network / a_buildable_container / an_api.py View on Github external
return cursor.fetchone()


@app.delete("/items/{item_id}")
def delete_item(item_id: int):
    with CONNECTION.cursor() as cursor:
        cursor.execute('DELETE FROM my_table WHERE num=%s RETURNING *;', (item_id, ))
        CONNECTION.commit()
        return cursor.fetchone()


if __name__ == "__main__":
    try:
        CONNECTION = psycopg2.connect(dbname='postgres', user='postgres', host='my_db', port=5432)
        create_database()
        uvicorn.run(app, host="0.0.0.0", port=5000, log_level="info")
    finally:
        CONNECTION.close()
github apiad / auditorium / auditorium / show.py View on Github external
def run(self, *, host: str, port: int, debug: bool = False) -> None:
        self._content = self._render_content()

        try:
            import uvicorn

            uvicorn.run(self.app, host=host, port=port, debug=debug)
        except ImportError:
            warnings.warn("(!) You need `uvicorn` installed in order to call `run`.")
            exit(1)
github deepmipt / DeepPavlov / deeppavlov / utils / alexa / server.py View on Github external
signature_chain_url: str = cert_chain_url_header) -> JSONResponse:
        # It is necessary for correct data validation to serialize data to a JSON formatted string with separators.
        request_dict = {
            'request_body': json.dumps(data, separators=(',', ':')).encode('utf-8'),
            'signature_chain_url': signature_chain_url,
            'signature': signature,
            'alexa_request': data
        }

        bot.input_queue.put(request_dict)
        loop = asyncio.get_event_loop()
        response: dict = await loop.run_in_executor(None, bot.output_queue.get)
        response_code = 400 if 'error' in response.keys() else 200
        return JSONResponse(response, status_code=response_code)

    uvicorn.run(app, host=host, port=port, logger=uvicorn_log, ssl_version=ssl_config.version,
                ssl_keyfile=ssl_config.keyfile, ssl_certfile=ssl_config.certfile)
    bot.join()
github Machine-Learning-Tokyo / kuzushiji-lite / classifier.py View on Github external
#@app.route("/form")
#def redirect_to_homepage(request):
#@    return RedirectResponse("/")

@app.route('/analyze', methods=['POST'])
async def analyze(request):
    data = await request.form()
    img_bytes = await (data['file'].read())
    img = open_image(BytesIO(img_bytes))
    pred_class, pred_idx, outputs = learn.predict(img)[0]
    return JSONResponse({'result': str(pred_class)})

if __name__ == '__main__':
    uvicorn.run(app, host='0.0.0.0', port=8888)
github ray-project / ray / python / ray / experimental / serve / server.py View on Github external
def run(self, host="0.0.0.0", port=8000):
        uvicorn.run(
            self.app, host=host, port=port, lifespan="on", access_log=False)
github opensight-cv / opensight / demo.py View on Github external
def main():
    program = make_program()

    make_nodetree(program)

    program.pipeline.run()

    webserver = WebServer(program)

    test_webserver(webserver)

    uvicorn.run(webserver.app)
github render-examples / fastai-v3 / app / server.py View on Github external
html_file = path / 'view' / 'index.html'
    return HTMLResponse(html_file.open().read())


@app.route('/analyze', methods=['POST'])
async def analyze(request):
    img_data = await request.form()
    img_bytes = await (img_data['file'].read())
    img = open_image(BytesIO(img_bytes))
    prediction = learn.predict(img)[0]
    return JSONResponse({'result': str(prediction)})


if __name__ == '__main__':
    if 'serve' in sys.argv:
        uvicorn.run(app=app, host='0.0.0.0', port=5000, log_level="info")
github rmyers / cannula / examples / cloud / mock_server.py View on Github external
}
            ]
          }
        ]
      }
    })


for server_id in SERVER_IDS:
    create_new_server('fake', IMAGES[0].get('id'), FLAVORS[0].get('id'), server_id)


if __name__ == '__main__':
    import uvicorn
    LOG.info(f'starting mock openstack server on {PORT}')
    uvicorn.run(app, host='0.0.0.0', port=8080, debug=True, log_level=logging.INFO)
github pankymathur / google-app-engine / app / server.py View on Github external
loop.close()

@app.route('/')
def index(request):
    html = path/'view'/'index.html'
    return HTMLResponse(html.open().read())

@app.route('/analyze', methods=['POST'])
async def analyze(request):
    data = await request.form()
    img_bytes = await (data['file'].read())
    img = open_image(BytesIO(img_bytes))
    return JSONResponse({'result': learn.predict(img)[0]})

if __name__ == '__main__':
    if 'serve' in sys.argv: uvicorn.run(app, host='0.0.0.0', port=8080)
github ClericPy / newspaper / newspaper / server.py View on Github external
def main():
    uvicorn.run(
        app,
        host='127.0.0.1',
        port=9001,
        proxy_headers=True,
    )