Skip to content

Instantly share code, notes, and snippets.

@avilior
Created April 30, 2021 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avilior/fc3bcfa3bc916216edec1ef5dfecddd0 to your computer and use it in GitHub Desktop.
Save avilior/fc3bcfa3bc916216edec1ef5dfecddd0 to your computer and use it in GitHub Desktop.
FastApi
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from fastapi import FastAPI
import logging
LOG = logging.getLogger(__name__)
app = FastAPI()
@app.on_event("startup")
async def on_start_up():
LOG.info("Start Up procedures...")
LOG.info("Start up procedures DONE")
@app.on_event("shutdown")
async def on_shutdown():
LOG.info("Shutdown procedures...")
LOG.info("Shutdown procedures DONE")
@app.get('/')
async def hello():
return F"Hello From Fast API: {__name__}"
if __name__ == '__main__':
import uvloop
import uvicorn
logging.basicConfig(
filename=None,
filemode="a",
format='%(asctime)-15s|%(levelname)-8s|%(filename)-25s|%(funcName)-15s|%(lineno)-4s|%(message)s',
level=logging.INFO
)
uvloop.install()
uvicorn.run(app, host="0.0.0.0", port=9000, log_level="info")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment