Skip to content
Discussion options

You must be logged in to vote

In this case you can just do something like this.

app = FastAPI()
    
@app.get("/item")
def do_get_item(p3):
    return get_item()

@app.on_event("startup")
def app_startup():
    p1 = sys.argv[0]
    p2 = sys.argv[1]
    print(p1, p2)
    # do_startup_stuff(p1, p2)

@app.on_event("shutdown")
def app_shutdown():
    p4 = sys.argv[1]
    print(p4)
    # do_shutdown_stuff(p4)


if __name__ == "__main__":
    uvicorn.run(app)

If these require a more complicated configuration usually in fast api this is done by using a settings/config object which you can learn more about here https://fastapi.tiangolo.com/advanced/settings/#create-the-settings-object

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dineshbvadhia
Comment options

Answer selected by dineshbvadhia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
2 participants
Converted from issue

This discussion was converted from issue #5822 on February 24, 2023 16:29.