Sentinel Hub — API reference#
Sentinel Hub server-side-render data source subpackage —
earthlens.sentinel_hub. Background, usage, authentication, the
collection/recipe catalog, and the Statistical/Batch planes are covered on the
other pages in this section; this page is the rendered API.
earthlens.sentinel_hub
#
Sentinel Hub server-side-render backend (defaults to Sentinel Hub on CDSE).
earthlens sends a bbox/geometry + time + an evalscript to one of Sentinel Hub's
request planes (Process / Async / Batch render → raster GeoTIFF; Statistical /
Batch-Statistical → tabular zonal stats); the server computes on-the-fly and
earthlens collects the result. A request is
variables={collection_or_recipe: [band, ...]} plus a bbox + date window, and
the plane is chosen by api= (auto-selected by size + whether geometry= was
given).
Public surface (re-exported from this package):
- :class:
SentinelHub— the backend; instantiate with a date range, a bbox, a{collection_or_recipe: [band, ...]}request, and (optionally)evalscript,resolution,endpoint,mosaicking_order,api,geometry, then call :meth:SentinelHub.download. - :class:
Catalog— pydantic-backed loader for the bundled two-layer catalog undersrc/earthlens/sentinel_hub/catalog/, exposingdatasets(collections),recipes,available_collections, andget_collection/get_recipe/is_recipe/resolve. - :class:
Collection/ :class:EvalscriptRecipe/ :class:Band/ :class:Extent/ :class:ResolvedRequest— the frozen value objects the catalog is built from. - :func:
read_evalscript— read a bundled.jsevalscript by name. - :class:
SentinelHubAuth/ :class:SentinelHubCredentials— the OAuth2 client-credentials auth wrapper and its credentials value object. - :class:
AuthenticationError— raised when no credentials are resolvable. - :data:
CATALOG_PATH/ :data:EVALSCRIPTS_PATH— absolute paths to the bundled catalog directory and evalscript directory; monkey-patchable in tests.
The Sentinel Hub client ([sentinel-hub] extra) is imported lazily, so the
EarthLens facade still imports without it.
AuthenticationError
#
Bases: AuthenticationError
Raised when the Sentinel Hub SHConfig cannot be assembled.
Wraps the missing-credentials case with an actionable message pointing at
the CDSE Dashboard. A subclass of the cross-backend
:class:earthlens.base.AuthenticationError so callers can catch every
backend's auth failure with one except clause.
Source code in src/earthlens/sentinel_hub/auth.py
Band
#
Bases: BaseModel
Per-band metadata for one band of a Sentinel Hub collection.
Frozen value object; the band name is the parent mapping key and is not repeated in the body. Every field is optional because band metadata is uneven across collections.
Attributes:
| Name | Type | Description |
|---|---|---|
common_name |
str | None
|
Common name ( |
description |
str | None
|
Human description of the band, or |
units |
str | None
|
Physical unit string, or |
resolution |
float | None
|
Native ground sample distance in metres, or |
center_wavelength |
float | None
|
Central wavelength in micrometres (optical), or |
Source code in src/earthlens/sentinel_hub/catalog.py
Catalog
#
Bases: AbstractCatalog
YAML-backed catalog of Sentinel Hub collections and evalscript recipes.
Reads every *.yaml under :data:CATALOG_PATH on construction and merges
them into typed :class:Collection / :class:EvalscriptRecipe models.
Collections are stored under the inherited :attr:datasets field (keyed by
logical key); recipes live in :attr:recipes; the informational index lives
in :attr:available_collections.
Attributes:
| Name | Type | Description |
|---|---|---|
datasets |
dict[str, Collection]
|
Logical collection key → :class: |
recipes |
dict[str, EvalscriptRecipe]
|
Recipe key → :class: |
available_collections |
list[str]
|
Every collection the backend can render (refreshed index; informational). |
Examples:
- A recipe resolves to its bundled evalscript; a collection to a bare bind:
- Resolving normalises both layers to one shape:
Source code in src/earthlens/sentinel_hub/catalog.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
get_collection(collection_key)
#
Return the :class:Collection for collection_key (did-you-mean on miss).
Alias of the inherited :meth:get_dataset, named for clarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_key
|
str
|
Logical collection key. |
required |
Returns:
| Type | Description |
|---|---|
Collection
|
The matching :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the key is unknown (message suggests the closest key). |
Source code in src/earthlens/sentinel_hub/catalog.py
get_recipe(recipe_key)
#
Return the :class:EvalscriptRecipe for recipe_key (did-you-mean on miss).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_key
|
str
|
Recipe key. |
required |
Returns:
| Type | Description |
|---|---|
EvalscriptRecipe
|
The matching :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the key is unknown (message suggests the closest key). |
Source code in src/earthlens/sentinel_hub/catalog.py
is_recipe(key)
#
Return whether key names a curated evalscript recipe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A logical collection or recipe key. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/earthlens/sentinel_hub/catalog.py
load(catalog_path=None)
classmethod
#
Read the Sentinel Hub catalog from disk (cached).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Catalog directory or single |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
Propagated from the loader. |
Source code in src/earthlens/sentinel_hub/catalog.py
model_post_init(__context)
#
Auto-load the bundled catalog when no rows were supplied.
Catalog() with no args reads the bundled catalog/ directory through
the (path, mtime)-keyed cache. If the caller passed datasets= or
recipes=, the disk read is skipped (in-memory catalogs for tests).
The base available_datasets field is mirrored from
available_collections so the index is discoverable through the
AbstractCatalog contract, then super().model_post_init populates
catalog from get_catalog().
Raises:
| Type | Description |
|---|---|
ValueError
|
When auto-loading, propagates the loader's errors. |
Source code in src/earthlens/sentinel_hub/catalog.py
resolve(key)
#
Resolve a collection-or-recipe key to a uniform :class:ResolvedRequest.
A recipe resolves to its bundled evalscript + bands + kind; a plain
collection resolves with evalscript=None and its default bands (the
backend then requires an explicit evalscript=).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A logical collection or recipe key. |
required |
Returns:
| Type | Description |
|---|---|
ResolvedRequest
|
The normalised :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- A recipe carries its evalscript + kind:
Source code in src/earthlens/sentinel_hub/catalog.py
Collection
#
Bases: BaseModel
One curated Sentinel Hub data collection, addressed by a logical key.
Attributes:
| Name | Type | Description |
|---|---|---|
sh_collection |
str
|
The |
bands |
dict[str, Band]
|
Band name → :class: |
default_bands |
list[str]
|
Bands used when the request names none. Falls back to
every key of |
cadence |
str | None
|
Native revisit cadence label, or |
resolution |
float | None
|
Native ground sample distance in metres, or |
extent |
Extent | None
|
Spatial/temporal coverage, or |
description |
str | None
|
One-line human summary, or |
Source code in src/earthlens/sentinel_hub/catalog.py
effective_bands
property
#
The band names to request by default (default_bands, else all bands).
EvalscriptRecipe
#
Bases: BaseModel
One curated evalscript recipe fixing a base collection + a .js file.
Attributes:
| Name | Type | Description |
|---|---|---|
base_collection |
str
|
The |
evalscript |
str
|
The bundled |
bands |
list[str]
|
The collection bands the evalscript consumes (informational + used by the refresh/validate tool). |
output_bands |
int
|
The number of bands the evalscript writes. |
kind |
str
|
|
description |
str | None
|
One-line human summary, or |
Source code in src/earthlens/sentinel_hub/catalog.py
Extent
#
Bases: BaseModel
Spatial/temporal coverage of a Sentinel Hub collection.
Attributes:
| Name | Type | Description |
|---|---|---|
start_date |
str | None
|
First available date ( |
end_date |
str | None
|
Last available date, or |
bbox |
tuple[float, float, float, float] | None
|
|
Source code in src/earthlens/sentinel_hub/catalog.py
ResolvedRequest
#
Bases: BaseModel
The uniform shape a resolved collection-or-recipe key takes.
Both a plain collection and a recipe resolve to this so the backend's
request-builder consumes one type. A plain collection resolves with
evalscript=None (the backend must then have an explicit evalscript=); a
recipe carries its bundled .js filename.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
The logical key the request named. |
sh_collection |
str
|
The |
bands |
list[str]
|
The bands to request (request override applied by the backend). |
evalscript |
str | None
|
The bundled |
output_bands |
int
|
Number of output bands the evalscript writes. |
is_recipe |
bool
|
Whether the key named a recipe (vs a plain collection). |
kind |
str
|
|
Source code in src/earthlens/sentinel_hub/catalog.py
SentinelHub
#
Bases: AbstractDataSource
Server-side Sentinel Hub backend on CDSE (raster or tabular by api=).
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
|
Source code in src/earthlens/sentinel_hub/backend.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 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 313 314 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 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 | |
__init__(start, end, variables, lat_lim, lon_lim, temporal_resolution='daily', path='', fmt='%Y-%m-%d', resolution=10.0, evalscript=None, endpoint=None, mosaicking_order=_DEFAULT_MOSAICKING_ORDER, api=None, geometry=None, maxcc=None, batch_output=None, client_id=None, client_secret=None, profile=None)
#
Initialise a Sentinel Hub backend instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str
|
Inclusive start date string (parsed with |
required |
end
|
str
|
Inclusive end date string. |
required |
variables
|
dict[str, list[str]]
|
|
required |
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
temporal_resolution
|
str
|
Advisory cadence label; the render window is
|
'daily'
|
path
|
Path | str
|
Output directory (created by the parent class). |
''
|
fmt
|
str
|
|
'%Y-%m-%d'
|
resolution
|
float
|
Output pixel size in metres (→ |
10.0
|
evalscript
|
str | None
|
A custom evalscript — an inline V3 JS string or a path to
a |
None
|
endpoint
|
str | None
|
Endpoint alias ( |
None
|
mosaicking_order
|
str
|
Per-pixel scene selection passed to
|
_DEFAULT_MOSAICKING_ORDER
|
api
|
str | None
|
The request plane ( |
None
|
geometry
|
Any
|
A shapely geometry / GeoJSON mapping / |
None
|
maxcc
|
float | None
|
Optional maximum cloud cover (0–1) passed to |
None
|
batch_output
|
dict[str, Any] | None
|
S3 delivery spec ( |
None
|
client_id
|
str | None
|
OAuth client id (else |
None
|
client_secret
|
str | None
|
OAuth client secret (else |
None
|
profile
|
str | None
|
A saved |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in src/earthlens/sentinel_hub/backend.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
download(progress_bar=True, aggregate=None)
#
Build the request(s), render server-side, and collect the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Reserved for parity with the other backends. |
True
|
aggregate
|
AggregationConfig | None
|
Optional aggregation request. Accepted (not rejected)
because |
None
|
Returns:
| Type | Description |
|---|---|
list[Any]
|
The written raster paths / table paths / S3 URIs, depending on the |
list[Any]
|
resolved plane. |
Source code in src/earthlens/sentinel_hub/backend.py
search(limit=100)
#
Query the Sentinel Hub Catalog API for scenes intersecting the request.
A real STAC-style search (distinct from the internal :meth:_search
fetch-planner): returns one :class:RemoteProduct per catalog item that
intersects the request bbox + window, so a caller can enumerate coverage
before rendering. An empty result is an empty list (not an error).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of items to return per requested collection. |
100
|
Returns:
| Type | Description |
|---|---|
list[RemoteProduct]
|
One product per catalog item (id + datetime + geometry on metadata). |
Source code in src/earthlens/sentinel_hub/backend.py
SentinelHubAuth
#
Bases: AbstractAuth[SentinelHubCredentials]
Assemble and hold a Sentinel Hub SHConfig (non-interactive OAuth2).
Conforms to the cross-backend :class:earthlens.base.AbstractAuth contract:
:meth:configure builds the SHConfig lazily and idempotently;
:meth:is_authenticated is the cheap predicate; and :meth:config returns
the configured SHConfig (configuring on first use). The token itself is
minted and refreshed by sentinelhub-py from the config on the first
request — there is no interactive flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
SentinelHubCredentials | None
|
The OAuth credentials. Defaults to an empty
:class: |
None
|
endpoint
|
str | None
|
A named endpoint alias ( |
None
|
Examples:
- Construct against CDSE-free (no config built until
configure()):
Source code in src/earthlens/sentinel_hub/auth.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
base_url
property
#
The resolved Sentinel Hub base URL this auth targets.
__init__(credentials=None, endpoint=None)
#
Store the credentials + resolved endpoint; does not build the config yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
SentinelHubCredentials | None
|
OAuth credentials, or |
None
|
endpoint
|
str | None
|
Endpoint alias or base URL; resolved eagerly so a bad alias fails at construction. |
None
|
Source code in src/earthlens/sentinel_hub/auth.py
config()
#
Return the assembled SHConfig, configuring on first use.
Returns:
| Type | Description |
|---|---|
Any
|
The |
Raises:
| Type | Description |
|---|---|
ImportError
|
When the |
AuthenticationError
|
When no credentials are resolvable. |
Source code in src/earthlens/sentinel_hub/auth.py
configure()
#
Build the SHConfig (base/token urls + credentials); idempotent.
Resolves credentials env → kwargs → profile. A second call after
:meth:is_authenticated returns True is a no-op.
Raises:
| Type | Description |
|---|---|
ImportError
|
When the |
AuthenticationError
|
When no credentials are resolvable (no id/secret and no profile). |
Source code in src/earthlens/sentinel_hub/auth.py
is_authenticated()
#
True once :meth:configure has assembled an SHConfig.
Cheap predicate — does not call the network. Returns True exactly when
a config object has been built.
Returns:
| Type | Description |
|---|---|
bool
|
Whether the |
Source code in src/earthlens/sentinel_hub/auth.py
SentinelHubCredentials
#
Bases: BaseModel
Frozen value object holding the Sentinel Hub OAuth credentials.
All fields are optional: an empty object falls back to the
SENTINELHUB_CLIENT_ID / SENTINELHUB_CLIENT_SECRET environment (or the
SH_* fallback), then to the named profile. Supplying client_id
(+ client_secret) selects the explicit client-credentials pair (which wins
over the environment).
Attributes:
| Name | Type | Description |
|---|---|---|
client_id |
str | None
|
OAuth client id, or |
client_secret |
SecretStr | None
|
OAuth client secret (kept as a |
profile |
str | None
|
A saved |
Examples:
- An empty object carries no id (the env / profile path):
- The secret is carried opaquely:
Source code in src/earthlens/sentinel_hub/auth.py
from_env()
classmethod
#
Build credentials from the SENTINELHUB_* (or SH_*) environment.
Reads the descriptive SENTINELHUB_CLIENT_ID / SENTINELHUB_CLIENT_SECRET
/ SENTINELHUB_PROFILE variables, falling back to the sentinelhub-py
native SH_CLIENT_ID / SH_CLIENT_SECRET / SH_PROFILE for users coming
from the SDK. Absent variables stay None.
Returns:
| Type | Description |
|---|---|
SentinelHubCredentials
|
The credentials object built from the environment. |
Source code in src/earthlens/sentinel_hub/auth.py
read_evalscript(filename)
#
Read a bundled evalscript .js file by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
str
|
The evalscript source. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When no such bundled evalscript exists. |
Source code in src/earthlens/sentinel_hub/catalog.py
earthlens.sentinel_hub.backend
#
Sentinel Hub server-side-render backend (raster or tabular output).
SentinelHub(AbstractDataSource) sends a bbox/geometry + time + an evalscript
to one of Sentinel Hub's request planes on CDSE (sh.dataspace.copernicus.eu,
free with a CDSE account); the server computes on-the-fly and earthlens
collects the result. Its closest siblings are the GEE and openEO backends — the
server does the band math / compositing / rendering and earthlens (a)
authenticates, (b) builds the request from a curated evalscript library, (c)
triggers, (d) collects the output.
A request is variables={collection_or_recipe: [band, ...]} plus a bbox + date
window. A key may name a collection (then an explicit evalscript= is
required) or an evalscript recipe (a bundled .js that pins its collection).
The plane is chosen by the api= kwarg ("process" / "async" / "batch" /
"statistical" / "batch-statistical"), auto-selected by request size +
whether a geometry= was supplied when api= is omitted.
Because it returns raster or tabular depending on api=, the backend is
OUTPUT_KIND="mixed" (a fixed class attribute, never mutated per-instance):
the EarthLens facade forwards aggregate= for {"raster", "mixed"}, and
aggregate= is supported on every plane (including the statistical plane, where
it maps to the Statistical aggregation_interval), so demoting the instance to
"tabular" would wrongly make the facade reject it.
SentinelHub
#
Bases: AbstractDataSource
Server-side Sentinel Hub backend on CDSE (raster or tabular by api=).
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
|
Source code in src/earthlens/sentinel_hub/backend.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 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 313 314 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 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 | |
__init__(start, end, variables, lat_lim, lon_lim, temporal_resolution='daily', path='', fmt='%Y-%m-%d', resolution=10.0, evalscript=None, endpoint=None, mosaicking_order=_DEFAULT_MOSAICKING_ORDER, api=None, geometry=None, maxcc=None, batch_output=None, client_id=None, client_secret=None, profile=None)
#
Initialise a Sentinel Hub backend instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str
|
Inclusive start date string (parsed with |
required |
end
|
str
|
Inclusive end date string. |
required |
variables
|
dict[str, list[str]]
|
|
required |
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
temporal_resolution
|
str
|
Advisory cadence label; the render window is
|
'daily'
|
path
|
Path | str
|
Output directory (created by the parent class). |
''
|
fmt
|
str
|
|
'%Y-%m-%d'
|
resolution
|
float
|
Output pixel size in metres (→ |
10.0
|
evalscript
|
str | None
|
A custom evalscript — an inline V3 JS string or a path to
a |
None
|
endpoint
|
str | None
|
Endpoint alias ( |
None
|
mosaicking_order
|
str
|
Per-pixel scene selection passed to
|
_DEFAULT_MOSAICKING_ORDER
|
api
|
str | None
|
The request plane ( |
None
|
geometry
|
Any
|
A shapely geometry / GeoJSON mapping / |
None
|
maxcc
|
float | None
|
Optional maximum cloud cover (0–1) passed to |
None
|
batch_output
|
dict[str, Any] | None
|
S3 delivery spec ( |
None
|
client_id
|
str | None
|
OAuth client id (else |
None
|
client_secret
|
str | None
|
OAuth client secret (else |
None
|
profile
|
str | None
|
A saved |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in src/earthlens/sentinel_hub/backend.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
download(progress_bar=True, aggregate=None)
#
Build the request(s), render server-side, and collect the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Reserved for parity with the other backends. |
True
|
aggregate
|
AggregationConfig | None
|
Optional aggregation request. Accepted (not rejected)
because |
None
|
Returns:
| Type | Description |
|---|---|
list[Any]
|
The written raster paths / table paths / S3 URIs, depending on the |
list[Any]
|
resolved plane. |
Source code in src/earthlens/sentinel_hub/backend.py
search(limit=100)
#
Query the Sentinel Hub Catalog API for scenes intersecting the request.
A real STAC-style search (distinct from the internal :meth:_search
fetch-planner): returns one :class:RemoteProduct per catalog item that
intersects the request bbox + window, so a caller can enumerate coverage
before rendering. An empty result is an empty list (not an error).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of items to return per requested collection. |
100
|
Returns:
| Type | Description |
|---|---|
list[RemoteProduct]
|
One product per catalog item (id + datetime + geometry on metadata). |
Source code in src/earthlens/sentinel_hub/backend.py
earthlens.sentinel_hub.catalog
#
Two-layer catalog for the Sentinel Hub backend: collections + evalscripts.
Sentinel Hub renders from an evalscript — there is no granule to fetch — so the
"catalog" has two layers (the headline design decision, G1):
- Collections — the underlying Sentinel Hub
DataCollections (SENTINEL2_L2A,SENTINEL1_IW,SENTINEL3_OLCI, …) with their bands. A request names a collection (plus an explicitevalscript=). - Evalscript recipes — a curated library of named, parametric
.jsfiles bundled underevalscripts/(sentinel-2-l2a-ndvi,…-true-colour, …), each fixing a base collection + the render logic. A recipe is either a"render"recipe (writes a raster) or a"stats"recipe (emits thedataMaskband the Statistical API requires). A request that names a recipe gets that fixed evalscript over its collection.
The catalog ships as a directory of YAML files at
src/earthlens/sentinel_hub/catalog/ (collections.yaml, recipes.yaml, plus
_index.yaml carrying the informational available_collections: index rebuilt
by tools/sentinel_hub/refresh_sh_catalog.py). The loader unions the per-file
collections: / recipes: blocks into one :class:Catalog (a key declared in
two files is a load-time error) and caches on (path, mtime_ns), the same way
the openEO / GEE / STAC catalogs do. The evalscript .js files live alongside
under evalscripts/ and are read at request time (not parsed here).
The bundled catalog directory lives at :data:CATALOG_PATH and the evalscript
directory at :data:EVALSCRIPTS_PATH; tests can monkey-patch either to redirect
the loader at a temporary directory.
Band
#
Bases: BaseModel
Per-band metadata for one band of a Sentinel Hub collection.
Frozen value object; the band name is the parent mapping key and is not repeated in the body. Every field is optional because band metadata is uneven across collections.
Attributes:
| Name | Type | Description |
|---|---|---|
common_name |
str | None
|
Common name ( |
description |
str | None
|
Human description of the band, or |
units |
str | None
|
Physical unit string, or |
resolution |
float | None
|
Native ground sample distance in metres, or |
center_wavelength |
float | None
|
Central wavelength in micrometres (optical), or |
Source code in src/earthlens/sentinel_hub/catalog.py
Catalog
#
Bases: AbstractCatalog
YAML-backed catalog of Sentinel Hub collections and evalscript recipes.
Reads every *.yaml under :data:CATALOG_PATH on construction and merges
them into typed :class:Collection / :class:EvalscriptRecipe models.
Collections are stored under the inherited :attr:datasets field (keyed by
logical key); recipes live in :attr:recipes; the informational index lives
in :attr:available_collections.
Attributes:
| Name | Type | Description |
|---|---|---|
datasets |
dict[str, Collection]
|
Logical collection key → :class: |
recipes |
dict[str, EvalscriptRecipe]
|
Recipe key → :class: |
available_collections |
list[str]
|
Every collection the backend can render (refreshed index; informational). |
Examples:
- A recipe resolves to its bundled evalscript; a collection to a bare bind:
- Resolving normalises both layers to one shape:
Source code in src/earthlens/sentinel_hub/catalog.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
get_collection(collection_key)
#
Return the :class:Collection for collection_key (did-you-mean on miss).
Alias of the inherited :meth:get_dataset, named for clarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_key
|
str
|
Logical collection key. |
required |
Returns:
| Type | Description |
|---|---|
Collection
|
The matching :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the key is unknown (message suggests the closest key). |
Source code in src/earthlens/sentinel_hub/catalog.py
get_recipe(recipe_key)
#
Return the :class:EvalscriptRecipe for recipe_key (did-you-mean on miss).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_key
|
str
|
Recipe key. |
required |
Returns:
| Type | Description |
|---|---|
EvalscriptRecipe
|
The matching :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the key is unknown (message suggests the closest key). |
Source code in src/earthlens/sentinel_hub/catalog.py
is_recipe(key)
#
Return whether key names a curated evalscript recipe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A logical collection or recipe key. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/earthlens/sentinel_hub/catalog.py
load(catalog_path=None)
classmethod
#
Read the Sentinel Hub catalog from disk (cached).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Catalog directory or single |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
Propagated from the loader. |
Source code in src/earthlens/sentinel_hub/catalog.py
model_post_init(__context)
#
Auto-load the bundled catalog when no rows were supplied.
Catalog() with no args reads the bundled catalog/ directory through
the (path, mtime)-keyed cache. If the caller passed datasets= or
recipes=, the disk read is skipped (in-memory catalogs for tests).
The base available_datasets field is mirrored from
available_collections so the index is discoverable through the
AbstractCatalog contract, then super().model_post_init populates
catalog from get_catalog().
Raises:
| Type | Description |
|---|---|
ValueError
|
When auto-loading, propagates the loader's errors. |
Source code in src/earthlens/sentinel_hub/catalog.py
resolve(key)
#
Resolve a collection-or-recipe key to a uniform :class:ResolvedRequest.
A recipe resolves to its bundled evalscript + bands + kind; a plain
collection resolves with evalscript=None and its default bands (the
backend then requires an explicit evalscript=).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A logical collection or recipe key. |
required |
Returns:
| Type | Description |
|---|---|
ResolvedRequest
|
The normalised :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- A recipe carries its evalscript + kind:
Source code in src/earthlens/sentinel_hub/catalog.py
Collection
#
Bases: BaseModel
One curated Sentinel Hub data collection, addressed by a logical key.
Attributes:
| Name | Type | Description |
|---|---|---|
sh_collection |
str
|
The |
bands |
dict[str, Band]
|
Band name → :class: |
default_bands |
list[str]
|
Bands used when the request names none. Falls back to
every key of |
cadence |
str | None
|
Native revisit cadence label, or |
resolution |
float | None
|
Native ground sample distance in metres, or |
extent |
Extent | None
|
Spatial/temporal coverage, or |
description |
str | None
|
One-line human summary, or |
Source code in src/earthlens/sentinel_hub/catalog.py
effective_bands
property
#
The band names to request by default (default_bands, else all bands).
EvalscriptRecipe
#
Bases: BaseModel
One curated evalscript recipe fixing a base collection + a .js file.
Attributes:
| Name | Type | Description |
|---|---|---|
base_collection |
str
|
The |
evalscript |
str
|
The bundled |
bands |
list[str]
|
The collection bands the evalscript consumes (informational + used by the refresh/validate tool). |
output_bands |
int
|
The number of bands the evalscript writes. |
kind |
str
|
|
description |
str | None
|
One-line human summary, or |
Source code in src/earthlens/sentinel_hub/catalog.py
Extent
#
Bases: BaseModel
Spatial/temporal coverage of a Sentinel Hub collection.
Attributes:
| Name | Type | Description |
|---|---|---|
start_date |
str | None
|
First available date ( |
end_date |
str | None
|
Last available date, or |
bbox |
tuple[float, float, float, float] | None
|
|
Source code in src/earthlens/sentinel_hub/catalog.py
ResolvedRequest
#
Bases: BaseModel
The uniform shape a resolved collection-or-recipe key takes.
Both a plain collection and a recipe resolve to this so the backend's
request-builder consumes one type. A plain collection resolves with
evalscript=None (the backend must then have an explicit evalscript=); a
recipe carries its bundled .js filename.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
The logical key the request named. |
sh_collection |
str
|
The |
bands |
list[str]
|
The bands to request (request override applied by the backend). |
evalscript |
str | None
|
The bundled |
output_bands |
int
|
Number of output bands the evalscript writes. |
is_recipe |
bool
|
Whether the key named a recipe (vs a plain collection). |
kind |
str
|
|
Source code in src/earthlens/sentinel_hub/catalog.py
read_evalscript(filename)
#
Read a bundled evalscript .js file by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
str
|
The evalscript source. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When no such bundled evalscript exists. |
Source code in src/earthlens/sentinel_hub/catalog.py
earthlens.sentinel_hub.auth
#
OAuth2 client-credentials authentication for the Sentinel Hub backend.
Hosts :class:SentinelHubAuth, a thin wrapper that builds and holds a
sentinelhub.SHConfig. Unlike the openEO backend's interactive OIDC device
flow, Sentinel Hub authenticates non-interactively with an OAuth2
client-credentials pair (a client_id / client_secret minted in the CDSE
Dashboard) — closest to GEE's service-account model. sentinelhub-py mints and
refreshes the bearer token internally from the config, so there is no explicit
login step here: :meth:SentinelHubAuth.configure only assembles the
SHConfig (base URL, token URL, credentials).
The credential resolution order in :meth:SentinelHubAuth.configure is:
- environment —
SENTINELHUB_CLIENT_ID/SENTINELHUB_CLIENT_SECRET(withSH_CLIENT_ID/SH_CLIENT_SECRETaccepted as asentinelhub-py-native fallback). - kwargs — an explicit
client_id/client_secreton the credentials object (these win over the environment). - saved profile — a named
SHConfigprofile written earlier withSHConfig.save(profile)(used when neither of the above is set).
endpoint= switches the CDSE-free deployment (the default) and the commercial
one (services.sentinel-hub.com, a different token URL). Any failure is wrapped
as :class:AuthenticationError with a pointer at the CDSE Dashboard OAuth-client
page, never a raw sentinelhub exception.
AuthenticationError
#
Bases: AuthenticationError
Raised when the Sentinel Hub SHConfig cannot be assembled.
Wraps the missing-credentials case with an actionable message pointing at
the CDSE Dashboard. A subclass of the cross-backend
:class:earthlens.base.AuthenticationError so callers can catch every
backend's auth failure with one except clause.
Source code in src/earthlens/sentinel_hub/auth.py
SentinelHubAuth
#
Bases: AbstractAuth[SentinelHubCredentials]
Assemble and hold a Sentinel Hub SHConfig (non-interactive OAuth2).
Conforms to the cross-backend :class:earthlens.base.AbstractAuth contract:
:meth:configure builds the SHConfig lazily and idempotently;
:meth:is_authenticated is the cheap predicate; and :meth:config returns
the configured SHConfig (configuring on first use). The token itself is
minted and refreshed by sentinelhub-py from the config on the first
request — there is no interactive flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
SentinelHubCredentials | None
|
The OAuth credentials. Defaults to an empty
:class: |
None
|
endpoint
|
str | None
|
A named endpoint alias ( |
None
|
Examples:
- Construct against CDSE-free (no config built until
configure()):
Source code in src/earthlens/sentinel_hub/auth.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
base_url
property
#
The resolved Sentinel Hub base URL this auth targets.
__init__(credentials=None, endpoint=None)
#
Store the credentials + resolved endpoint; does not build the config yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
SentinelHubCredentials | None
|
OAuth credentials, or |
None
|
endpoint
|
str | None
|
Endpoint alias or base URL; resolved eagerly so a bad alias fails at construction. |
None
|
Source code in src/earthlens/sentinel_hub/auth.py
config()
#
Return the assembled SHConfig, configuring on first use.
Returns:
| Type | Description |
|---|---|
Any
|
The |
Raises:
| Type | Description |
|---|---|
ImportError
|
When the |
AuthenticationError
|
When no credentials are resolvable. |
Source code in src/earthlens/sentinel_hub/auth.py
configure()
#
Build the SHConfig (base/token urls + credentials); idempotent.
Resolves credentials env → kwargs → profile. A second call after
:meth:is_authenticated returns True is a no-op.
Raises:
| Type | Description |
|---|---|
ImportError
|
When the |
AuthenticationError
|
When no credentials are resolvable (no id/secret and no profile). |
Source code in src/earthlens/sentinel_hub/auth.py
is_authenticated()
#
True once :meth:configure has assembled an SHConfig.
Cheap predicate — does not call the network. Returns True exactly when
a config object has been built.
Returns:
| Type | Description |
|---|---|
bool
|
Whether the |
Source code in src/earthlens/sentinel_hub/auth.py
SentinelHubCredentials
#
Bases: BaseModel
Frozen value object holding the Sentinel Hub OAuth credentials.
All fields are optional: an empty object falls back to the
SENTINELHUB_CLIENT_ID / SENTINELHUB_CLIENT_SECRET environment (or the
SH_* fallback), then to the named profile. Supplying client_id
(+ client_secret) selects the explicit client-credentials pair (which wins
over the environment).
Attributes:
| Name | Type | Description |
|---|---|---|
client_id |
str | None
|
OAuth client id, or |
client_secret |
SecretStr | None
|
OAuth client secret (kept as a |
profile |
str | None
|
A saved |
Examples:
- An empty object carries no id (the env / profile path):
- The secret is carried opaquely:
Source code in src/earthlens/sentinel_hub/auth.py
from_env()
classmethod
#
Build credentials from the SENTINELHUB_* (or SH_*) environment.
Reads the descriptive SENTINELHUB_CLIENT_ID / SENTINELHUB_CLIENT_SECRET
/ SENTINELHUB_PROFILE variables, falling back to the sentinelhub-py
native SH_CLIENT_ID / SH_CLIENT_SECRET / SH_PROFILE for users coming
from the SDK. Absent variables stay None.
Returns:
| Type | Description |
|---|---|
SentinelHubCredentials
|
The credentials object built from the environment. |
Source code in src/earthlens/sentinel_hub/auth.py
earthlens.sentinel_hub._dispatch
#
Request-plane selection for the Sentinel Hub backend.
Pure, network-free helpers that decide which request plane a download uses.
The backend passes the resolved render size (px/side) and whether a geometry=
was supplied; these functions return the plane name (one of
:data:earthlens.sentinel_hub._helpers.VALID_APIS). Kept separate from
backend.py so the routing rules are unit-testable in isolation.
The auto-routing rule (G4 / G5), when api= is omitted:
- a
geometry=request →"statistical"(zonal stats over the polygon); - otherwise a raster render routed by size:
≤ SH_MAX_DIMENSION→"process"; larger →"async"(within the Async ceiling) /"batch"(above it) when an S3batch_outputis configured, else"tiling"(the local split + mosaic path, which needs no S3 bucket).
An explicit api= is honoured verbatim (only validated), so a user can force
"process" on a request the auto-rule would route elsewhere — the size guard in
the backend then raises if that forced plane cannot satisfy the request.
auto_select_api(max_side_px, has_geometry, has_s3=False)
#
Pick the plane for a request when api= was omitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_side_px
|
int
|
The larger of the render's two pixel dimensions. |
required |
has_geometry
|
bool
|
Whether a |
required |
has_s3
|
bool
|
Whether an S3 |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The selected plane name. |
Examples:
- A geometry request goes to the Statistical plane:
- A small raster goes to Process; an oversized one without S3 to tiling:
- With an S3 bucket, oversized rasters go to async / batch:
Source code in src/earthlens/sentinel_hub/_dispatch.py
resolve_api(api, max_side_px, has_geometry, has_s3=False)
#
Validate an explicit api=, or auto-select one by size / geometry / S3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api
|
str | None
|
The requested plane, or |
required |
max_side_px
|
int
|
The larger render dimension in pixels. |
required |
has_geometry
|
bool
|
Whether a |
required |
has_s3
|
bool
|
Whether an S3 |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The resolved plane name. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in src/earthlens/sentinel_hub/_dispatch.py
validate_api(api)
#
Validate an explicit api= value, if any.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api
|
str | None
|
The requested plane, or |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in src/earthlens/sentinel_hub/_dispatch.py
earthlens.sentinel_hub._helpers
#
Stateless helpers for the Sentinel Hub backend.
Hosts the small, pure functions and constant tables the backend, auth, and
dispatch modules share: the request-plane vocabulary (VALID_APIS), the
endpoint registry (CDSE-free vs commercial), the Process/Async pixel ceilings
(SH_MAX_DIMENSION / ASYNC_MAX_DIMENSION), the lazy sentinelhub SDK importer
(which turns a missing [sentinel-hub] extra into a friendly ImportError), the
CDSE data-collection binding (cdse_collection), and the pandas-frequency →
Statistical aggregation_interval (ISO-8601) mapping used by aggregate=.
None of these touch the network, so they are trivially unit testable and safe to
import without the sentinelhub SDK installed (the SDK is imported only inside
import_sentinelhub / cdse_collection, never at module load).
cdse_collection(name, base_url)
#
Bind a DataCollection name to the CDSE deployment (or return it as-is).
The stock sentinelhub.DataCollection enum members point at the commercial
deployment, so on CDSE each must be rebound to the CDSE service URL via
DataCollection.<NAME>.define_from(..., service_url=base_url) (verified, A1).
On a commercial base_url the stock member is returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A |
required |
base_url
|
str
|
The configured |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The (possibly rebound) |
Raises:
| Type | Description |
|---|---|
ImportError
|
When the |
ValueError
|
When |
Source code in src/earthlens/sentinel_hub/_helpers.py
import_sentinelhub()
#
Import and return the sentinelhub SDK, or raise a friendly ImportError.
The SDK is an optional dependency (pip install earthlens[sentinel-hub]);
this helper centralises the lazy import so every call site surfaces the same
actionable message when the extra is missing.
Returns:
| Type | Description |
|---|---|
Any
|
The imported |
Raises:
| Type | Description |
|---|---|
ImportError
|
When the |
Source code in src/earthlens/sentinel_hub/_helpers.py
interval_for(freq)
#
Map a pandas frequency alias to a Statistical aggregation_interval.
Strips any leading repeat count ("1MS" → "MS") before the lookup, except
for the count-prefixed day windows ("7D", "10D") handled directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
str
|
A pandas offset alias, optionally count-prefixed ( |
required |
Returns:
| Type | Description |
|---|---|
str
|
The ISO-8601 duration string the Statistical API expects ( |
str
|
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
Examples:
- Month-start maps to a one-month interval:
- A daily window maps to
P1D:
Source code in src/earthlens/sentinel_hub/_helpers.py
resolve_endpoint(endpoint)
#
Resolve an endpoint= value to a (base_url, token_url) pair.
Accepts a named alias ("cdse", "commercial"), a full http(s):// base
URL (paired with the matching token URL by host), or None (the CDSE-free
default).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str | None
|
A named alias, a full base URL, or |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
- The default alias resolves to CDSE-free:
- A full URL on a CDSE host keeps the CDSE Keycloak token URL:
Source code in src/earthlens/sentinel_hub/_helpers.py
tile_bbox(bbox, width_px, height_px, max_dim=SH_MAX_DIMENSION)
#
Split a bbox into a grid of sub-bboxes each ≤ max_dim px per side.
Request-shaping arithmetic for the Process-API 2500 px cap: the bbox is
divided into ceil(width_px / max_dim) × ceil(height_px / max_dim) equal
tiles in degree space (row-major, south-to-north then west-to-east). The
mosaic of the rendered tiles is the responsibility of pyramids — this only
decides the windows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
tuple[float, float, float, float]
|
The |
required |
width_px
|
int
|
The full render width in pixels (at the target resolution). |
required |
height_px
|
int
|
The full render height in pixels. |
required |
max_dim
|
int
|
The per-tile pixel ceiling (defaults to :data: |
SH_MAX_DIMENSION
|
Returns:
| Type | Description |
|---|---|
list[tuple[float, float, float, float]]
|
The list of |
Examples:
- A render within the cap is a single tile (the bbox itself):
- A 2× oversized render splits into a 2×2 grid: