views:

1218

answers:

8

I am planning on porting a PHP application over to Python. The application is mostly about data collection and processing. The main application runs as a stand alone command line application. There is a web interface to the application which is basically a very light weight reporting interface.

I did not use a framework in the PHP version, but being new to Python, I am wondering if it would be advantageous to use something like Django or at the very least Genshi. The caveat is I do not want my application distribution to be overwhelmed by the framework parts I would need to distribute with the application.

Is using only the cgi import in Python the best way to go in this circumstance? I would tend to think a framework is too much overhead, but perhaps I'm not thinking in a very "python" way about them. What suggestions do you have in this scenario?

+4  A: 

Depends on the size of the project. If you had only a few previous php-scripts which called your stand alone application then I'd probably go for a cgi-app.

If you have use for databases, url rewriting, templating, user management and such, then using a framework is a good idea.

And of course, before you port it, consider if it's worth it just to switch the language or if there are specific Python features you need.

Good luck!

kigurai
Thanks for the advice. Most of the framework concerns you listed are not really in the area I am concerned with, so thus is my quandary.
Crad
A: 

It depends on the way you are going to distribute your application.
If it will only be used internally, go for django. It's a joy to work with it. However, django really falls short at the distribution-task; django-applications are a pain to set up.

Alphager
Care to be abit more elaborate? Having set up two myself I fail to see what is so hard?
kigurai
mod_python rules. Works great for me.
S.Lott
I agree, I've used mod_python with trac and it was easy to setup.
Crad
+10  A: 

The command-line Python, IMO, definitely comes first. Get that to work, since that's the core of what you're doing.

The issue is that using a web framework's ORM from a command line application isn't obvious. Django provides specific instructions for using their ORM from a command-line app. Those are annoying at first, but I think they're a life-saver in the long run. I use it heavily for giant uploads of customer-supplied files.

Don't use bare CGI. It's not impossible, but too many things can go wrong, and they've all been solved by the frameworks. Why reinvent something? Just use someone else's code.

Frameworks involve learning, but no real "overhead". They're not slow. They're code you don't have to write or debug.

  1. Learn some Python.

  2. Do the Django tutorial.

  3. Start to build a web app.

    a. Start a Django project. Build a small application in that project.

    b. Build your new model using the Django ORM. Create a Django unit test for the model. Be sure that it works. You'll be able to use the default admin pages and do a lot of playing around. Just don't build the entire web site yet.

  4. Get your command-line app to work using Django ORM. Essentially, you have to finesse the settings file for this app to work nicely. See the settings/configuration section.

  5. Once you've got your command line and the default admin running, you can finish the web app.

Here's the golden rule of frameworks: It's code you don't have to write, debug or maintain. Use them.

S.Lott
In releasing my application, I then release it with a Django dependency but don't distribute Django, correct?I'm also concerned about making things too heavy with unneeded code in the command line app.I will look more closely at Django, thanks.
Crad
Django is a web application framework. You install it on a web server to use it. If you want to donate it into the public domain, you donate your application -- nothing else.
S.Lott
+2  A: 

I recently ported a PHP app to Python using web.py. As frameworks go it is extremely lightweight with minimal dependencies, and it tends to stay out of your way, so it might be the compromise you're looking for.

It all depends on your initial application though, because with a large application the advantages of having a full-featured framework handling the plumbing tend to outweigh the disadvantages involved in having to drag around all the framework code.

Big Dave Diode
Thanks for the heads up, I'll check it out.
Crad
+1  A: 

Django makes it possible to whip out a website rapidly, that's for sure. You don't need to be a Python master to use it, and since it's very pythonic in it's design, and there is not really any "magic" going on, it will help you learn Python along the way.

Start with the examples, check out some django screencasts from TwiD and you'll be on your way.

Start slow, tweaking the admin, and playing with it via shell is the way to start. Once you have a handle on the ORM and get how things work, start building the real stuff!

The framework isn't going to cause any performance problems, like S. Lott said, it's code you don't have to maintain, and that's the best kind.

camflan
Yeah my main concern is Django is too much framework for my needs. 90% of the application lies out of the web layer. I'm concerned Django is overkill. Thanks for the heads up on how to get started with it, I definitely want to get to know it, even if not for this project.
Crad
+9  A: 

You might consider using something like web.py which would be easy to distribute (since it's small) and it would also be easy to adapt your other tools to it since it doesn't require you to submit to the framework so much like Django does.

Be forewarned, however, it's not the most loved framework in the Python community, but it might be just the thing for you. You might also check out web2py, but I know less about that.

Andrew Gwozdziewycz
Thanks! I appreciate the heads up.
Crad
+1  A: 

Go for a framework. Basic stuffs like session handling are a nightmare if you don't use a one because Python is not web specialized like PHP.

If you think django is too much, you can try a lighter one like the very small but still handy web.py.

e-satis
A: 

For the love of pete, use a framework! There are literally dozens of frameworks out there, from cherrypy to django to albatross to ... well.. you name it. In fact, the huge number of web frameworks are what people point to when they whine about the popularity of Rails.

The Python web development community is divided up with no single voice. But that's another topic alltogether! The point is, there are "web toolkits" (e.g. albatross) that are fairly lightweight but powerful enough to get you through the day (e.g. auto-verifying a bot didn't do a simple form submission fake, or helping with keeping MVC clean).

If you want something that's not "too much framework" look here:

http://wiki.python.org/moin/WebFrameworks

Look under "Basic Frameworks Providing Templating". They're all lightweight and do all the "don't reinvent the wheel" stuff without forcing a Mac truck on you.

Gabriel