Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suggestion on finding a Python web-framework that supports py3k?

Since one month ago I started learning Python, and I find the language simple and useful.

I'm a web developer but I only have experience with PHP, I have used frameworks like CakePHP or Zend. I am familiar with Django which is the most popular one. However, Django is not compatible with Python 3.

Does anybody know a Python web framework that supports Python 3? Should I consider using pure Python, without frameworks ? If is good idea, which webserver should I use? Nginx with reverse proxy like uwsgi or Gunicorn, why?

like image 670
Gonzalo Bahamondez Avatar asked Jan 18 '26 05:01

Gonzalo Bahamondez


1 Answers

The latest stable release of Django is 1.5 and it does support Python 3. Please read the public announcement: https://docs.djangoproject.com/en/dev/topics/python3/

Django 1.5 is first version of Django that supports Python 3 so you can expect more bugs than previous versions which have been pretty solid with Python 2 support. But Django core team is very serious about merging patches from the community so it shouldn't be too big a deal.

In general you have three more really famous Python web-frameworks: Flask, Bottle and Pyramid. The first two are targeted at minimalist. Bottle is just a single Python file. I can safely say Bottle is just a wrapper on top of WSGI server by adding the routing functionality. That's pretty much it. Use Bottle if you want the least feature and build everything up from scratch. That's usually ideal for very lightweight API web service.

Flask is the new famous dude standing out. It's heavier than Bottle but still very minimalist. Pyramid is usually the direct competitor to Django. Pyramid does not have ORM or hard-integrated template engine. By default, you can use Mako or Chameleon to build the front-end templates. Without ORM means you are not restricted to just relational databases. Django's ORM is object-relational Mapper so it binds to a relational DB like MySQL, PostgreSQL or MariaDB or other RDMBs. If you want to use MongoDB which is a non-relational (NoSQL) then you are pretty much screw. You can't benefit from using Django's ORM. Pyramid allows you to use SQLAlchemy or other ODM (object-document mapper for NoSQL) instead of a hard-integrated ORM in Django.

The problem using Python 3 with any Python web-framework at this point is that most of the Python web-framework ecosystem (be it Django's ecosystem, Flask's, Pyramid's) are not compatible with Python 3. Many of the most popular Django apps do not claim to support Python 3 so you will be out of luck if you want to use these apps to build your Django website.

But with 1.5 I think the ecosystem will move to Python 3 compatible support rapidly. If you are familiar with Python enough, look at Flask or Pyramid. I like Pyramid because it comes with Auth policy that you can adaopt. We have been using Pyramid to build our web api service. Django is good if you build a front-end. I will still leave my API webservice in Pyramid or Flask.

In general, you should avoid Apache + mod_wsgi. Most people do not know how to tweak Apache to run efficiently. Nginx by default will give you high throughput and efficient worker CPU-memory consumption. Yes. I recommend using Gunicorn.

What do you mean pure Python? All the web frameworks are built with Python. Well I can get in a bit details that the Python most people use is called CPython. There are other implementations of Python. An implementation of Python language can be in C, C++, Java, Ruby, .NET or even PHP. CPython is C. To confuse you a little, there is an implementation of the Python programming language "PyPy" which implements Python language in Python.

Okay. Let me finish the point: that's probably not what you are referring to. If you want to build a web-framework yourself, that's fine. You just need to understand how WSGI work, have a regex middleware dispatching requests based on URL to a view function and you are done. That's really all modern Python web-framework needs. I have written a dummy one (a horrible one though) last semester.

like image 167
CppLearner Avatar answered Jan 19 '26 19:01

CppLearner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!