The Blocks CLI is the primary interface for registering automations.

To get started, install the Blocks PyPI package:

pip install blocks-sdk

Once installed, you’ll need to initialize Blocks. To do this, you’ll need a valid API key which you can obtain from the Blocks dashboard.

blocks init --key <api-key>

This will create a .blocks directory in your current working directory. All automation source code needs to be placed there.

Once initialized, the easiest way to create an automation is to use the create command.

blocks create hello_world

This will create a new automation in the .blocks directory with the following structure:

.blocks/
    hello_world/
        main.py
        requirements.txt

Add a README.md to your automation folder to provide a description of the automation, which will display in the dashboard.

If you need to change your API key at any point, you can use the configure command.

blocks configure --key <api-key>

Once you have an automation you’d like to register, you can use the push command to register it. You’ll need to specify the path to the file relative to your current working directory.

For the above folder hello_world automation, you’d run:

blocks push .blocks/hello_world/main.py

This may take a few minutes to complete the first time it is run, as we need to build a runtime for your automation. Subsequent pushes will not rebuild your automation’s runtime unless pip or plugin dependencies have changed. Additionally, subsequent pushes for a registered automation will create a new revision or version of your automation.

Changing the name in the task decorator will create a new automation.