Previous
Run control logic
At this point you should have a working module, deployed locally on a machine for testing. To make it available to deploy on more machines, the following steps will show you how to package it and upload it to the registry.
Create a README (strongly recommended)
It’s quite helpful to create a README to document what your module does and how to configure and use it, especially if you plan to share your module with others.
Create a GitHub repo and link to it from your meta.json
Create a GitHub repository with all the source code and the README for your module. This is required for cloud build to work.
Add the link to the repo to the meta.json file
Add the link to that repo as the url
in the
Edit the meta.json file
Make any necessary edits to the meta.json
file.
For example, if you’ve changed the module’s functionality, update the description in the meta.json
file.
Click below for information about the available fields.
If you want to share the module outside of your organization, set "visibility": "public"
.
Package and upload
To package (for Python) and upload your module and make it available to configure on machines in your organization (or in any organization, depending on how you set visibility
in the
The recommended approach for Python is to use PyInstaller to compile your module into a packaged executable: a standalone file containing your program, the Python interpreter, and all of its dependencies. When packaged in this fashion, you can run the resulting executable on your desired target platform or platforms without needing to install additional software or manage dependencies manually.
To follow these PyInstaller packaging steps, you must have enabled cloud build when moving through the module generator prompts.
If you did not, you will need to manually create a
Edit your
"entrypoint": "dist/main",
"first_run": "",
"build": {
"build": "./build.sh",
"setup": "./setup.sh",
"path": "dist/archive.tar.gz",
"arch": [
"linux/amd64",
"linux/arm64"
]
}
Delete the
Now you are ready to build and upload your module, either using Viam’s cloud build tooling which is recommended for continuous integration, or a more manual process:
We recommend you use PyInstaller with the build-action
GitHub action which provides a simple cross-platform build setup for multiple platforms: x86 and Arm Linux distributions, and MacOS.
The viam module generate
command already generated the build-action
file in your
In your terminal, run viam organizations list
to view your organization ID.
Create an organization API key by running the following command:
viam organization api-key create --org-id YOUR_ORG_UUID --name descriptive-key-name
In the GitHub repo for your project, go to Settings → Secrets and variables → Actions. Create two new secrets using the New repository secret button:
VIAM_KEY_ID
with the UUID from Key ID:
in your terminalVIAM_KEY_VALUE
with the string from Key Value:
in your terminalFrom the main code page of your GitHub repo, find Releases in the right side menu and click Create a new release.
In the Choose a tag dropdown, create a new tag with a name consisting of three numbers separated by periods, following the regular expression [0-9]+.[0-9]+.[0-9]+
(for example, 1.0.0
).
You must follow this format to trigger the build action.
For details about versioning, see Module versioning.
Click Publish release.
The cloud build action will begin building the new module version for each architecture listed in your
See Update an existing module using a GitHub action for more information.
From within the module directory, create a virtual Python environment with the necessary packages and then build an executable by running the setup and build scripts:
sh setup.sh
sh build.sh
Run the viam module upload
CLI command to upload the module to the registry.
If your module can only be run on Linux or macOS, for example due to platform-specific dependencies, replace any
with linux/any
or darwin/any
, respectively.
If your module runs on all platforms, keep any
:
viam module upload --version 1.0.0 --platform any dist/archive.tar.gz
For details on platform support, see Using the --platform
argument.
For details about versioning, see Module versioning.
The viam module upload
command only supports one platform
argument at a time.
If you would like to upload your module with support for multiple platforms, you must run a separate viam module upload
command for each platform.
Use the same version number when running multiple upload
commands of the same module code if only the platform
support differs.
The Viam Registry page for your module displays the platforms your module supports for each version you have uploaded.
PyInstaller does not support relative imports in entrypoints (imports starting with .
).
If you get "ImportError: attempted relative import with no known parent package"
, set up a stub entrypoint as described on GitHub.
In addition, PyInstaller does not support cross-compiling: you must compile your module on the target architecture you wish to support.
For example, you cannot run a module on a Linux arm64
system if you compiled it using PyInstaller on a Linux amd64
system.
Viam makes this easy to manage by providing a build system for modules.
Follow these instructions to automatically build for each system your module can support using Viam’s CLI.
You can use the following package and upload method if you opted not to enable cloud build when you ran viam module generate
.
Package the module as an archive by running the following command from inside the module directory:
tar -czf module.tar.gz run.sh setup.sh requirements.txt src meta.json
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.
This creates a tarball called
Run the viam module upload
CLI command to upload the module to the registry.
If your module can only be run on Linux or macOS, for example due to platform-specific dependencies, replace any
with linux/any
or darwin/any
, respectively.
If your module runs on all platforms, keep any
:
viam module upload --version 1.0.0 --platform any module.tar.gz
For details on platform support, see Using the --platform
argument.
For details about versioning, see Module versioning.
The viam module upload
command only supports one platform
argument at a time.
If you would like to upload your module with support for multiple platforms, you must run a separate viam module upload
command for each platform.
Use the same version number when running multiple upload
commands of the same module code if only the platform
support differs.
The Viam Registry page for your module displays the platforms your module supports for each version you have uploaded.
From within your module’s directory, run the viam module upload
CLI command to upload the module to the registry.
If your module can only be run on Linux or macOS, for example due to platform-specific dependencies, replace <platform>
with linux/amd64
, linux/arm64
, or another platform.
viam module upload --version 1.0.0 --platform <platform> .
For details about versioning, see Module versioning.
The viam module upload
command only supports one platform
argument at a time.
If you would like to upload your module with support for multiple platforms, you must run a separate viam module upload
command for each platform.
Use the same version number when running multiple upload
commands of the same module code if only the platform
support differs.
The Viam Registry page for your module displays the platforms your module supports for each version you have uploaded.
If you look at the Viam Registry page while logged into your account, you’ll be able to find your module listed.
If your module supports hardware, add the hardware name in the Components & services section on the module registry page under the heading Supported hardware.
For information about updating modules, see Update and manage modules you created.
Once your module is in the registry, you can use the registry version of your module on machines. Configure it just as you would configure any other component or service in the registry:
Go to your machine’s CONFIGURE tab.
Click the + button.
Select Component or service, and search for and select your model. If you cannot find your new module, it may be private and not accessible to the organization you are in. Check that you are in an organization that can access the module.
Click Add module.
Enter a name for your resource and click Create.
If the module has requires attributes, configure them.
Click Save.
Your module will now be added to your machine.
If you used a local module for testing, you can safely delete it.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!