Ask a Question

Swagger codegen for Flask (Python). Access to shared Python object from models and controllers

fillmore
Frequent Visitor

Swagger codegen for Flask (Python). Access to shared Python object from models and controllers

Hello, I have an existing (and fully functioning) REST API built with Flask that I am re-implementing using the OpenAPI 3.0 for the heck of it.

I am using the Swagger codegen to jumpstart the server part. First a general question: is there a document/tutorial/blogpost that explains how the different bits hang together?

Looking at the files in the swagger_server folder it sort of makes sense, but I could still use an overview of some kind (apologies if it's somewhere in plain sight, I couldn't find it).

 

Here is my specific question. In my existing server, I have a pretty heavy initialization part that generates some large "in-memory" data structures. As my current implementation is a monolithic file, that's not an issue. But as controllers and models will need to access this data structure (and re-initializing it each time is out of question), how do you recommend that I access this shared object from within controllers and model? Is there a way for me to set a reference in __main__.py that I can access from all the other classes? Or should I create some kind of singleton?  Or am I missing something?

 

Hopefully what I wrote made sense. 

 

Thank you

0 REPLIES 0
cancel
Showing results for 
Search instead for 
Did you mean: