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?
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.
Learn some Python.
Do the Django tutorial.
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.
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.
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.