Can the Pyramid framework be run on a CGI server - python

Ok, I get that CGI is sow outdated, and no one likes it, but I have a customer who needs a new site, is on shared hosting, and does not wish to change hosting providers. We are doing the back-end of his site in Python, and are researching Python framework options that can run as CGI(no one wants to just use the CGI module). So far, It seems Django can be run on CGI, but it is terrible. Flask and Bottle seem to run well on CGI(at least it is supported), but I was wondering if the Pyramid Framework can. If not, I guess we will just be using Flask. Can I get Pyramid running on CGI? If so what would be the performance against running Flask r Bottle under CGI?

See this solution here, it shows how to use WSGI on CGI
https://www.python.org/dev/peps/pep-0333/#the-server-gateway-side

Take a look at wsgiref as well
https://docs.python.org/2/library/wsgiref.html
example :
https://github.com/w1mvy/twitter_bot_on_gae-py/blob/55754d0ec1580b67f7f0c710f5cf3456313cff4d/app.py

Related

Best way to make a web interface for python script

I've made a small python script to scrap the web. I would like to make a nice and simple web interface where the user can enter data to search for and have the result displayed as a list.
I understand that there's many different ways to do that but don't know which one would be the best in my case.
I would like something :
Really simple and light
Running locally with the less dependencies possible.
So far I've thinking about :
A NodeJS server displaying content and executing the script
A web framework in Python (web.py, Flask, Django..?)
A local webserver (XAMPP) and cgi
Please note that I don't know much about web in python but I'm a bit used to NodeJS.
What would you recommend ?
Thanks, Victor
Personally I prefer gevent, bottle or Flask, and some front end framework like bootstrap or framework7.
Gevent easily makes it asynchronous and has websockets built right in, and bottle is the easiest (and fastest) way to build a web app or api.
Socket.io ist Very easy to send Data between Websites and scripts.
The Website Connect with the Socket.io Server and Inside the Server the Python Script can be executed

Can I run Python 2.7 Libraries (Impacket, Pcapy) on Django

Hi I just want to ask if its possible to run Impacket to Django,
On my project I am already done on my sniffing and parsing using Impacket and Pcapy but my clients requested that the GUI will be web based. I picked Django because its the most widely used and all but I am having doubts that it can run my Libraries.
For starters can Django open my NIC in Ubuntu and have access to sniff on it?
or is it better for me to use Flask for from what I read flask is being run on the Python Console Application, from what I understood I will install a HTTP Server in the Project then the Python Console will be like a Controller (MVC) to my GUI which is Flask.
You can run anything from Django, it just provides a framework to get stuff to the web.
As long as the Django application is running as a user which has privileges to access your NIC there won't be an issue with that.
You can simply call your code you already have from the Django Views.
The time this stuff takes may be too long for a web request so you may need to pass some stuff down a message queue and look up the results. Look at Celery for that purpose.
I do prefer Flask over Django but it doesn't matter what you use.
Just remember Django is another library it all still runs inside Python :)

How to develop a simple web application with server-side Python

I am wondering how to go about implementing a web application with Python.
For example, the html pages would link to python code that would give it increased functionality and allow it to write to a database.
Kind of like how Reddit does it.
If you're looking for server side programming with databases and html templates etc, I think Django is great, along with Pyramid. However, I use Flask ( http://flask.pocoo.org/ ) for this since it is easy to use, learn and deploy even though it may not have as much support as the before mentioned 2 framework since it's just a microframework, using the Jinja2 templating engine, including a development test server with it's own debugger.
On the other hand, if you're going for client-side programming (i.e. in browser implementation ) You can look up .NET Ironpython or even Brython which uses python like javascript.
You might want to check out mod_wsgi or mod_python.
What Is mod_wsgi?
The aim of mod_wsgi is to implement a simple to use
Apache module which can host any Python application which supports the
Python WSGI interface. The module would be suitable for use in hosting
high performance production web sites, as well as your average self
managed personal sites running on web hosting services.
-
Current State of Mod_Python
Currently mod_python is not under active development. This does not
mean that it is "dead" as some people have claimed. It smiply means
that the code and the project are mature enough when very little is
required to maintain it.
This is a good article from the Python website:
http://docs.python.org/howto/webservers.html
Plain CGI is a good starting point to learn about server side scripting, but it is an outdated technology and gets difficult to maintain after certain level of complexity. I would think it is no longer used in industrial-grade web server anymore. Plus you have to setup a web server and then install some module to interpret python script (like Apache with mod_python) just to get started.
I had some experience with Django (https://www.djangoproject.com/) and found it fairly easy to get started with since they come with development test server. All you need to have is a Python interpreter + Django and you can get up-and-running quickly and worry about the deployment setup later. They have pretty good documentation for beginner as well.
We have never used Python for a web site without a framework. In our case that is Django. In other words, we do not use Python for our web sites the way Perl can be used, just having Apache run a Perl script.
The recommendations you have received about Django are sound. If you go the Django route, Graham Dumpleton and the modwsgi Google group were very helpful to me. I could
not have gotten mod_wsgi deployed on Red Hat Enterprise 5 64-bit without Graham's help.
Whether you choose Django or "straight" Python, you will need to become familiar with mod_wsgi.
Good luck in quantum time, which means by now, I hope this all worked out for you.

Can I run Bottle.py on my Apache server without disrupting my PHP apps?

I'm antsy to get Python running on my webserver after just recently picking it up.
I chose Bottle.py because it looks simple, accessible, and contained. I have very little experience with or knowledge of how exactly webservers work (how to mess with them) and I'm reluctant to play with my server's Apache if I don't need to since it hosts a very active message board already.
Bottle's documentation seemed to assume a step or two of server/python understanding that I don't have, as I'm not even sure where to put the actual routes/website content once I already have bottle.py copied over to my doc root. Or how the server knows to run bottle (or execute python) when I go to "mydomain.com".
Run it in a WSGI container such as mod_wsgi.
You can also run Apace as a proxy to your application. I believe using mod_proxy would get you there. I myself run a nginx front end as reverse proxy to a bottle application running on bjoern. Bjoern itself is quite capable of running the bottle app, so I didn't want to use mod_wsgi, and similar stuff.

Simple python mvc framework

Is there any lightweight mvc webframework which is not necessary to install to the server?
I need something simple, that i could just copy to the shared hosting. And it must handle urls other that localhost/test.py, something like this localhost/Blog/test
You should probably check out Flask or Bottle, two nice Python microframeworks. With an appropriate "main" Python script (to initialize your app and dispatch requests to it) and mod_rewrite rules in place, you can probably get pretty close to your goal of "just copy[ing] to the shared hosting" with nice URLs.
Flask has good documentation on deploying via CGI, which is what you might have to use on your shared host. (If your host supports FastCGI or mod_wsgi, those deployment options would be preferable.)
Checkout web2py. Seems to be about the simplest python based webserver I can think of.
Django might do, it's hefty, but it comes with it's own development server.
web2py includes everything (ssl-enabled web server, sqlite sql based transaction safe database, web based Integrated Development Enviroment, web based database interface) in one package. The web2py binaries for windows and mac also include Python itself. web2py does not require configuration or installation and can run off a usb drive. It was originally developed as a teaching tool for MVC.
checkout https://github.com/salimane/bottle-mvc or https://github.com/salimane/flask-mvc . They are boilerplates that could get you started with controllers, models in separate folders. They are based on bottle and flask micro frameworks, no useless features, they give you the flexibility to plugin whatever modules you want.

Categories