'FastAPI - Dataframe updated change lost between route
I'm trying to make a simple FastAPI api.
Let's suppose these routes:
The POST Route
@api.post('/user', name='Get list of users')
def get_user(user: User):
"""Returns a list of users
"""
res = get_user(data, user.name, user.nick, user.mail)
return {
'username': user.name,
'nickname': user.nick,
'user': user.mail
'USERS': res
}
And the PUT Route
@api.put('/add_user', name='Create a new user')
def add_question(new_user: New_User):
u = {
'name': new_user.name,
'nick': new_user.nick,
'mail': new_user.mail
}
global data
data = data.append(u, ignore_index=True)
return parse_csv(data)
The 'data' is a pandas dataframe (from a csv). And the 'parse_csv()' function is an helper function which transform my dataframe to json.
Now, my issue is when I add a user through the PUT route, the user is correctly added (I can see it via the return), and if I made a request with my GET route, the dataframe is not updated.
How can I update my dataframe without loose any change between route usage ?
I precise it's an API for test purpose, so that's the reason why i'm using a csv file.
Thank's a lot.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|