开发者

command line python app and frameworks

开发者 https://www.devze.com 2023-04-12 08:47 出处:网络
I\'m going to be writing a fairly sophisticated command line app in python.I\'d like to leverage something other than just pure python, maybe a framework or something that makes the services and code

I'm going to be writing a fairly sophisticated command line app in python. I'd like to leverage something other than just pure python, maybe a framework or something that makes the services and code management within the app easier. I gue开发者_StackOverflow社区ss in my mind, I'm thinking MVC, as the app will have several different commands (controllers) which call different sources for data (JSON requests, REST requests, etc., e.g. the "Models" in MVC), and then display results in different formats (the View).

I think MVC works well for this, but I'm not really doing a web app. I want something that doesn't necessarily require a web server, but has the advantages of a framework to force some coding standards.

Does anyone have any tips or suggestions? I know I could build something from scratch with Python, but I'm just curious if there's something else out there I could utilize.

Thanks, Dustin


This is a bit late, however posting for anyone else who stumbles across this:

Cement is an Advanced CLI Application Framework for Python. Getting started is easy, and it is extremely flexible for customizing almost every piece of it from logging to config file parsing. Cement2 (code name portland) is currently in beta, but is very close to a stable release:

http://cement.readthedocs.org/en/portland/

Additionally, if you are creating a REST command line client, also checkout dRest:

http://drest.readthedocs.org/en/latest/

It too is very easy to get started with, and is also extremely flexible for customization from the request handler, to how serialization happens on both the sending and receiving ends.

I'd be happy to answer any questions about either.


To be fair to the pattern, MVC is not bound to web applications. I think because of the web-aware trend of the last couple of years this relation between MVC and web apps could have grown. Put differently, a web app can use MVC, but using MVC doesn't necessarily mean that you have a web app.

If you want to use a framework, you could try to use the one most close to your intended controller. I'm not aware of an MVC frameworks that have a command line as the interface, but some platform independent GUI frameworks that use it are for example GTK+ or QT: both have python bindings.

From a personal point of view, I've used Django for this purpose before. Although the technical purity can be a point of discussion, when selecting a framework no one forces you to use all of the framework's components. Django has a nice ORM which I've liked so much that I made it the backend for a SSH operated interface. It might be overkill, but for me had the advantage that I could reuse my knowledge about the system instead of learning a new, once-to-be-used framework.

In conclusion, it all boils down to discipline. Even the best framework cannot prevent you from violating coding standards and cutting corners...

PS if you're on Linux, you might consider using python's curses module for your command line frontend.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号