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.
Related
I'm learning about basic back-end and server mechanics and how to connect it with the front end of an app. More specifically, I want to create a React Native app and connect it to a database using Python(simply because Python is easy to write and fast). From my research I've determined I'll need to make an API that communicates via HTTP with the server, then use the API with React Native. I'm still confused as to how the API works and how I can integrate it into my React Native front-end, or any front-end that's not Python-based for that matter.
I think you have to follow some online tutorial
And from my experiences, I think Flask is good choice for such case.
This is basic flask tutorial provided by tutorialspoint.com
You have to create a flask proxy, generate JSON endpoints then use fetch or axios to display this data in your react native app. You also have to be more specific next time.
I am developing a chatbot using DialogFlow, as my natural language processing handler, and Python as my client.
My application aims to talk with a human in a python environment (I am currently using a Jupyter Notebook), send the request to DialogFlow, get the response, then calculate the data using some python libraries and show the results to the user.
All the process described above is already working.
Now I must to find a way that lets the people uses my chatbot on line.
Here is my problem, I don't know how to model this.
I think I should put my chatbot in a webpage and make it communicate with my python application stored in a server.
Did anybody make something similar?
Given your current architecture, you'll have to do the following:
Write a client for your chatbot in HTML and JavaScript
Write a server in Python that contains your application logic and makes the API calls to Dialogflow
This is a pretty normal architecture for a web application. Given that you're using Python, you might find Flask or Django helpful.
There should be plenty of samples out there that can help you figure out what to do; I just found this blog post that demonstrates how to build a simple chat client/server with Flask and websockets.
If you're willing to change your architecture so that the user interacts directly with Dialogflow, and all of your application logic lives in the Dialogflow fulfillment webhook, you can make use of Dialogflow's Web Demo integration that provides a pre-built chat widget you can embed into an HTML page.
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.
I have a long-running process written in Python 2.7 that I would like to send KML files to my GWT application asynchronously as the KML files are generated.
I have been trying to determine what Python web framework I could use as the back-end with the Python process that could possibly allow the webapp to be hosted on Google AppEngine.
I was able to write a simple python webserver using Cherrypy that sent the kml using JSON from the back-end to GWT using an http request; however, I would like the files to be sent to GWT as they are generated since it may be several minutes between each one. What would be a relatively simple but effective way to achieve this? (Comet? Long-polling? Websockets?)
After researching more python web frameworks, I started experimenting with Tornado because it is non-blocking and seems like it could return data as it is generated possibly using long-polling as mentioned in this answer. However, it looks like GAE requires WSGI which would not allow a Tornado webserver to be non-blocking.
I have read answers to similar questions such as this one. However, I am not sure if updates in web frameworks, GWT, or GAE has changed what is the best option today, or whether some of these answers apply to my case.
What Python web framework would you recommend I use to send data to my asynchronous GWT app using long-polling or another method relatively simply? Could I use this web framework with GAE, or would I need to use something else?
If I understood the problem correctly you might don't need any special framework and you can solve it with what you have: Tasks API and Channel API.
With Tasks API you can perform long task and when the task is complete you can get a notification. You can combine it with the Channel API to push messages directly to the client when a particular task is complete.
You could use also the deferred library to simplify your life with tasks and maybe even using the PubNub for your push notifications, since the setup is easier and you can have many subscribers at the same time.
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.