Get Started with the Patterns CLI Devkit
The Patterns Devkit lets you build and run your apps directly from the command line. You
can use the Patterns Devkit to download and edit Apps, run your
Apps, and use git
or other version control for your Apps' code.
Installation
To install the Patterns Devkit, make sure you have Python 3.8 or newer.
Then, run the following command to install the devkit:
pip install patterns-devkit
Now you can check that the devkit is installed successfully with this command:
patterns
Updating
You can check that you have the latest version of the devkit installed:
patterns --version
And you can update your installation:
pip install --upgrade patterns-devkit
Authentication
The Devkit uses OAuth to authenticate with Patterns. Run the following command to authenticate from the CLI:
patterns login
This command will open a browser window asking you to log in to Patterns and grant the Devkit access.
Once authorized, the Devkit stores your auth token in the following location, depending on your OS:
- Linux:
~/.config/patterns/config.json
- macOS:
~/Library/Preferences/patterns/config.json
- Windows:
%APPDATA%/patterns/config.json
You can also run the following command to see the location on your device:
patterns config
Downloading an App
You can use the Devkit download the source code for any Apps in your organization.
Get the App Slug
The devkit uses App slugs to identify apps. You can see all your Apps and their slugs with this command:
patterns list apps
Download the App
To download the App, run the following command, replacing my-app
with your App's slug:
patterns download my-app
This command will create a new directory with the same name as your App slug containing all the code for your app.
Download new versions of an App
Once you've downloaded an app, if you make any changes from another device or in the Studio UI, you can fetch the latest version by running the following command from the app directory:
patterns download
The download
command won't overwrite any files by default. If there are changes, add
the --diff
flag to show a detailed diff:
patterns download --diff
To overwrite your local files with the changes, add the --force
flag:
patterns download --force
Editing an App locally
An App's structure is defined by a graph.yml
file, but you don't need to edit this
file manually to add a node to your app. You can add nodes with the Devkit by running
the create node
command from an App's downloaded source directory.
Adding a Python node
To add a Python or SQL node, you need to specify the source file to create:
patterns create node --name='Process data' process_data.py
Adding an SQL node
patterns create node --name='Process data' process_data.sql
Adding a webhook node
For webhooks, specify the name of the table that the webhook will write to:
patterns create node --type=webhook --name='Ingest data' webhook_data
Adding a component node
You can add a Marketplace component by specifying its name and version:
patterns create node --type=component --name='Import data' patterns/some-component@v1
Uploading an App
After you make changes to and app you've downloaded, you can upload the new version of the App with the following command from the App's directory:
patterns upload
Like the download
command, this won't overwrite any files by default. You can see
a full diff of changes:
patterns upload --diff
Or force the upload to complete:
patterns upload --force
Running an App
You can trigger the run of a node in your App by specifying the node's file:
patterns trigger my_node.py
Or with the App slug and node id:
patterns trigger --app=my-app --node-id=a1b2c3
Using the Devkit with Git source control
All Patterns apps are fully defined by code. Once you've downloaded an app, you can check it in to the source control of your choice.
The devkit has built-in support for Git. As long as you have git
installed, the
upload
command will skip the .git
directory and any files or directories
excluded by .gitignore
.
Getting Help
To get usage details and info on the other commands available in the Devkit, pass
--help
to any command or subcommand:
patterns --help
patterns create node --help
If you encounter any trouble using the Devkit, you can create in the Devkit's GitHub repo, or chat with us on Slack