-
-
Notifications
You must be signed in to change notification settings - Fork 4
Tutorial: Part One
Let's build something with Pyttman. In this quick start tutorial, we're building a digital assistant helping us checking the weather forecast for different locations.
If you haven't already, start a project in your favourite editor/IDE and make sure Pyttman is installed in a virtual environment. Feel free to checkout the installation guide here.
After installing Pyttman you have access to use our CLI tool pyttman
globally in your terminal by simply running pyttman
.
As of Pyttman 1.1.8, it supports 3 commands:
new app
dev <app name>
runclient <app name>
For now, we'll focus on the new app
command.
To create a new app using the built-in template project, in your terminal, run:
pyttman new app pyttman_tutorial
This sets up a project directory for you with the files you need to get going. The app catalog is named pyttman_tutorial
in this case.
The directory created by pyttman
contains a few files;
/my_app:
__init__.py
settings.py
/abilities:
clockability.py
/logs:
<empty>
/tests:
__init__.py
test_intents.py
The settings file alter the behaviour of Pyttman for your app scope.
There are many ways to tweak the behaviour of Pyttman, and all are done inside this file. Advanced users can choose very finely how their app is run, and basic users can rely on the default settings for the most part.
For now, leave it be.
This directory is a suggestive structure of how to create abilities in your application. Abilities are just like human abilities; the ability to do math, or the ability to translate languages; maybe just the ability to tell what time it is.
Pyttman apps are structured the same way. Think of it as a bucket of skills related to one and the same ability.
In these files, we're going to develop our Intent
classes, which house the logic which does the actual work in our app.
Think of them like API View classes in MVC frameworks.
Log files will be created by Pyttman in this directory. To log something in our application, we're going to use the
built in logger decorator in Pyttman: @pyttman.logger.loggedmethod
.
It's important to develop tests for our app. In this directory, we can develop unit and integration tests as we proceed.
When we created our app template, Pyttman included an Ability for us to try out the tech without a single line of code.
If you check under the /abilities
directory, you see that there's a file called clockability.py
. This ability is
our version of Hello, World! and simply enables your first Pyttman app to tell you what time it is, while also allowing
you to change the format of the date time, demonstrating Pyttman's powerful EntityParser API at a glance. It also touches
upon the Storage
api built in to Pyttman.
Let's get accustomed to the pyttman
CLI tool and try out the ability.
Assuming you named your app according to this tutorial, In your terminal, run:
pyttman dev pyttman_tutorial
What a buzzkill, we get straight in to errors and problems. You probably got this message in your terminal:
errors occurred:
AssertionError: No Ability classes were provided the ABILITIES list in settings.py
What does this mean?
Pyttman is modular, which means you explicitly have to tell it which Ability classes you want to be loaded when you run your app.
As stated above; "you explicitly have to tell it which Ability classes you want to be loaded when you run your app." - Lets' do that, by opening the settings.py
file.
Add an ability in settings.py
Now, scroll down to the setting ABILITIES
. This is a list, and right now it's empty, which is why you got that error before.
If you read the instructions above it, you'll quickly copy-and-paste the import reference to the ClockAbility
class. If you're not using PyCharm and can't perform such magic; fear not. Simply start at the app directory and replace / \
with .
Example with file system and class name
pyttman_tutorial/abilities/clockability.py/ClockAbility
becomes pyttman_tutorial.abilities.clockability.ClockAbility
We only have this ability for now.
Now, try running your app again
In your terminal, run:
pyttman dev pyttman_tutorial
You should now have a working Pyttman up and running, congratulations! In the next part, we'll explore more how things work by poking around in the app. You can find part two here.
Welcome to the Pyttman Wiki! Here you'll find all available documentation and tutorials for Pyttman.
Get started
Documentation
Contributors