Skip to content

A small Python CLI example that you can use to build on

License

Notifications You must be signed in to change notification settings

craigell/python-cli-example

 
 

Repository files navigation

Coursera Course

Python CLI Example

A small Python CLI example you can use to build on. With an emphasis on Linux and creating automation tools that solve a problem for you. THis is the basis for DevOps principles that you can apply in your own environment as well as production environments.

💡 Are you just looking for a 👉 Rust template to get started easily with a Rust project? The template has everything you need!

This repository is part of the Python and Rust CLI tools course:

Practice Lab

Use the included practice lab to apply the content you've learned in this week. Follow the steps to create your own repository and apply the requirements to complete the lab.

Setting up the environment

Python development will require you to have Python installed on your system. For Linux systems, you should prefer the Python that comes available through the package manager. For example, on Ubuntu, you can install Python with the following command:

sudo apt-get update && sudo apt-get install python3

The update part is required if this is a fresh install of the system. Any Python version above 3.6 should work well for this repository, its examples, and most of the work shown in the video course.

The course uses Visual Studio Code exclusively, but you can use any other text editor as well.

These are all the tools and editor extensions recommended for Python development:

Working with Modules

Adding modules (Python files) is as easy as adding more files. But you can also add a directory and add an __init__.py file to it. This will allow you to import the modules from the directory as if they were part of the same file. There are some caveats and things to keep in mind when working with modules, and what strategies you can use to make your code more maintainable and easier to understand for you as well as other developers.

  1. Use the ceph-volume command-line tool as an example to explore module organizing
  2. Add imports to __init__.py as a shorthand for making modules available, but be aware of side effects
  3. Use relative imports to avoid circular imports and understand absolute

Dependencies and libraries

Using dependencies can be tricky, but you can use the well known requirements.txt file to keep track of the dependencies for your projects which is something that works with the pip installer tool. Here are some things to be aware of when working with dependencies:

  1. Create a requirements.txt file, optionally read it in for the setup.py file
  2. Use separate files for development and testing like dev-requirements.txt and test-requirements.txt when needed
  3. Use pip to install dependencies and use pip freeze to pin dependencies. Be aware of the caveats and positive aspects of pinning.
  4. Understand how relaxed dependencies can be instead of pinning

Resources

Explore additional content that you can use to learn more about the topics covered in this course.

Coursera Courses

O'Reilly Courses and Books

About

A small Python CLI example that you can use to build on

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 68.6%
  • Dockerfile 31.4%