Contact Us
24/7
Python BlogDjango BlogSearch for Kubernetes Big DataSearch for Kubernetes AWS BlogCloud Services

Blog

<< ALL BLOG POSTS

Building Python Command Line Tools, Part 2: Console Scripts

|
February 9, 2015

Over the past few months 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 = """\
  [paste.app_factory]
  main = myapp:main

  [console_scripts]
  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.

RELATED POSTS:

Was this article useful? Be sure to stay tuned for the next installment and sign up for our Python How-To digests to receive more how-to guides as soon as they are published!

How can we assist you in reaching your objectives?
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.