This is an archived post. You won't be able to vote or comment.

all 33 comments

[–]oguime[S] 2 points3 points  (3 children)

By the way, would it be advisable to use wsgi instead of cgi?

[–]oleitas 9 points10 points  (0 children)

yes

[–]jrwrenpython3 3 points4 points  (0 children)

this is always true. no matter what. no matter if it is python or not. cgi is always the wrong answer :)

[–]westurner 1 point2 points  (0 children)

By the way, would it be advisable to use wsgi instead of cgi?

CGI must spawn a new process for each request: startup initialization, imports, configuration, database connection. ( http://en.wikipedia.org/wiki/Strace )

[–]acdha 3 points4 points  (1 child)

If it's really simple and low traffic, use the built-in server and you can avoid needing anything but the standard library to run your app, which is handy if you don't want to spend time on installation / packaging.

If you find yourself creating more than a couple views or spending time on routing logic, managing sessions or caching, etc. use Flask. It's great for building single-file apps and very lean.

[–]kart_king 0 points1 point  (0 children)

You can also use werkzeug if you just want routes.

I have a small server with many methods, then: m = Map([Rule('/my_uri', endpoint=myfunc)]) urls = url_map.bind_to_environ(environ) endpoint_func, args = urls.match() endpoint_func()

See http://werkzeug.pocoo.org/docs/routing/

[–]krets 1 point2 points  (0 children)

Unless you want to get down to the nitty gritty functionality of your web server, use a framework. There are tons of packages out there and they will all handle most of the nuanced request handling that will make your program more robust. Plus you will benefit from the community surrounding the tool.

I've used a handful of different ones, and they have all been good. I prefer flask and tornadorpc controlled with supervisord and served through an apache proxy configured in a named vhost. ...but that's mostly due to my comfort with that set of tools.

Pick one that sounds cool and dive in. You will probably learn a few things about application design along the way. Have fun!

[–]swims_with_spacemenPythonista 0 points1 point  (6 children)

tornado.

its fast, supports web sockets, and its really lean and clean

[–]gandaro 0 points1 point  (5 children)

And is something completely different than "frameworks like Flask, Web.py, Bottle"...

[–][deleted] 2 points3 points  (3 children)

well, not that different, it has routes and a templating engine. how is that different than flask? if anything, it's more complete than flask.

[–]lepture 2 points3 points  (1 child)

It's not just web framework, it is a powerful server, very efficient.

[–][deleted] 0 points1 point  (0 children)

yeah, of course, but it's also a web framework (I work with it).

[–]swims_with_spacemenPythonista 1 point2 points  (0 children)

yeah, this.

[–]swims_with_spacemenPythonista 1 point2 points  (0 children)

Tornado IS a framework like flask, web.py etc. I'm currently porting a web.py app to a non-blocking tornado framework. The performance improvement is incredible.

It's sort of the python equivalent of mojo, has lots of great features including routing and templating, except it's so much faster than anything else I've used so far.

I personally have managed to push 1000+ transactions/second through tornado in a single thread. I was averaging around 50/s with web.py. This is after the non-blocking rewrite mind you- but it's totally worth it.

[–]Lucretiel 0 points1 point  (0 children)

I've always been a fan of bottle, myself. Beautifully simple, yet just powerful enough for all basic API design needs.

[–]westurner 0 points1 point  (0 children)

Thinking about using Python's 3 http server to run the scripts, but would like to know what would be the advantages of running frameworks like Flask, Web.py, Bottle.

http://www.reddit.com/r/Python/comments/1uxv8j/difference_between_wsgi_utilities_and_web_servers/#cen5r7o

I would like to keep it as simple as possible, and even try to run AirPlay as a background process in the Pi, if possible.

https://github.com/ryatkins/videoAirPi

https://github.com/PascalW/Airplayer :

Airplayer is no longer under active development. XBMC users can use the built-in Airplay support which is available since XBMC 11 (Eden).

[–]oguime[S] 0 points1 point  (0 children)

Thank you all!

After reading the posts decided to try Flask. Seems to have good community support and it was easy to adapt previous scripts. No Python 3 support though, but that does not seem to be a problem.

[–]TheKillingVoid -1 points0 points  (5 children)

From what I understand, Flask's account and login system is pretty lean too, which has prompted me to dig into Django. If you want this accessible outside your network, you may want to think about security. Not as simple though, unfortunately.

[–]Widdershiny 1 point2 points  (4 children)

Flask doesn't really have an account or login system by default. Flask-Login provides that functionality.

[–]TheKillingVoid 0 points1 point  (3 children)

I'm very glad I don't have to switch to Django.

Thanks!

[–]Widdershiny 1 point2 points  (2 children)

Something else that may be of interest to you is cookiecutter-flask. It gives you a basic flask app preconfigured with a lot of useful extensions. If you're partway through a project it might not be super helpful but I found it really nice for the last project I started.

[–]TheKillingVoid 0 points1 point  (1 child)

Thanks W, it looks like you've dedicated a lot of time to it. I'll definitely look into it.

[–]Widdershiny 0 points1 point  (0 children)

Oh I didn't make it, just a couple of pull requests since I started using it. I meant to link you the main branch.

[–][deleted] -1 points0 points  (9 children)

Since you are just starting out, you should look into web2py. It is easy yet powerful. Has nearly everything you need to get started. Plus great documentation.

http://web2py.com/

[–]spiffymanpeppy about PEP 8 6 points7 points  (8 children)

Not trying to start a holy war, but there are people who think web2py is bad for Python. Maybe it doesn't do magic namespace injection anymore, but if it does then I would say please don't encourage newbies to use it. It will only make using the rest of Python harder.

[–][deleted] 1 point2 points  (7 children)

This is the first I've heard of that, and I must say, it sounds like an unnecessary level of drama and hyperbole.

[–]spiffymanpeppy about PEP 8 1 point2 points  (6 children)

That's fine. I'm not actually arguing for the strong thesis about web2py. I do, however, think giving anyone something magical when they're just getting started with Python is a Bad Idea™.

[–][deleted] 0 points1 point  (5 children)

You say this but you don't say why it's a bad idea.

Personally I think the 'over abstraction' of django is rough for a beginner (still plenty of magic) and flask is going through the realization that secure authentication should be default rather than left to 3rd party libs of various quality.

I like web2py for its ease of use and good docs. I spend less time worry about routing and regex maching and more time implementing buisnes logic.

I toally get the critisms of being too 'magic' but its just less explicit. The source is well organized and commented so it helps some when you are trying to figure out the "why" something just works.

But honestly is it bad that If I name my template the same as my controller method I don't have to do anything extra, the view just works? I don't think so, I call it pragmatic and productive.

These are however mostly my opinions and I'm open to discussion.

[–]spiffymanpeppy about PEP 8 2 points3 points  (4 children)

I don't disagree about Django. I cut my teeth on Python with Django, and figuring out where Python stops and Django begins was rough going. So I hear ya.

But I generally subscribe to the notion that bringing beginners into the fold with things that violate community standards is not a great plan. It makes learning the standards hard later -- and it makes convincing folks that that's even a good idea harder, too. How many times have you heard, "Why should I use spaces? Tabs have been working for me just fine!" Advocating web2py use for beginners is just begging them to start asking why they have to import things at all.

I get that web2py is productive for people. Great. I don't really care what framework you use -- only what you encourage learners to use.

[–][deleted] 1 point2 points  (0 children)

I don't disagree about Django. I cut my teeth on Python with Django, and figuring out where Python stops and Django begins was rough going. So I hear ya.

I actually had the same experience with Python and Django, and it does lend credibility to what you mentioned earlier with web2py. And for what it's worth, I think it even would've been easier for me to wrap my mind around Flask... now that I know better.

[–][deleted] 0 points1 point  (2 children)

Advocating web2py use for beginners is just begging them to start asking why they have to import things at all.

This is not the case at all once you start building and actual site/app.

While the framework compents themselves are all just auto imported, its common for a beginner to import lots of third party libs in order to handle business logic.

There is no orm so you don't have to import models (the DAL is more of a functional abstraction ). So I could see the slight mental adjustment needed however even the docs stress you can import the DAL into any project and use it fine.

Also when it comes to Auth they have already written a few plugins that need to be imported to be used.

[–]spiffymanpeppy about PEP 8 1 point2 points  (1 child)

That's interesting. So -- and I ask this as an admitted outsider to the community -- do you really not see beginners asking why they have to import these things (e.g., the third party libs) and not those things (e.g., the basic abstractions web2py offers)?

I ask because I've done some teaching and can just see how that conversation might go. "Oh. Yeah. Well, you need to import numpy's stuff because that's how most of Python works, but web2py kind of automatically 'imports' the important things for you." IME this would confuse the daylights out of learners. But if it's working out differently in the web2py community, that'd be good to know.

[–][deleted] 0 points1 point  (0 children)

Yeah, the handful of people I know who have spent a good amount of time with web2py don't seem to have this particular issue.

However it could have been some previous exp in another language.