Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consume External XML API (with models, etc) with Flask

I'm going to be building a webapp that will consume an XML-based API, and I'd like to use Flask to make it.

Assuming I will be using SQLAlchemy for a database and something like FlaskWTF for forms, how can I get started using Flask in this way? I'm not really sure where to begin. I've heard the requests Python library a good way to go, but I don't know how to integrate that with db.model or other features of Flask, since I will be building an MVC-like app.

I've read through this but it doesn't really help me since I won't be using a local database. https://github.com/mitsuhiko/flask/wiki/Large-app-how-to

like image 450
element119 Avatar asked Dec 07 '25 01:12

element119


1 Answers

The requests library simplifies the work of making HTTP requests, but it does nothing in particular to help you consume the response XML. You might be more comfortable with Suds, PySimpleSOAP, or Flask-Enterprise to consume the SOAP data. Likewise, Flask alone does little to help you consume SOAP services specifically, but Flask complements other Python libraries made to work with SOAP.

Begin by writing and testing functions that interact with the SOAP data source. These functions should serve as the data models for your application, translating Python objects to/from SOAP requests. I presume you have no need for local caching or application-specific local data storage, since you mention that you won't be using a local database (though these can be added easily if desired).

Just as SQLAlchemy isolates the details of SQL from the rest of an app, your SOAP-backed data models should insulate the rest of your application from SOAP specifics. Build your app on these data models, relying on native Python objects as you'd find in most generic Flask examples.

like image 71
roderickm Avatar answered Dec 08 '25 16:12

roderickm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!