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.
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?
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.
csv
module and shows you how to watch out for datetime
timezone issues.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!