How to set global variable in request lifecycle?
See original GitHub issueHow can I set some data in global request lifecycle which can be used throughout the app In flask, it was possible via,
from flask import g
g.data = {}
tried setting data to the incoming requests, but it turns out request is read-only. Please help! Thanks in advance.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
FastApi: How to define a global variable once - Stack Overflow
One approach would be to use the FastAPI startup event to define the variable data once on app startup. An example similar to...
Read more >How to set a global variable in Postman? - Tutorialspoint
Step4 − First select the option Environment_Test and add {{url} in the address bar. On hovering over it, we shall show the letter...
Read more >How do I set global variables to be used by all flows? - IBM
In IBM Spectrum LSF Application Center, select System & Settings > System Services > Flow Manager Service; Select Set Global Variables to display...
Read more >Can we use global variable sets in different applications
Yes, We can use Global variable sets in different application Record producer. The scripts and policies which are applicable to that global ...
Read more >Use Global Variables and Data Stitch to log request payloads
We will create a Global Variable based on the request payload. Global Variables are visible anywhere in the integration, including fault ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @knowBalpreet and other contributors of this issue.
I just learned the new
contextvars
that comes with Python 3.7+, and made this Gist that provide a request lifecycle pseudo-global similar to the Flask “g” object.https://gist.github.com/glenfant/2fe530e5a2b90c28608165b5a18afcaf
Any comment on the Gist is welcome.
found it. for reference: https://fastapi.tiangolo.com/advanced/using-request-directly/