Should I have a NodeJS server for react server-side rendering? - python

I have a API server which is written in python.
And I wanted to render my react components on server side.
So I searched the best practices and result was having a nodeJS server.
But in my thoughts, this is weird because I have to build a another server with different language. This is bad at maintainable, and maybe have an overload.
So I want to know having nodeJS server is usual. and also how do big companies do server-side rendering.

If it is as simple as wanting to use Python with React, you can use python-react to render React components.
As noted above, if you are using Flask, the templating is in Jinja2, but that isn't necessarily mutually exclusive to using React in your project.
This resource on using Flask/React may be of use to you, as well.

Related

Client-Server framework for python

I'm currently working on a University project that needs to be implemented with a Client - Server model.
I had experiences in the past where I was managing the communication at socket level and that really sucked.
I was wondering if someone could suggest an easy to use python framework that I can use for that purpose.
I don't know what kind of details you may need to answer so I'm just going to describe the project briefly.
Communication should happen over HTTP, possibly HTTPS.
The server does not need to send data back or invoke methods on the clients, it just collects data
Many clients send data concurrently to server, who needs to distinguish the sender, process the data accordingly and put the result in a database.
You can use something like Flask or Django. Both frameworks are fairly easy to implement, Flask is much easier than Django IMO, although Django has a built in authentication layer that you can use, albeit more difficult to implement in a client/server scenario like you need.
I would personally use Flask and JWT (JSON Web Tokens), which will allow you to give a token to each client for authentication with the server, which will also let you differentiate between clients, and you can use HTTPS for your SSL/TLS requirement. It is tons easier to implement this, and although I like django better for what it brings to the table, it is probably overkill to have you learn it for a single assignment.
For Flask with SSL, here is a quick rundown of that.
For JWT with Flask, here is that.
You can use any database system you would like.
If I understood you correctly you can use any web framework in python. For instance, you can use Flask (I use it and I like it). Django is also a popular choice among the python web frameworks. However, you shouldn't be limited to only these two. There are plenty of them out there. Just google for them.
The implementation of the client depends on what kind of communication there will be between the clients and the server - I don't have enough details here. I only know it's unidirectional.
The client can be a browser accessing you web application written in Flask where users send only POST requests to the server. However, even here the communication will bidirectional (the clients need to open the page which means the server sends requests back to the client) and it violates your initial requirement.
Then it can be a specific client written in python sending some particular requests to your server over http/https. For instance, your client can use a requests package to send HTTP requests.

Gwt Front end with python web server

I am building a web app where I'd like to use GWT for generating the java script that runs in the browser but because I use other python packages (specifically scipy) I would like for the web server to be python (not a servlet engine). Has anybody done so ? Any pointers would be appreciated.
Thank you.
Ranga
GWT is a front-end framework. You can use any backend technologies, whether it is Python, PHP, Java, Node.js or any Server-side technologies. There is no limitations on this. I haven't use GWT for quite long now, You have the request builder to fetch data from the server.
Anyway, the simplest solutions that gonna scale for wide range of your devices is to build a REST API on the backend with python, its very simple, you have many simply python technologies like Bottle or Flask that does it in a giffy for you. Build your backend and make it follow REST conventions.
Then, on the level of GWT, it has to have something for fetching data from the webserver. I'll advise to make your data in JSON and then you'll be able to use technologies like GSON to convert your JSON serialised string into Java objects on the fly
Pyjamas looks like it was originally a port of GWT to Python:
https://wiki.python.org/moin/Pyjamas
This guy doesn't like it though, so you might consider the cons to doing this as well:
http://blog.pyjeon.com/?p=302

Python framework for an extremely lightweight python webservice

I want to develop an extremely lightweight web service with a RESTful JSON API. I will do all the session management on the server side. The solution will receive several 100k (or more) API calls an hour and return (compressed) JSON as response, it should be able to scale effortlessly.
Security is naturally important, but I want to avoid heavy weight frameworks like Django etc, and preferably will use a webserver like nginx or lighttpd instead of Apache.
At the server end, this is all I need:
user session management
security (protection against atleast the more common attacks such as cross site request forgery etc)
url routing
http utilities (e.g. compression)
I am aware of web2py, but its deployment options seems 'not well though out' at best - so far, I have been unable to get it to work with Apache, despite following the user manuals.
Can anyone suggest a python framework (and web server) best suited for this task?
if you want to go really lightweight, you might try wsgi itself without a framework, or maybe Flask. I understand wsgi runs on lighttpd, you'll get some hits on a Google search.
Try Pyramid. It's fast, lightweight and with a lot of options to configure your enviroment as you like...

Deciding to WSGI or Django for new web app

I'm in the process of setting up a new web app and deciding whether to just do it with WSGI or go the full framework route with Django.
The app's foremost requirements:
1) The app has no UI what so ever and all of the data is exposed to clients via a REST api with JSON.
2) It will have data to persist so MongoDB & probably Amazon's SimpleDB will be used for the database side.
Is there a reason to use Django or can I get marginal speed improvement with WSGI only?
Previous server-side apps I've built were either with Java/Struts and Groovy/Grails on the JVM. My understanding is that Django is an MVC framework similar to Rails and Grails.
I've also played around with Google App Engine which uses WSGI as thin layer above your code for managing and routing requests.
I suggest you consider something between those two extremes. Flask is lightweight, very easy to use, and connects to your web server via wsgi. You can use regular python database connectors with it, and a few databases even have Flask-specific extension modules.
I have worked with Django for a couple of projects and I like it a lot, but since you are going to use mongoDB and a lot of JSON I suggest you use NodeJS as server side, with Express as framework, you can see a brief tutorial here:
http://howtonode.org/express-mongodb
One of the advantages of this is that you will use only javascript all along your project, I began working with this technology the last month in a Hackathon, and I can tell you that I'm very impressed of how fast and simple it is.
I've worked a bit with some django "apps" ,its really easy, but setting up the "apps" can be a bit of a long process. Django has a lot of nice features that you won't be using and I agree that you might be on one "extreme" here.

HTTP framework for a python based server serving mobile applications

I am working on building a python powered back-end server for a mobile application. I am using MongoDB hosted on the Cloud for storage. The communication between the Application and the server will be mostly JSON. There wont be any HTML involved in this transfer as such.
I am looking for a framework to build my server. I did some research and found (django, Pylons etc) are for full stack server and is not needed for my requirements.
I am confused on how to go about selecting an HTTP framework (web.py, cherrypy etc).
also, i might use Mongoengine as the ODM. I am not sure if this decision is anyway going to affect the framework selection
any ideas?
I'd recommend bottle or flask, both of which are very minimal and impose no constraints on you whatsoever. In the case of bottle, it's particularly easy to build a simple RESTful server since it will automatically return JSON from a route that returns a dict:
from bottle import route, run
#route('/user_info/:id'):
def user_info(id):
user = get_user(id) # ...do something, lookup user, whatever
return {'first_name': user.first_name, 'last_name': user.last_name}
run()
Pyramid Framework doesnt enforce a templating engine (not a full stack) or a persistence/storage system. It has json and jsonp renderer (no html at all).
It also has a scaffold for jquery mobile app (I havent tried this, so I dont know).
I personally prefer web.py, but in your case it is possible to start with basic wsgi app, or something simple as http://werkzeug.pocoo.org/ because it doesn't enforce a specific template engine or database adapter.

Categories