api_endpoints
plantdb.client.api_endpoints Link
API Endpoints for PlantDB client.
This module provides helper functions to construct URL paths for the PlantDB REST API. Each function returns the endpoint string with optional prefix and performs basic sanitization of identifiers.
Key Features
- Sanitizes and validates scan, fileset, and file names.
- Supports optional URL prefixes for API versioning.
- Generates paths for authentication, health checks, scans, images, and archives.
Usage Examples
from plantdb.client import api_endpoints api_endpoints.login(prefix='/api/v1') '/api/v1/login' api_endpoints.scan('plant1', prefix='/api/v1') '/api/v1/scans/plant1'
archive Link
archive(scan_id, **kwargs)
Return the URL path to the dataset archive endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_id
|
str
|
The name of the scan dataset to archive. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the dataset archive endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.archive('scan1')
'/archive/scan1'
Source code in plantdb/client/api_endpoints.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
file Link
file(scan_id, fileset_id, file_id, **kwargs)
Return the URL path to the scan/fileset/file endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_id
|
str
|
The name of the scan dataset containing the file. |
required |
fileset_id
|
str
|
The name of the fileset containing the file. |
required |
file_id
|
str
|
The name of the file. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the file endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.file('real_plant','images','00000_rgb')
'/files/real_plant/images/00000_rgb'
Source code in plantdb/client/api_endpoints.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
health Link
health(**kwargs)
Return the URL path to the health endpoint.
Other Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
An optional prefix to prepend to the URL path. |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the health endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.health(prefix='/api/v1')
'/api/v1/health'
Source code in plantdb/client/api_endpoints.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
image Link
image(scan_id, fileset_id, file_id, size, **kwargs)
Return the URL path to the image endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_id
|
str
|
The name of the scan dataset containing the image. |
required |
fileset_id
|
str
|
The name of the fileset containing the image. |
required |
file_id
|
str
|
The name of the image. |
required |
size
|
str or int
|
The size parameter of the image request. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the image endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.image('real_plant','images','00000_rgb', 'orig')
'/image/real_plant/images/00000_rgb?size=orig'
Source code in plantdb/client/api_endpoints.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
login Link
login(**kwargs)
Return the URL path to the login endpoint.
Other Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
An optional prefix to prepend to the URL path. |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the login endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.login(prefix='/api/v1')
'/api/v1/login'
Source code in plantdb/client/api_endpoints.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
logout Link
logout(**kwargs)
Return the URL path to the logout endpoint.
Other Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
An optional prefix to prepend to the URL path. |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the logout endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.logout(prefix='/api/v1')
'/api/v1/logout'
Source code in plantdb/client/api_endpoints.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
refresh Link
refresh(scan_id=None, **kwargs)
Return the URL path to the dataset archive endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_id
|
str
|
The name of the scan dataset to archive. |
None
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
An optional prefix to prepend to the URL path. |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the refresh endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.refresh(prefix='/api/v1')
'/api/v1/refresh'
>>> api_endpoints.refresh('scan1')
'/refresh?scan_id=scan1'
Source code in plantdb/client/api_endpoints.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
register Link
register(**kwargs)
Return the URL path to the register endpoint.
Other Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
An optional prefix to prepend to the URL path. |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the register endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.register(prefix='/api/v1')
'/api/v1/register'
Source code in plantdb/client/api_endpoints.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
sanitize_name Link
sanitize_name(name)
Sanitizes and validates the provided name.
The function ensures that the input string adheres to predefined naming rules by:
- stripping leading/trailing spaces,
- isolating the last segment after splitting by slashes,
- validating the name against an alphanumeric pattern
with optional underscores (
_), dashes (-), or periods (.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to sanitize and validate. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Sanitized name that conforms to the rules. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided name contains invalid characters or does not meet the naming rules. |
Source code in plantdb/client/api_endpoints.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
scan Link
scan(scan_id, **kwargs)
Return the URL path to the scan endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_id
|
str
|
The name of the scan to access. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
An optional prefix to prepend to the URL path. |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the scan endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.scan('scan1')
'/scans/scan1'
>>> api_endpoints.scan('scan1', prefix='/api/v1')
'/api/v1/scans/scan1'
Source code in plantdb/client/api_endpoints.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
scan_file Link
scan_file(scan_id, file_path, **kwargs)
Return the URL path to the scan/fileset/file endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_id
|
str
|
The name of the scan dataset containing the file. |
required |
file_path
|
str
|
The path to the file in the database. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the file endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.scan_file('real_plant','images/00000_rgb.jpg')
'/files/real_plant/images/00000_rgb.jpg'
Source code in plantdb/client/api_endpoints.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
scans Link
scans(**kwargs)
Return the URL path to the scans endpoint.
Other Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
An optional prefix to prepend to the URL path. |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the scans endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.scans(prefix='/api/v1')
'/api/v1/scans'
Source code in plantdb/client/api_endpoints.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
token_refresh Link
token_refresh(**kwargs)
Return the URL path to the token refresh endpoint.
Other Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
An optional prefix to prepend to the URL path. |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the token refresh endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.token_refresh(prefix='/api/v1')
'/api/v1/token-refresh'
Source code in plantdb/client/api_endpoints.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
token_validation Link
token_validation(**kwargs)
Return the URL path to the token validation endpoint.
Other Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
An optional prefix to prepend to the URL path. |
Returns:
| Type | Description |
|---|---|
str
|
The URL path to the token validation endpoint. |
Examples:
>>> from plantdb.client import api_endpoints
>>> api_endpoints.token_validation(prefix='/api/v1')
'/api/v1/token-validation'
Source code in plantdb/client/api_endpoints.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
url_prefix Link
url_prefix(endpoint_path)
Wrap an endpoint path generator with an optional URL prefix.
Examples:
>>> def base_path(user_id):
... return f"/users/{user_id}"
...
>>> prefixed = url_prefix(base_path)
>>> prefixed(42)
'/users/42'
>>> prefixed(42, prefix='api')
'/api/users/42'
>>> prefixed(42, prefix='/api/')
'/api/users/42'
Source code in plantdb/client/api_endpoints.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |