1

I have Flask application and need to add SOAP server functionality to integrate with some services. The Spyne library was choosen for SOAP. I found how to combine Flask and Spyne wsgi apps together using werkzeug.wsgi.DispatcherMiddleware. But now I faced with issue of getting Flask app config inside Spyne service views. I usually use current_app.config['FOO'] to get Flask app settings, but when request comes to Spyne wsgi app I have no Flask application context. I need an advice how to deal with it, please.

Paco
  • 4,520
  • 3
  • 29
  • 53
Anton Egorov
  • 1,174
  • 1
  • 11
  • 21
  • I'm using Flask but don't know Spyne, just a suggestion: how about using a config file shared between Flask and Spyne? See [Flask Configuring from Files](http://flask.pocoo.org/docs/config/#configuring-from-files). – Leon Young Oct 14 '13 at 09:21
  • Yes, I can. But my app has a few configs and there are some configuration logic. The better is to share read-only config instance. I will try. My mind is stuck in thought that I alway have flask app context, it is very handy. – Anton Egorov Oct 14 '13 at 10:34
  • Hi, Spyne maintainer here. Can you provide a working example? I skimmed over the Flask app config page but did not find much about your specific use case. – Burak Arslan Oct 14 '13 at 13:04
  • Hello Spyne maintainers! I've created an example to show you my use case. This is the line I want to access flask app config http://goo.gl/N3HzEh – Anton Egorov Oct 14 '13 at 20:16
  • Now I found solution to `set ctx.udc.config` to `flask_app.config` on `wsgi_call` event. But I dont like it. I think how to integrate Spyne views to Flask natively. – Anton Egorov Oct 14 '13 at 20:18
  • I've created a pull request with flask example https://github.com/arskom/spyne/pull/286 – Anton Egorov Oct 18 '13 at 06:30

2 Answers2

0

I don't know how to get hold of that config object outside of the Flask context, but if you can, you can setattr anything to the Application instance which is acccessible via ctx.app within Spyne's @rpc context.

Burak Arslan
  • 7,671
  • 2
  • 15
  • 24
  • This is the solution I choose. On `wsgi_call` I set `ctx.udc.config` to `flask_app.config`, and use it wherever I need. – Anton Egorov Oct 14 '13 at 14:19
  • This is the right way to do it. If you can share your code, I can put it in the Spyne examples directory in the main repo. I don't see the wsgi_call event in the example you shared. – Burak Arslan Oct 16 '13 at 20:30
  • I've created a pull request with flask example https://github.com/arskom/spyne/pull/286 – Anton Egorov Oct 18 '13 at 06:30
  • I created a pull request in Flask-Spyne to use Flask app context. This way, I have full access to Flask context, not only config. https://github.com/rayrapetyan/flask-spyne/pull/3 – iurisilvio Dec 22 '14 at 12:44
-1

I am assuming a shared config file approach is not possible for you, otherwise I would go for import from the config file in the spyne e.g from config import blah blah just a thought

Ryan
  • 221
  • 3
  • 7