Skip to content

Commit d256ed8

Browse files
njoomabenjirewis
andauthored
Add a getting started guide (#457)
Co-authored-by: Benjamin Rewis <[email protected]>
1 parent 5ff52d1 commit d256ed8

File tree

2 files changed

+86
-9
lines changed

2 files changed

+86
-9
lines changed

README.md

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,55 @@
11
# Viam Python SDK
2+
23
![PyPI](https://img.shields.io/pypi/v/viam-sdk)
34
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/viam-sdk)
45
[![documentation](https://img.shields.io/static/v1?label=docs&message=python.viam.dev&color=lightgray)](https://python.viam.dev)
56
![build status](https://github.com/viamrobotics/python-sdk/actions/workflows/test.yml/badge.svg)
67
[![license](https://img.shields.io/badge/license-Apache_2.0-blue)](https://github.com/viamrobotics/viam-python-sdk/blob/main/LICENSE)
78

9+
The Viam Python SDK allows you to build robots, access existing Viam robots, and manage your fleet of Viam robots.
10+
11+
If you would like a blueprint on setting up a Python environment with Viam from scratch, you can follow our [Setup](https://python.viam.dev/setup.html) guide.
12+
13+
If you would like to develop and contribute to Viam's Python SDK, take a look at the [Development](#development) portion of the README.
14+
815
## Installation
16+
917
Currently, we have pre-built binaries for macOS (both Intel and Apple Silicon), along with Linux (x86, aarch64, armv6l) that you can install via pip
1018

1119
`pip install viam-sdk`
1220

1321
Windows is not supported. If you are using Windows, install `viam-sdk` in WSL. For other unsupported systems, read further on how to install from source.
1422

1523
### Upgrading
24+
1625
To upgrade, simply run the `pip install` command with the `-U` option:
1726
`pip install -U viam-sdk`
1827

1928
### Installing from Source
29+
2030
The Viam Python SDK uses native libraries to support communication over WebRTC, which will allow you to connect to robots that are not on the same network. In order to facilitate that communication, there is a [rust-utils repo](https://github.com/viamrobotics/rust-utils) that contains the necessary protocols. Therefore, to build from source, you will need both the Rust utils and the Rust compiler.
2131

2232
1. Download/clone this [repository](https://github.com/viamrobotics/viam-python-sdk)
2333
1. Download/clone the [rust-utils](https://github.com/viamrobotics/rust-utils)
2434
1. [Install Rust](https://www.rust-lang.org/tools/install) if not already available
2535
1. From the `rust-utils` directory, run `cargo build`
26-
* You can optionally provide the `--release` flag: `cargo build --release`
36+
- You can optionally provide the `--release` flag: `cargo build --release`
2737
1. Find the compiled library in `rust-utils/target/debug/libviam_rust_utils.*`
28-
* If you provided the `--release` flag, the enclosing directory will be `release`: `rust-utils/target/release/libviam_rust_utils.*`
29-
* The extension of the executable will depend on your operating system. For example, on macOS it will be `libviam_rust_utils.dylib`, whereas on Linux it will be `libviam_rust_utils.so`
38+
- If you provided the `--release` flag, the enclosing directory will be `release`: `rust-utils/target/release/libviam_rust_utils.*`
39+
- The extension of the executable will depend on your operating system. For example, on macOS it will be `libviam_rust_utils.dylib`, whereas on Linux it will be `libviam_rust_utils.so`
3040
1. Copy the compiled library to the directory `viam-python-sdk/src/viam/rpc/`
3141
1. From the `viam-python-sdk` directory, run `poetry build` to create an installable package
3242
1. Find the newly created installable package located in `viam-python-sdk/dist/` and pip install it directly, e.g.: `pip install viam-python-sdk/dist/viam_sdk-0.1.0-py3-none-any.whl`
3343

3444
If you have a macOS or Linux based operating system and do not want to build rust-utils manually, you can also look for the executable in the [releases](https://github.com/viamrobotics/rust-utils/releases/latest) page of the rust-utils library.
3545

36-
3746
If you do **NOT** need communication over WebRTC (and thus, do not need the native library), the steps are:
3847

3948
1. Download/clone this repository
4049
1. Run `poetry build` from the `viam-python-sdk` directory
4150
1. Find the newly created installable package located in `viam-python-sdk/dist/` and pip install it directly, e.g.: `pip install viam-python-sdk/dist/viam_sdk-0.1.0-py3-none-any.whl`
4251
1. Ensure that every connection has the option `disable_webrtc` set to `True`: `viam.rpc.dial.DialOptions(disable_webrtc=True)`
43-
* For more information about connecting to a robot, see the [documentation](https://python.viam.dev) and [example usage](https://python.viam.dev/examples/example.html)
52+
- For more information about connecting to a robot, see the [documentation](https://python.viam.dev) and [example usage](https://python.viam.dev/examples/example.html)
4453

4554
## Configure a client application at [app.viam.com](https://app.viam.com)
4655

@@ -79,31 +88,37 @@ The Viam Python SDK utilizes gRPC and, optionally WebRTC (defaults to on). gRPC
7988
Sessions are a safety feature that automatically cancel operations made by the python client if it loses connection to a robot. Sessions are enabled by default but can be disabled by setting `RobotClient.Options.disable_sessions = True`. Please see the [RDK session documentation](https://pkg.go.dev/go.viam.com/rdk/session) for more details and server-side configuration options.
8089
8190
## Examples
91+
8292
Read the [Example Usage](https://python.viam.dev/examples/example.html) page, to learn how to access a component, build a custom component, and expose
8393
custom components as a remote to existing robots.
8494
8595
More examples can be found in the [`examples`](/examples) directory.
8696
8797
## Documentation
98+
8899
Documentation, like this entire project, is under active development, and can be found at [python.viam.dev](https://python.viam.dev).
89100
90101
---
102+
91103
## Development
104+
92105
To contribute to the python SDK, please see the [contribution guidelines](https://python.viam.dev/contributing.html).
93106
94107
### Adding new resource types
108+
95109
The SDK provides a number of abstract base components and services (collectively: resources). To add more abstract resources, follow these steps:
96110
97111
1. Create a new directory in `viam.components` or `viam.services` with the name of the new component
98112
1. Create 4 new files in the newly created directory:
99-
1. Define all requirements of the resource in `{RESOURCE_NAME}.py`
100-
1. Implement the gRPC service for the new resource in `service.py`
101-
1. Create a gRPC client for the new resource in `client.py`
102-
1. Register the subtype and define package exports in `__init__.py`
113+
1. Define all requirements of the resource in `{RESOURCE_NAME}.py`
114+
1. Implement the gRPC service for the new resource in `service.py`
115+
1. Create a gRPC client for the new resource in `client.py`
116+
1. Register the subtype and define package exports in `__init__.py`
103117
1. Write tests for the new resource and add the resource to `tests.mocks.{components|services}`
104118
1. If the resource is a component, add the component to `examples.server.v1.components` and its corresponding concrete type in `examples.server.v1.server`
105119
106120
## License
121+
107122
Copyright 2021-2023 Viam Inc.
108123
109124
Apache 2.0 - See [LICENSE](https://github.com/viamrobotics/viam-python-sdk/blob/main/LICENSE) file

SETUP.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Viam + Python
2+
3+
This guide will help you get set up with Viam with Python. It assumes that you are starting from scratch, and will walk you through setting up a fresh environment and installing the necessary requirements.
4+
5+
## Setup your project
6+
7+
The first step is to create a directory to house your project. For this guide, we will be using the directory name `viam-python`:
8+
9+
```bash
10+
mkdir viam-python
11+
cd viam-python
12+
```
13+
14+
## Create a Virtual Environment
15+
16+
Now that we are in the project directory, let's create and activate a virtual environment for python to run in.
17+
18+
> **INFO**
19+
> Creating a virtual environment (`venv`) is important as it isolates this python environment from any other you might already have. This allows us to ensure a clean project and easier dependency management, and it avoids bloating your global python environment.
20+
21+
```bash
22+
python3 -m venv viam-env
23+
source viam-env/bin/activate
24+
```
25+
26+
> **INFO**
27+
> Some Linux environments may not have the necessary requirements to create a virtual environment. If you receive an error, you can try running `apt install python3-venv` and then running the above commands.
28+
29+
You will now see `(viam-env)` prepend the commands in your terminal window. This shows that the python packages being used are from this particular environment.
30+
31+
You can exit this environment by running `deactivate`.
32+
33+
## Install Viam
34+
35+
Inside the activated `viam-env` python environment, you can now install the Viam SDK:
36+
37+
```bash
38+
pip3 install viam-sdk
39+
```
40+
41+
This will install Viam and all required dependencies.
42+
43+
> **INFO**
44+
> Some features of the Viam SDK require additional dependencies. For example, the ML Models feature requires extras, which can be installed with `pip3 install viam-sdk[mlmodel]`. Read the documentation to determine if a specific feature requires extra dependencies.
45+
46+
Should you need to install your own requirements, be sure to do so in this environment.
47+
48+
## Setup your IDE
49+
50+
You'll now want to point your IDE to use the python interpreter of your new environment, rather than the default interpreter (likely the global python interpreter).
51+
52+
The following steps are for VS Code. If you're not using VS Code, please read your IDE's documentation on selecting python interpreters.
53+
54+
1. Open the `viam-python` directory in VS Code
55+
1. Open the Command Palette (using `⇧⌘P` or through the menus View -> Command Palette)
56+
1. Select the command `Python: Select Interpreter`. There, you should see all the interpreters available to you. You're looking for one the on you just made: `viam-env`. It will look something like: `Python 3.11.5 ('viam-env': venv) ./viam-env/bin/python`. If you don't see it, click the `Refresh` icon on the top right of the Command Palette.
57+
58+
Your IDE will now recognize all packages installed in this environment.
59+
60+
## Start building!
61+
62+
You are now ready to start using Viam's Python SDK!

0 commit comments

Comments
 (0)