<< All Blog Posts
Building Python Command Line Tools, Part 2: console_scripts

Building Python Command Line Tools, Part 2: console_scripts


python command line header-590px

Over the past few months here at Six Feet Up I have noticed an increasing need to demonstrate the usefulness and efficiency of Python command line tools. Command line tools can be very handy, and, making your own using Python is easier than you might think! The information in this article is part two of our series on building a command line app and will show you how to execute and install console_scripts. Did you miss part one on getting started with Command Line Tools? Read it here.

How Do You Hook This Up to Make an Executable Script in My Pyramid or Django App?

Now that you can read in arguments from the command line using argparse, how do you try it out and actually get the command line tool generated so you can run it?

How to Make a Console Script for your utility

Ok, now that you have read in the arguments to our script, you need to make sure that a script is created when someone installs our product. The setup.py handles this for you by defining a [console_scripts] entry points section like this:

entry_points = """\
  main = myapp:main

  import_sessions = myapp.scripts:import_sessions

This allows your python function to be registered as a command line tool. With that in place, you will have a script called import_sessions installed into your environment and ready for you to load data with once you have fleshed out the rest of the script.

Next Steps

In the next post in this series, we will put some meat into our script that will actually interact with our Pyramid application. We will show bootstrapping the app so we have the full environment ready to use with the database.

Thanks for filling out the form! A Six Feet Up representative will be in contact with you soon.

Have a question? Want to connect with us?