Part 1: Creating Your First Project
Introduction
Throughout this tutorial we will be building a task management application called todo
. We will begin with a barebones template using the cement generate
tool, and build up from there to cover as much of the core features of the framework as possible.
Our application will include the following features:
Ability to create, update, and delete task items
List and display tasks via Jinja2 templates
Persist data using TinyDB
Send an email message when tasks are complete
A video walk-thru of the tutorial is also available.
Generating a New Project Repository
Cement includes a developer utility called cement
that includes tools to make our lives easier. This was introduced in Cement 3, and will continue to grow as feature requests are made for new and improved ways of streamlining the development process.
Create a new project with the following command and parameters:
Exploring The TODO Project
The following covers the primary components included with your new project. First, take a look at the generated directory:
This looks like a lot, however there is a lot of placeholders here for best practice or recommended design. Keep in mind, a Cement application can be as simple as a single file script... however we know that our TODO application will be disrupting the industry of task management, therefore we want to start things on the right track.
Let's break this down into more manageable pieces:
Common Project Files
These files should look familiar as they are common in most projects. The README.md
is populated with some starter info to help get more familiar with the layout and navigation of the project. You should read the README.md
now.
Common Python Packaging Files
These files should look familiar to anyone who has packaged and distributed a Python project before, and are required for proper installation, setup, and distribution. Note that the requirements.txt
lists dependencies that are strictly required for deployment (production), where the additional requirements-dev.txt
includes additional dependencies that are only required for development (running tests, building documentation, etc).
Miscellaneous Development Files
The included Dockerfile
gives you a working Docker image out-of-the box, while the Makefile
includes several helpers for common development tasks such as creating a virtualenv, running tests, building docker, etc.
Default Configuration, Documentation, and Tests
A good application has excellent documentation and testing, along with example configuration files of the applications settings (and their defaults). As configuration defaults are added (or modified) in the application, the config/todo.yml.example
should be updated to reflect them.
Our Application Module
Finally, our code lives in a python module called todo
, with what should be an obvious breakdown of submodules that clearly separate code into relevant and organized buckets. Take a moment to briefly review all of the files provided in the generated project repository.
Again, note that a Cement project does not need to be organized this way but is a solid starting point to streamline development. If you aren't entirely happy with the layout and organization of the generated projects you can always create your own templates to start from.
Setting up Our Development Environment
Our generated project includes a Makefile
with several helpers to streamline the development process. You can use these helpers, add your own, or do away with it and follow any other development process you are more familiar with.
First we will setup our VirtualENV:
This runs common commands to create our virtual environment in ./env/
, and then runs pip
to install our dependencies. We activate the environment, and are ready to run our TODO application:
Look at that! Let's play around with some of the pre-built features:
Conclusion
And that completes Part 1. In the next section we will add the functionality of managing task items, storing data in a database, and sending email messages when completing tasks.
Last updated