|
1 | 1 | # Viam Python SDK
|
| 2 | + |
2 | 3 | 
|
3 | 4 | 
|
4 | 5 | [](https://python.viam.dev)
|
5 | 6 | 
|
6 | 7 | [](https://github.com/viamrobotics/viam-python-sdk/blob/main/LICENSE)
|
7 | 8 |
|
| 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 | + |
8 | 15 | ## Installation
|
| 16 | + |
9 | 17 | 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
|
10 | 18 |
|
11 | 19 | `pip install viam-sdk`
|
12 | 20 |
|
13 | 21 | 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.
|
14 | 22 |
|
15 | 23 | ### Upgrading
|
| 24 | + |
16 | 25 | To upgrade, simply run the `pip install` command with the `-U` option:
|
17 | 26 | `pip install -U viam-sdk`
|
18 | 27 |
|
19 | 28 | ### Installing from Source
|
| 29 | + |
20 | 30 | 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.
|
21 | 31 |
|
22 | 32 | 1. Download/clone this [repository](https://github.com/viamrobotics/viam-python-sdk)
|
23 | 33 | 1. Download/clone the [rust-utils](https://github.com/viamrobotics/rust-utils)
|
24 | 34 | 1. [Install Rust](https://www.rust-lang.org/tools/install) if not already available
|
25 | 35 | 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` |
27 | 37 | 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` |
30 | 40 | 1. Copy the compiled library to the directory `viam-python-sdk/src/viam/rpc/`
|
31 | 41 | 1. From the `viam-python-sdk` directory, run `poetry build` to create an installable package
|
32 | 42 | 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`
|
33 | 43 |
|
34 | 44 | 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.
|
35 | 45 |
|
36 |
| - |
37 | 46 | If you do **NOT** need communication over WebRTC (and thus, do not need the native library), the steps are:
|
38 | 47 |
|
39 | 48 | 1. Download/clone this repository
|
40 | 49 | 1. Run `poetry build` from the `viam-python-sdk` directory
|
41 | 50 | 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`
|
42 | 51 | 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) |
44 | 53 |
|
45 | 54 | ## Configure a client application at [app.viam.com](https://app.viam.com)
|
46 | 55 |
|
@@ -79,31 +88,37 @@ The Viam Python SDK utilizes gRPC and, optionally WebRTC (defaults to on). gRPC
|
79 | 88 | 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.
|
80 | 89 |
|
81 | 90 | ## Examples
|
| 91 | +
|
82 | 92 | 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
|
83 | 93 | custom components as a remote to existing robots.
|
84 | 94 |
|
85 | 95 | More examples can be found in the [`examples`](/examples) directory.
|
86 | 96 |
|
87 | 97 | ## Documentation
|
| 98 | +
|
88 | 99 | Documentation, like this entire project, is under active development, and can be found at [python.viam.dev](https://python.viam.dev).
|
89 | 100 |
|
90 | 101 | ---
|
| 102 | +
|
91 | 103 | ## Development
|
| 104 | +
|
92 | 105 | To contribute to the python SDK, please see the [contribution guidelines](https://python.viam.dev/contributing.html).
|
93 | 106 |
|
94 | 107 | ### Adding new resource types
|
| 108 | +
|
95 | 109 | The SDK provides a number of abstract base components and services (collectively: resources). To add more abstract resources, follow these steps:
|
96 | 110 |
|
97 | 111 | 1. Create a new directory in `viam.components` or `viam.services` with the name of the new component
|
98 | 112 | 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` |
103 | 117 | 1. Write tests for the new resource and add the resource to `tests.mocks.{components|services}`
|
104 | 118 | 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`
|
105 | 119 |
|
106 | 120 | ## License
|
| 121 | +
|
107 | 122 | Copyright 2021-2023 Viam Inc.
|
108 | 123 |
|
109 | 124 | Apache 2.0 - See [LICENSE](https://github.com/viamrobotics/viam-python-sdk/blob/main/LICENSE) file
|
0 commit comments