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

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

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.

Related

How to communicate data from ReactJS and Python?

I'm building an app in which I need to communicate data from and to ReactJS and Python. It needs to go both ways - but I'm more concerned about the React part right now. At first I considered JSON, but couldn't find any resources/ libraries to update JSON files, and people said I should stay away from that. Other than literally creating a text file with data in it, what are my options? The application has to do with getting stock data from a python API, doing calculations on it, and sending the data to ReactJS to render on a webpage. I also need ReactJS to send account data back to Python where we do our MySQL. Any suggestions?
Since the ReactJS app is a front-end application, your only real choice to ensure security is exposing an API on the python app which the ReactJS app talks to (via Websockets for example since you're mentioning a bidirectional communication). Maybe take a look at something like Flask with the flask-socketio package.

Open API specification and App Engine Endpoints

I have developed an API on App Engine using the endpoints-proto-datastore library. At this point I am exploring the use of Swagger to create an Endpoints specification, and am not sure how to proceed. Support for this is indicated in Google's Endpoints docs, but there's not much to get started, particularly for Python.
If possible, I'd like to continue using just the endpoints library and webapp rather than going to Flask which seems like overkill. Any hints for how one might thus proceed?

Web server using python

I am trying to develop a multithreaded web server, it has the following task:
Collect data from various data sources (API calls), I was planning to do this using multiple threads.
Store the collected data in a memory data structure
Do some processing on the data structure using another thread
This data structure would be queried by the multiple clients; maybe I could also make separate threads for each client request.
Now regarding language and platform, I was considering either python or JAVA. I did some research on Flask framework for python, but I do not know how it will accommodate the multithreaded nature of web server.
Please suggest how I could achieve the above functionality in my project.
Flask, with some of the available addons, is very suited for what you want to do. Keep in mind that flask is pure python, and therefore you can access any of the excellent available python libraries.
As far as I understand what you have in mind, you can:
1- define a url that, when visited, executes the data gathering from external sources by means of, e.g. python-requests (http://docs.python-requests.org/en/latest/)
2- do the same periodically by scheduling the function above
3- store the collected data in a (e.g.) Redis database (which is memory based) or one of the many available databases (all of the nosql dbs have python bindings that you can access from a flask application)
4- define urls for the visiting clients to access the latest versions of the data. You will just need to define the data extraction functions (from redis or whatever you decide to use) and design a nice template to show them.
Flask/Werkzeug will take care of the multithreading necessary to handle simultaneous requests from different clients.

python client app model comunication with a Json API

Sorry in advice for my strange english.
I have to develop a client application with python that comunicate with a php server that uses JSON protocol for data exchange.
There are many python frameworks that permit to implement MVC pattern, and in particular with structured Models for data handling, but all these model structures talk directly with a database in SQL language.
My purpose is to use a single server that shots data with JSON api to all kind of devices or platforms.
So, in my python application, i would to write a syncing model storage that talks directly with my Json Server as well as an ExtJs 4 app, using a framework or a library that permits to implement easily my request.
Does anybody knows any tools that permits this ?
If I understood your question correctly, you're looking for a proxying solution to put between application server clients. It may not be 100% fit but I'd suggest looking at Ext.Direct remoting that's built in Ext JS; RPC should work fine if you don't have to publish and maintain your API. As for proxying, take a look at RPC::ExtDirect::Client. It's an Ext.Direct client implementation in Perl; I developed it mostly for testing purposes but it can probably be used for proxying, too.
On a side note, I'm not sure why exactly you would want to implement such an architecture at all. It sounds overcomplicated for no good purpose.

Creating a python web server to recieve XML HTTP Requests

I am currently working on a project to create simple file uploader site that will update the user of the progress of an upload.
I've been attempting this in pure python (with CGI) on the server side but to get the progress of the file I obviously need send requests to the server continually. I was looking to use AJAX to do this but I was wondering how hard it would be to, instead of changing to some other framerwork (web.py for instance), just write my own web server for receiving the XML HTTP Requests?
My main problem is that sending the request is done from HTML and Javascript so it all seems like magic trickery at the moment.
Can anyone advise me as to the best way to go about receiving these requests on the server?
EDIT: It seems that a framework would be the way to go. Would web.py be a good route to take?
I would recommend to use a microframework like Sinatra for Ruby. There seem to be some equivalents for Python. What python equivalent of Sinatra would you recommend?
Such a framework allows you to simply map a single method to a route.
Writing a very basic HTTP server won't be very hard (see http://docs.python.org/library/simplehttpserver.html for an example), but you will be missing many features that are provided by real servers and web frameworks.
For your project, I suggest you pick one of the many Python web frameworks and run your application behind Apache/mod_wsgi.
There's absolutely no need to write your own web server. Plenty of options exist, including lightweight ones like nginx.
You should use one of those, and either your own custom WSGI code to receive the request, or (better) one of the microframeworks like Flask or Bottle.

Categories

Resources