Upload a module to the Viam Registry

After writing a module, you can upload your module to the Viam Registry to:

  • share your module with other Viam users
  • deploy your module to a fleet of machines from a central interface

You can choose to upload it to the Viam Registry as a public module that is shared with other Viam users, or as a private module that is shared only within your organization.

To upload your custom module to the Viam Registry, either as a public or private module, use the Viam CLI commands create and upload following these instructions.

Prerequisites

A local module you've written and tested

Upload a module

1. Install the CLI

First, install the Viam CLI and authenticate to Viam, from the same machine that you intend to upload your module from.

To download the Viam CLI on a macOS computer, install brew and run the following commands:

brew tap viamrobotics/brews
brew install viam

To download the Viam CLI on a Linux computer with the aarch64 architecture, run the following commands:

sudo curl -o /usr/local/bin/viam https://storage.googleapis.com/packages.viam.com/apps/viam-cli/viam-cli-stable-linux-arm64
sudo chmod a+rx /usr/local/bin/viam

To download the Viam CLI on a Linux computer with the amd64 (Intel x86_64) architecture, run the following commands:

sudo curl -o /usr/local/bin/viam https://storage.googleapis.com/packages.viam.com/apps/viam-cli/viam-cli-stable-linux-amd64
sudo chmod a+rx /usr/local/bin/viam

You can also install the Viam CLI using brew on Linux amd64 (Intel x86_64):

brew tap viamrobotics/brews
brew install viam

If you have Go installed, you can build the Viam CLI directly from source using the go install command:

go install go.viam.com/rdk/cli/viam@latest

To confirm viam is installed and ready to use, issue the viam command from your terminal. If you see help instructions, everything is correctly installed. If you do not see help instructions, add your local go/bin/* directory to your PATH variable. If you use bash as your shell, you can use the following command:

echo 'export PATH="$HOME/go/bin:$PATH"' >> ~/.bashrc

For more information see install the Viam CLI.

Authenticate your CLI session with Viam using one of the following options:

viam login

This will open a new browser window with a prompt to start the authentication process. If a browser window does not open, the CLI will present a URL for you to manually open in your browser. Follow the instructions to complete the authentication process.

Use your organization, location, or machine part API key and corresponding API key ID in the following command:

viam login api-key --key-id <api-key-id> --key <organization-api-key-secret>

2. Generate a metadata file

Next, run the viam module create command to choose a custom module name and generate the required metadata for your module. By default, a new module is created as private, meaning that it is only accessible to members of your organization, but you can choose to set the visibility of your module to public to make it accessible to all Viam users.

Select the private or public tab for instructions to upload your module with the respective visibility setting:

Get the org-id for your organization from your organization’s Settings page in the Viam app and run the following command from the same directory as your custom module to generate metadata for your module:

viam module create --name <your-module-name> --org-id <your-org-id>

If you later wish to make your module public, you can use the viam module update command.

  1. If you haven’t already, create a new namespace for your organization. If you have already created a namespace, you can find it on your organization’s Settings page in the Viam app, or by running the viam organizations list command.

  2. To generate metadata for your module using your public namespace, run the following command from the same directory as your custom module:

    viam module create --name <your-module-name> --public-namespace <your-unique-namespace>
    

This command creates a new meta.json metadata file in your current working directory, which serves as a template.

3. Edit the metadata file

Edit the newly-created meta.json file, and provide the required configuration information for your custom module by filling in the following fields.

NameTypeInclusionDescription
module_idstringRequiredThe module ID, which includes either the module namespace or organization ID, followed by its name (pre-populated using the --name you provided in the viam module create command).
visibilitystringRequiredWhether the module is accessible only to members of your organization (private), or visible to all Viam users (public). You can later make a private module public using the viam module update command. Once you make a module public, you can change it back to private if it is not configured on any machines outside of your organization.

Default: private
urlstringOptionalThe URL of the GitHub repository containing the source code of the module.
descriptionstringRequiredA description of your module and what it provides.
modelsobjectRequired

A list of one or more models provided by your custom module. You must provide at least one model, which consists of an api and model key pair. If you are publishing a public module ("visibility": "public"), the namespace of your model must match the namespace of your organization.

For more information, see naming your model.

entrypointstringRequiredThe name of the file that starts your module program. This can be a compiled executable, a script, or an invocation of another program. If you are providing your module as a single file to the upload command, provide the path to that single file. If you are providing a directory containing your module to the upload command, provide the path to the entry point file contained within that directory.
buildobjectOptionalAn object containing the command to run to build your module, as well as optional fields for the path to your dependency setup script, the target architectures to build for, and the path to your built module. Use this with the Viam CLI's build subcommand.

For example, the following represents the configuration of an example my-module public module in the acme namespace:

Click to view example meta.json with build object
{
  "module_id": "acme:my-module",
  "visibility": "public",
  "url": "https://github.com/<my-repo-name>/my-module",
  "description": "An example custom module.",
  "models": [
    {
      "api": "rdk:component:generic",
      "model": "acme:demo:my-model"
    }
  ],
  "build": {
    "path": "dist/archive.tar.gz", // optional - path to your built module
    "build": "./build.sh", // command that will build your module
    "arch": ["linux/amd64", "linux/arm64"] // architecture(s) to build for
  },
  "entrypoint": "dist/main" // path to executable
}
Click to view example meta.json without build object
{
  "module_id": "acme:my-module",
  "visibility": "public",
  "url": "https://github.com/<my-repo-name>/my-module",
  "description": "An example custom module.",
  "models": [
    {
      "api": "rdk:component:generic",
      "model": "acme:demo:my-model"
    }
  ],
  "entrypoint": "my-module.sh" // path to executable
}

See meta.json file for more information.

4. (For Python) Package module as an archive

For modules written in Python, you should package your module files as an archive first, before uploading. Other languages can proceed to the next step to upload their module directly. To package a module written in Python, run the following command from the same directory as your meta.json file:

tar -czvf dist/archive.tar.gz <PATH-TO-EXECUTABLE>

where <PATH-TO-EXECUTABLE> is the packaged executable that runs the module at the entry point. If using PyInstaller, by default this would be dist/main.

For a Python module built using the venv approach, the command might look like this:

tar -czf module.tar.gz run.sh requirements.txt src

Where run.sh is your entrypoint file, requirements.txt is your pip dependency list file, and src is the directory that contains the source code of your module.

Supply the path to the resulting archive file in the next step.

5. Upload your module

Run viam module upload to upload your custom module to the Viam Registry. Specify the path to the file, directory, or compressed archive (with .tar.gz or .tgz extension) that contains your custom module code:

viam module upload --version <version> --platform <platform> <module-path> --tags=<tags>

where:

  • version: provide a version for your custom module, using semantic versioning (example: 1.0.0). You can later increment this value with subsequent viam module upload commands. See Using the --version argument for more information.
  • platform: provide the system architecture your custom module supports. You can only provide one platform argument at a time to the viam module upload command. See Using the --platform argument for the full list of supported architectures.
  • module-path: provide the path to the file, directory, or compressed archive (with .tar.gz or .tgz extension) that contains your custom module code.
  • tags: provide a comma-separated list of platform tags that determine to which platforms this binary can be deployed. See viam module upload.

For example:

  • To upload a module that is defined in a single file named my-module-file in a local bin directory:

    viam module upload --version 1.0.0 --platform linux/amd64 ./bin/my-module-file
    
  • To upload a module that includes multiple files, as well as a separate entry point file, all contained with a local bin directory:

    viam module upload --version 1.0.0 --platform linux/amd64 ./bin
    
  • To upload a module that has been compressed as an archive named packaged-module.tar.gz:

    viam module upload --version 1.0.0 --platform linux/amd64 packaged-module.tar.gz
    

When you upload a module, the command performs basic validation of your module to check for common errors.

For more information, see the viam module command.

Next steps

Now that your module is available in the registry, you can configure the components or services it supports just as you would configure other resources: Go to the CONFIGURE tab of a machine, add a component or service (as applicable), and search for the name of your model.

To update, delete, or change the privacy settings of a module you deployed, see Manage Modules.

Have questions, or want to meet other people working on robots? Join our Community Discord.

If you notice any issues with the documentation, feel free to file an issue or edit this file.