|
| 1 | +# The official QFieldCloud SDK and CLI |
| 2 | + |
| 3 | +`qfieldcloud-sdk` is the official client to connect to QFieldCloud API either as a python module, or directly from the command line. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +`pip install qfieldcloud-sdk` |
| 8 | + |
| 9 | +## Module usage |
| 10 | + |
| 11 | +``` |
| 12 | +import qfieldcloud_sdk |
| 13 | +import requests |
| 14 | +
|
| 15 | +client = qfieldcloud_sdk.Client( |
| 16 | + url="https://app.qfield.cloud/api/v1/", |
| 17 | + username="user1", |
| 18 | + password="pass1", |
| 19 | +) |
| 20 | +
|
| 21 | +try: |
| 22 | + projects = client.projects() |
| 23 | +except requests.HttpRequest: |
| 24 | + print("Oops!") |
| 25 | +``` |
| 26 | + |
| 27 | +## CLI usage |
| 28 | + |
| 29 | +The official QFieldCloud CLI tool. |
| 30 | + |
| 31 | +### Usage |
| 32 | + |
| 33 | +``` |
| 34 | +qfieldcloud-cli [OPTIONS] COMMAND [ARGS]... |
| 35 | +``` |
| 36 | + |
| 37 | +### Examples |
| 38 | + |
| 39 | +``` |
| 40 | +# logs in user "user" with password "pass" |
| 41 | +qfieldcloud-cli login user pass |
| 42 | +
|
| 43 | +# gets the projects of user "user" with password "pass" at "https://localhost/api/v1/" |
| 44 | +qfieldcloud-cli -u user -p pass -U https://localhost/api/v1/ list-projects |
| 45 | +
|
| 46 | +# gets the projects of user authenticated with token `QFIELDCLOUD_TOKEN` at "https://localhost/api/v1/" as JSON |
| 47 | +export QFIELDCLOUD_URL=https://localhost/api/v1/ |
| 48 | +export QFIELDCLOUD_TOKEN=017478ee2464440cb8d3e98080df5e5a |
| 49 | +qfieldcloud-cli --json list-projects |
| 50 | +``` |
| 51 | + |
| 52 | +### Global options overview |
| 53 | + |
| 54 | +``` |
| 55 | +-U, --url TEXT URL to the QFieldCloud API endpoint. If not passed, |
| 56 | + gets the value from QFIELDCLOUD_URL environment |
| 57 | + variable. Default: https://app.qfield.cloud/api/v1/ |
| 58 | +
|
| 59 | +-u, --username TEXT Username or email. |
| 60 | +-p, --password TEXT |
| 61 | +-t, --token TEXT Session token. |
| 62 | +--json / --human Output the result as newline formatted json. |
| 63 | +--help Show this message and exit. |
| 64 | +``` |
| 65 | + |
| 66 | +Environment variables can be used instead of passing some common global options. |
| 67 | + |
| 68 | +- `QFIELDCLOUD_API` - QFieldCloud API endpoint URL |
| 69 | +- `QFIELDCLOUD_USERNAME` - QFieldCloud username or email. Need `QFIELDCLOUD_PASSWORD` to be set. |
| 70 | +- `QFIELDCLOUD_PASSWORD` - Password. Needs `QFIELDCLOUD_USERNAME` to be set. |
| 71 | +- `QFIELDCLOUD_TOKEN` - Token that can be used instead of passing username and password. It can be obtained by running `qfieldcloud-cli login`. |
| 72 | + |
| 73 | +### Commands overview |
| 74 | + |
| 75 | +``` |
| 76 | + download-files Download QFieldCloud project files |
| 77 | + list-files List QFieldCloud project files |
| 78 | + list-projects List QFieldCloud projects |
| 79 | + login Login into QFieldCloud |
| 80 | +``` |
| 81 | + |
| 82 | +#### login |
| 83 | + |
| 84 | +Login to QFieldCloud. |
| 85 | + |
| 86 | +``` |
| 87 | +qfieldcloud-cli login [OPTIONS] USERNAME PASSWORD |
| 88 | +``` |
| 89 | + |
| 90 | +#### list-projects |
| 91 | + |
| 92 | +List QFieldCloud projects. |
| 93 | + |
| 94 | +``` |
| 95 | +qfieldcloud-cli list-projects [OPTIONS] |
| 96 | +
|
| 97 | +Options: |
| 98 | + --include-public / --no-public Includes the public project in the list. |
| 99 | +``` |
| 100 | + |
| 101 | +#### list-files |
| 102 | + |
| 103 | +List QFieldCloud project files. |
| 104 | + |
| 105 | +``` |
| 106 | +qfieldcloud-cli list-files [OPTIONS] PROJECT_ID |
| 107 | +``` |
| 108 | + |
| 109 | +#### download-files |
| 110 | + |
| 111 | +Download QFieldCloud project files. |
| 112 | + |
| 113 | +``` |
| 114 | +qfieldcloud-cli download-files [OPTIONS] PROJECT_ID LOCAL_DIR |
| 115 | +
|
| 116 | +Options: |
| 117 | + --subdir TEXT Do not download the whole project, but only |
| 118 | + the subdirectory passed. |
| 119 | +
|
| 120 | + --exit-on-error / --no-exit-on-error |
| 121 | + If any project file download fails stop |
| 122 | + downloading the rest. |
| 123 | +``` |
| 124 | + |
| 125 | +## Development |
| 126 | + |
| 127 | +Contributions are more than welcome! |
| 128 | + |
| 129 | +### Code style |
| 130 | +Code style done with [precommit](https://pre-commit.com/). |
| 131 | + |
| 132 | +``` |
| 133 | +pip install pre-commit |
| 134 | +# install pre-commit hook |
| 135 | +pre-commit install |
| 136 | +``` |
| 137 | + |
| 138 | +### Cloning the project |
| 139 | + |
| 140 | +One time action to clone and setup: |
| 141 | + |
| 142 | +``` |
| 143 | +git clone https://github.com/opengisch/qfieldcloud-sdk-python |
| 144 | +cd qfieldcloud-sdk-python |
| 145 | +# install dev dependencies |
| 146 | +python3 -m pip install --upgrade build pre-commit |
| 147 | +pre-commit install |
| 148 | +``` |
| 149 | + |
| 150 | +To run CLI interface for development purposes execute: |
| 151 | + |
| 152 | +``` |
| 153 | +python src/bin/qfieldcloud-cli |
| 154 | +``` |
| 155 | + |
| 156 | +### Building the package |
| 157 | + |
| 158 | +Run: |
| 159 | + |
| 160 | +``` |
| 161 | +python3 -m build |
| 162 | +``` |
| 163 | + |
| 164 | +Then install on your system: |
| 165 | + |
| 166 | +``` |
| 167 | +pip install dist/qfieldcloud_sdk-dev-py3-none-any.whl --force-reinstall |
| 168 | +``` |
| 169 | + |
| 170 | +Voila! |
0 commit comments