Python command line application and frameworks

I am going to write a rather complicated command line application in python. I would like to use something other than pure python, maybe a framework or something that facilitates the management of services and code in the application. In my opinion, I think of MVC, since the application will have several different commands (controllers) that call different data sources (JSON requests, REST requests, etc., for example, โ€œModelsโ€ in MVC), and then display results in different formats (view).

I think MVC works well for this, but I really am not building a web application. I want something that does not necessarily require a web server, but has the advantages of a structure to force some coding standards.

Does anyone have any tips or suggestions? I know that with Python I could have something from scratch from scratch, but I'm just wondering if there is anything else that I could use.

Thanks Dustin

+6
source share
2 answers

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

Cement is an advanced CLI application platform for Python. Getting started is easy, and it is extremely flexible to configure almost all of its parts when entering the parsing of a configuration file. Cement2 (codename portland) is currently in beta, but is very close to a stable release:

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

Also, if you are creating a REST command line client, also check dRest:

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

Itโ€™s also very easy to get started with this, as well as extremely flexible for configuring from the request handler how serialization occurs at both the sending and receiving ends.

I will be happy to answer any questions.

+20
source

To be fair with respect to the pattern, MVC is not tied to web applications. I think due to trends in Internet support over the past couple of years, this link between MVC and web applications could increase. In other words, a web application can use MVC, but using MVC does not necessarily mean that you have a web application.

If you want to use the framework, you can try to use the one closest to your intended controller. I am not aware of MVC structures with a command line as an interface, but some platforms with an independent GUI platform that use it, like GTK + or QT : both have python bindings.

From a personal point of view, I used to use Django . Although technical cleanliness may be the subject of discussion, when choosing a structure, no one forces you to use all the infrastructure components. Django has a good ORM that I liked so much that I made it the basis for the SSH interface. This may be redundant, but there was an advantage for me that I could reuse my knowledge of the system instead of learning a new, once-used infrastructure.

In conclusion, it all comes down to discipline. Even the best frames cannot stop you from breaking coding standards and cutting corners ...

PS, if you are running Linux, you can use the python curses module for the command line interface.

0
source

Source: https://habr.com/ru/post/899156/


All Articles