sfeos-helpers 5.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,558 @@
1
+ Metadata-Version: 2.1
2
+ Name: sfeos-helpers
3
+ Version: 5.0.0
4
+ Summary: Helper library for the Elasticsearch and Opensearch stac-fastapi backends.
5
+ Home-page: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch
6
+ License: MIT
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: Intended Audience :: Information Technology
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: stac-fastapi.core==5.0.0
19
+
20
+ # stac-fastapi-elasticsearch-opensearch
21
+
22
+ <!-- markdownlint-disable MD033 MD041 -->
23
+
24
+
25
+ <p align="left">
26
+ <img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/sfeos.png" width=1000>
27
+ </p>
28
+
29
+ **Jump to:** [Project Introduction](#project-introduction---what-is-sfeos) | [Quick Start](#quick-start) | [Table of Contents](#table-of-contents)
30
+
31
+ [![Downloads](https://static.pepy.tech/badge/stac-fastapi-core?color=blue)](https://pepy.tech/project/stac-fastapi-core)
32
+ [![GitHub contributors](https://img.shields.io/github/contributors/stac-utils/stac-fastapi-elasticsearch-opensearch?color=blue)](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/graphs/contributors)
33
+ [![GitHub stars](https://img.shields.io/github/stars/stac-utils/stac-fastapi-elasticsearch-opensearch.svg?color=blue)](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/stargazers)
34
+ [![GitHub forks](https://img.shields.io/github/forks/stac-utils/stac-fastapi-elasticsearch-opensearch.svg?color=blue)](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/network/members)
35
+ [![PyPI version](https://img.shields.io/pypi/v/stac-fastapi-elasticsearch.svg?color=blue)](https://pypi.org/project/stac-fastapi-elasticsearch/)
36
+ [![STAC](https://img.shields.io/badge/STAC-1.1.0-blue.svg)](https://github.com/radiantearth/stac-spec/tree/v1.1.0)
37
+ [![stac-fastapi](https://img.shields.io/badge/stac--fastapi-5.2.0-blue.svg)](https://github.com/stac-utils/stac-fastapi)
38
+
39
+ ## Sponsors & Supporters
40
+
41
+ The following organizations have contributed time and/or funding to support the development of this project:
42
+
43
+ <p align="left">
44
+ <a href="https://healy-hyperspatial.github.io/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/hh-logo-blue.png" alt="Healy Hyperspatial" height="100" hspace="20"></a>
45
+ <a href="https://atomicmaps.io/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/am-logo-black.png" alt="Atomic Maps" height="100" hspace="20"></a>
46
+ <a href="https://remotesensing.vito.be/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/VITO.png" alt="VITO Remote Sensing" height="100" hspace="20"></a>
47
+ </p>
48
+
49
+ ## Project Introduction - What is SFEOS?
50
+
51
+ SFEOS (stac-fastapi-elasticsearch-opensearch) is a high-performance, scalable API implementation for serving SpatioTemporal Asset Catalog (STAC) data - an enhanced GeoJSON format designed specifically for geospatial assets like satellite imagery, aerial photography, and other Earth observation data. This project enables organizations to:
52
+
53
+ - **Efficiently catalog and search geospatial data** such as satellite imagery, aerial photography, DEMs, and other geospatial assets using Elasticsearch or OpenSearch as the database backend
54
+ - **Implement standardized STAC APIs** that support complex spatial, temporal, and property-based queries across large collections of geospatial data
55
+ - **Scale to millions of geospatial assets** with fast search performance through optimized spatial indexing and query capabilities
56
+ - **Support OGC-compliant filtering** including spatial operations (intersects, contains, etc.) and temporal queries
57
+ - **Perform geospatial aggregations** to analyze data distribution across space and time
58
+
59
+ This implementation builds on the STAC-FastAPI framework, providing a production-ready solution specifically optimized for Elasticsearch and OpenSearch databases. It's ideal for organizations managing large geospatial data catalogs who need efficient discovery and access capabilities through standardized APIs.
60
+
61
+
62
+
63
+ ## Common Deployment Patterns
64
+
65
+ stac-fastapi-elasticsearch-opensearch can be deployed in several ways depending on your needs:
66
+
67
+ - **Containerized Application**: Run as a Docker container with connections to Elasticsearch/OpenSearch databases
68
+ - **Serverless Function**: Deploy as AWS Lambda or similar serverless function with API Gateway
69
+ - **Traditional Server**: Run on virtual machines or bare metal servers in your infrastructure
70
+ - **Kubernetes**: Deploy as part of a larger microservices architecture with container orchestration
71
+
72
+ The implementation is flexible and can scale from small local deployments to large production environments serving millions of geospatial assets.
73
+
74
+ ## Technologies
75
+
76
+ This project is built on the following technologies: STAC, stac-fastapi, FastAPI, Elasticsearch, Python, OpenSearch
77
+
78
+ <p align="left">
79
+ <a href="https://stacspec.org/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/STAC-01.png" alt="STAC" height="100" hspace="10"></a>
80
+ <a href="https://www.python.org/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/python.png" alt="Python" height="80" hspace="10"></a>
81
+ <a href="https://fastapi.tiangolo.com/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/fastapi.svg" alt="FastAPI" height="80" hspace="10"></a>
82
+ <a href="https://www.elastic.co/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/elasticsearch.png" alt="Elasticsearch" height="80" hspace="10"></a>
83
+ <a href="https://opensearch.org/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/opensearch.svg" alt="OpenSearch" height="80" hspace="10"></a>
84
+ </p>
85
+
86
+ ## Table of Contents
87
+
88
+ - [Documentation & Resources](#documentation--resources)
89
+ - [Package Structure](#package-structure)
90
+ - [Examples](#examples)
91
+ - [Performance](#performance)
92
+ - [Quick Start](#quick-start)
93
+ - [Installation](#installation)
94
+ - [Running Locally](#running-locally)
95
+ - [Configuration reference](#configuration-reference)
96
+ - [Interacting with the API](#interacting-with-the-api)
97
+ - [Configure the API](#configure-the-api)
98
+ - [Collection pagination](#collection-pagination)
99
+ - [Ingesting Sample Data CLI Tool](#ingesting-sample-data-cli-tool)
100
+ - [Elasticsearch Mappings](#elasticsearch-mappings)
101
+ - [Managing Elasticsearch Indices](#managing-elasticsearch-indices)
102
+ - [Snapshots](#snapshots)
103
+ - [Reindexing](#reindexing)
104
+ - [Auth](#auth)
105
+ - [Aggregation](#aggregation)
106
+ - [Rate Limiting](#rate-limiting)
107
+
108
+ ## Documentation & Resources
109
+
110
+ - **Online Documentation**: [https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch](https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch/)
111
+ - **Source Code**: [https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch)
112
+ - **API Examples**: [Postman Documentation](https://documenter.getpostman.com/view/12888943/2s8ZDSdRHA) - Examples of how to use the API endpoints
113
+ - **Community**:
114
+ - [Gitter Chat](https://app.gitter.im/#/room/#stac-fastapi-elasticsearch_community:gitter.im) - For real-time discussions
115
+ - [GitHub Discussions](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/discussions) - For longer-form questions and answers
116
+
117
+ ## Package Structure
118
+
119
+ This project is organized into several packages, each with a specific purpose:
120
+
121
+ - **stac_fastapi_core**: Core functionality that's database-agnostic, including API models, extensions, and shared utilities. This package provides the foundation for building STAC API implementations with any database backend. See [stac-fastapi-mongo](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo) for a working example.
122
+
123
+ - **sfeos_helpers**: Shared helper functions and utilities used by both the Elasticsearch and OpenSearch backends. This package includes:
124
+ - `database`: Specialized modules for index, document, and database utility operations
125
+ - `aggregation`: Elasticsearch/OpenSearch-specific aggregation functionality
126
+ - Shared logic and utilities that improve code reuse between backends
127
+
128
+ - **stac_fastapi_elasticsearch**: Complete implementation of the STAC API using Elasticsearch as the backend database. This package depends on both `stac_fastapi_core` and `sfeos_helpers`.
129
+ -
130
+ - **stac_fastapi_opensearch**: Complete implementation of the STAC API using OpenSearch as the backend database. This package depends on both `stac_fastapi_core` and `sfeos_helpers`.
131
+
132
+ ## Examples
133
+
134
+ The `/examples` directory contains several useful examples and reference implementations:
135
+
136
+ - **pip_docker**: Examples of running stac-fastapi-elasticsearch from PyPI in Docker without needing any code from the repository
137
+ - **auth**: Authentication examples including:
138
+ - Basic authentication
139
+ - OAuth2 with Keycloak
140
+ - Route dependencies configuration
141
+ - **rate_limit**: Example of implementing rate limiting for API requests
142
+ - **postman_collections**: Postman collection files you can import for testing API endpoints
143
+
144
+ These examples provide practical reference implementations for various deployment scenarios and features.
145
+
146
+ ## Performance
147
+
148
+ ### Direct Response Mode
149
+
150
+ - The `enable_direct_response` option is provided by the stac-fastapi core library (introduced in stac-fastapi 5.2.0) and is available in this project starting from v4.0.0.
151
+ - **Control via environment variable**: Set `ENABLE_DIRECT_RESPONSE=true` to enable this feature.
152
+ - **How it works**: When enabled, endpoints return Starlette Response objects directly, bypassing FastAPI's default serialization for improved performance.
153
+ - **Important limitation**: All FastAPI dependencies (including authentication, custom status codes, and validation) are disabled for all routes when this mode is enabled.
154
+ - **Best use case**: This mode is best suited for public or read-only APIs where authentication and custom logic are not required.
155
+ - **Default setting**: `false` for safety.
156
+ - **More information**: See [issue #347](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/issues/347) for background and implementation details.
157
+
158
+ ## Quick Start
159
+
160
+ This section helps you get up and running with stac-fastapi-elasticsearch-opensearch quickly.
161
+
162
+ ### Installation
163
+
164
+ - **For versions 4.0.0a1 and newer** (PEP 625 compliant naming):
165
+ ```bash
166
+ pip install stac-fastapi-elasticsearch # Elasticsearch backend
167
+ pip install stac-fastapi-opensearch # Opensearch backend
168
+ pip install stac-fastapi-core # Core library
169
+ ```
170
+
171
+ - **For versions 4.0.0a0 and older**:
172
+ ```bash
173
+ pip install stac-fastapi.elasticsearch # Elasticsearch backend
174
+ pip install stac-fastapi.opensearch # Opensearch backend
175
+ pip install stac-fastapi.core # Core library
176
+ ```
177
+
178
+ > **Important Note:** Starting with version 4.0.0a1, package names have changed from using periods (e.g., `stac-fastapi.core`) to using hyphens (e.g., `stac-fastapi-core`) to comply with PEP 625. The internal package structure uses underscores, but users should install with hyphens as shown above. Please update your requirements files accordingly.
179
+
180
+ ### Running Locally
181
+
182
+ There are two main ways to run the API locally:
183
+
184
+ #### Using Pre-built Docker Images
185
+
186
+ - We provide ready-to-use Docker images through GitHub Container Registry:
187
+ - [ElasticSearch backend](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pkgs/container/stac-fastapi-es)
188
+ - [OpenSearch backend](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pkgs/container/stac-fastapi-os)
189
+
190
+ - **Pull and run the images**:
191
+ ```shell
192
+ # For Elasticsearch backend
193
+ docker pull ghcr.io/stac-utils/stac-fastapi-es:latest
194
+
195
+ # For OpenSearch backend
196
+ docker pull ghcr.io/stac-utils/stac-fastapi-os:latest
197
+ ```
198
+
199
+ #### Using Docker Compose
200
+
201
+ - **Prerequisites**: Ensure [Docker Compose](https://docs.docker.com/compose/install/) or [Podman Compose](https://podman-desktop.io/docs/compose) is installed on your machine.
202
+
203
+ - **Start the API**:
204
+ ```shell
205
+ docker compose up elasticsearch app-elasticsearch
206
+ ```
207
+
208
+ - **Configuration**: By default, Docker Compose uses Elasticsearch 8.x and OpenSearch 2.11.1. To use different versions, create a `.env` file:
209
+ ```shell
210
+ ELASTICSEARCH_VERSION=8.11.0
211
+ OPENSEARCH_VERSION=2.11.1
212
+ ENABLE_DIRECT_RESPONSE=false
213
+ ```
214
+
215
+ - **Compatibility**: The most recent Elasticsearch 7.x versions should also work. See the [opensearch-py docs](https://github.com/opensearch-project/opensearch-py/blob/main/COMPATIBILITY.md) for compatibility information.
216
+
217
+
218
+
219
+ ## Configuration Reference
220
+
221
+ You can customize additional settings in your `.env` file:
222
+
223
+ | Variable | Description | Default | Required |
224
+ |------------------------------|--------------------------------------------------------------------------------------|--------------------------|---------------------------------------------------------------------------------------------|
225
+ | `ES_HOST` | Hostname for external Elasticsearch/OpenSearch. | `localhost` | Optional |
226
+ | `ES_PORT` | Port for Elasticsearch/OpenSearch. | `9200` (ES) / `9202` (OS)| Optional |
227
+ | `ES_USE_SSL` | Use SSL for connecting to Elasticsearch/OpenSearch. | `false` | Optional |
228
+ | `ES_VERIFY_CERTS` | Verify SSL certificates when connecting. | `false` | Optional |
229
+ | `STAC_FASTAPI_TITLE` | Title of the API in the documentation. | `stac-fastapi-<backend>` | Optional |
230
+ | `STAC_FASTAPI_DESCRIPTION` | Description of the API in the documentation. | N/A | Optional |
231
+ | `STAC_FASTAPI_VERSION` | API version. | `2.1` | Optional |
232
+ | `STAC_FASTAPI_LANDING_PAGE_ID` | Landing page ID | `stac-fastapi` | Optional |
233
+ | `APP_HOST` | Server bind address. | `0.0.0.0` | Optional |
234
+ | `APP_PORT` | Server port. | `8080` | Optional |
235
+ | `ENVIRONMENT` | Runtime environment. | `local` | Optional |
236
+ | `WEB_CONCURRENCY` | Number of worker processes. | `10` | Optional |
237
+ | `RELOAD` | Enable auto-reload for development. | `true` | Optional |
238
+ | `STAC_FASTAPI_RATE_LIMIT` | API rate limit per client. | `200/minute` | Optional |
239
+ | `BACKEND` | Tests-related variable | `elasticsearch` or `opensearch` based on the backend | Optional |
240
+ | `ELASTICSEARCH_VERSION` | Version of Elasticsearch to use. | `8.11.0` | Optional | |
241
+ | `OPENSEARCH_VERSION` | OpenSearch version | `2.11.1` | Optional
242
+ | `ENABLE_DIRECT_RESPONSE` | Enable direct response for maximum performance (disables all FastAPI dependencies, including authentication, custom status codes, and validation) | `false` | Optional
243
+ | `RAISE_ON_BULK_ERROR` | Controls whether bulk insert operations raise exceptions on errors. If set to `true`, the operation will stop and raise an exception when an error occurs. If set to `false`, errors will be logged, and the operation will continue. **Note:** STAC Item and ItemCollection validation errors will always raise, regardless of this flag. | `false` Optional |
244
+ | `DATABASE_REFRESH` | Controls whether database operations refresh the index immediately after changes. If set to `true`, changes will be immediately searchable. If set to `false`, changes may not be immediately visible but can improve performance for bulk operations. If set to `wait_for`, changes will wait for the next refresh cycle to become visible. | `false` | Optional |
245
+ | `ENABLE_TRANSACTIONS_EXTENSIONS` | Enables or disables the Transactions and Bulk Transactions API extensions. If set to `false`, the POST `/collections` route and related transaction endpoints (including bulk transaction operations) will be unavailable in the API. This is useful for deployments where mutating the catalog via the API should be prevented. | `true` | Optional |
246
+
247
+ > [!NOTE]
248
+ > The variables `ES_HOST`, `ES_PORT`, `ES_USE_SSL`, and `ES_VERIFY_CERTS` apply to both Elasticsearch and OpenSearch backends, so there is no need to rename the key names to `OS_` even if you're using OpenSearch.
249
+
250
+ ## Interacting with the API
251
+
252
+ - **Creating a Collection**:
253
+ ```shell
254
+ curl -X "POST" "http://localhost:8080/collections" \
255
+ -H 'Content-Type: application/json; charset=utf-8' \
256
+ -d $'{
257
+ "id": "my_collection"
258
+ }'
259
+ ```
260
+
261
+ - **Adding an Item to a Collection**:
262
+ ```shell
263
+ curl -X "POST" "http://localhost:8080/collections/my_collection/items" \
264
+ -H 'Content-Type: application/json; charset=utf-8' \
265
+ -d @item.json
266
+ ```
267
+
268
+ - **Searching for Items**:
269
+ ```shell
270
+ curl -X "GET" "http://localhost:8080/search" \
271
+ -H 'Content-Type: application/json; charset=utf-8' \
272
+ -d $'{
273
+ "collections": ["my_collection"],
274
+ "limit": 10
275
+ }'
276
+ ```
277
+
278
+ - **Filtering by Bbox**:
279
+ ```shell
280
+ curl -X "GET" "http://localhost:8080/search" \
281
+ -H 'Content-Type: application/json; charset=utf-8' \
282
+ -d $'{
283
+ "collections": ["my_collection"],
284
+ "bbox": [-180, -90, 180, 90]
285
+ }'
286
+ ```
287
+
288
+ - **Filtering by Datetime**:
289
+ ```shell
290
+ curl -X "GET" "http://localhost:8080/search" \
291
+ -H 'Content-Type: application/json; charset=utf-8' \
292
+ -d $'{
293
+ "collections": ["my_collection"],
294
+ "datetime": "2020-01-01T00:00:00Z/2020-12-31T23:59:59Z"
295
+ }'
296
+ ```
297
+
298
+ ## Configure the API
299
+
300
+ - **API Title and Description**: By default set to `stac-fastapi-<backend>`. Customize these by setting:
301
+ - `STAC_FASTAPI_TITLE`: Changes the API title in the documentation
302
+ - `STAC_FASTAPI_DESCRIPTION`: Changes the API description in the documentation
303
+
304
+ - **Database Indices**: By default, the API reads from and writes to:
305
+ - `collections` index for collections
306
+ - `items_<collection name>` indices for items
307
+ - Customize with `STAC_COLLECTIONS_INDEX` and `STAC_ITEMS_INDEX_PREFIX` environment variables
308
+
309
+ - **Root Path Configuration**: The application root path is the base URL by default.
310
+ - For AWS Lambda with Gateway API: Set `STAC_FASTAPI_ROOT_PATH` to match the Gateway API stage name (e.g., `/v1`)
311
+
312
+
313
+ ## Collection Pagination
314
+
315
+ - **Overview**: The collections route supports pagination through optional query parameters.
316
+ - **Parameters**:
317
+ - `limit`: Controls the number of collections returned per page
318
+ - `token`: Used to retrieve subsequent pages of results
319
+ - **Response Structure**: The `links` field in the response contains a `next` link with the token for the next page of results.
320
+ - **Example Usage**:
321
+ ```shell
322
+ curl -X "GET" "http://localhost:8080/collections?limit=1&token=example_token"
323
+ ```
324
+
325
+ ## Ingesting Sample Data CLI Tool
326
+
327
+ - **Overview**: The `data_loader.py` script provides a convenient way to load STAC items into the database.
328
+
329
+ - **Usage**:
330
+ ```shell
331
+ python3 data_loader.py --base-url http://localhost:8080
332
+ ```
333
+
334
+ - **Options**:
335
+ ```
336
+ --base-url TEXT Base URL of the STAC API [required]
337
+ --collection-id TEXT ID of the collection to which items are added
338
+ --use-bulk Use bulk insert method for items
339
+ --data-dir PATH Directory containing collection.json and feature
340
+ collection file
341
+ --help Show this message and exit.
342
+ ```
343
+
344
+ - **Example Workflows**:
345
+ - **Loading Sample Data**:
346
+ ```shell
347
+ python3 data_loader.py --base-url http://localhost:8080
348
+ ```
349
+ - **Loading Data to a Specific Collection**:
350
+ ```shell
351
+ python3 data_loader.py --base-url http://localhost:8080 --collection-id my-collection
352
+ ```
353
+ - **Using Bulk Insert for Performance**:
354
+ ```shell
355
+ python3 data_loader.py --base-url http://localhost:8080 --use-bulk
356
+ ```
357
+
358
+ ## Elasticsearch Mappings
359
+
360
+ - **Overview**: Mappings apply to search index, not source data. They define how documents and their fields are stored and indexed.
361
+ - **Implementation**:
362
+ - Mappings are stored in index templates that are created on application startup
363
+ - These templates are automatically applied when creating new Collection and Item indices
364
+ - The `sfeos_helpers` package contains shared mapping definitions used by both Elasticsearch and OpenSearch backends
365
+ - **Customization**: Custom mappings can be defined by extending the base mapping templates.
366
+
367
+ ## Managing Elasticsearch Indices
368
+
369
+ ### Snapshots
370
+
371
+ - **Overview**: Snapshots provide a way to backup and restore your indices.
372
+
373
+ - **Creating a Snapshot Repository**:
374
+ ```shell
375
+ curl -X "PUT" "http://localhost:9200/_snapshot/my_fs_backup" \
376
+ -H 'Content-Type: application/json; charset=utf-8' \
377
+ -d $'{
378
+ "type": "fs",
379
+ "settings": {
380
+ "location": "/usr/share/elasticsearch/snapshots/my_fs_backup"
381
+ }
382
+ }'
383
+ ```
384
+ - This creates a snapshot repository that stores files in the elasticsearch/snapshots directory in this git repo clone
385
+ - The elasticsearch.yml and compose files create a mapping from that directory to /usr/share/elasticsearch/snapshots within the Elasticsearch container and grant permissions for using it
386
+
387
+ - **Creating a Snapshot**:
388
+ ```shell
389
+ curl -X "PUT" "http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2?wait_for_completion=true" \
390
+ -H 'Content-Type: application/json; charset=utf-8' \
391
+ -d $'{
392
+ "metadata": {
393
+ "taken_because": "dump of all items",
394
+ "taken_by": "pvarner"
395
+ },
396
+ "include_global_state": false,
397
+ "ignore_unavailable": false,
398
+ "indices": "items_my-collection"
399
+ }'
400
+ ```
401
+ - This creates a snapshot named my_snapshot_2 and waits for the action to be completed before returning
402
+ - This can also be done asynchronously by omitting the wait_for_completion parameter, and queried for status later
403
+ - The indices parameter determines which indices are snapshotted, and can include wildcards
404
+
405
+ - **Viewing Snapshots**:
406
+ ```shell
407
+ # View a specific snapshot
408
+ curl http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2
409
+
410
+ # View all snapshots
411
+ curl http://localhost:9200/_snapshot/my_fs_backup/_all
412
+ ```
413
+ - These commands allow you to check the status and details of your snapshots
414
+
415
+ - **Restoring a Snapshot**:
416
+ ```shell
417
+ curl -X "POST" "http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2/_restore?wait_for_completion=true" \
418
+ -H 'Content-Type: application/json; charset=utf-8' \
419
+ -d $'{
420
+ "include_aliases": false,
421
+ "include_global_state": false,
422
+ "ignore_unavailable": true,
423
+ "rename_replacement": "items_$1-copy",
424
+ "indices": "items_*",
425
+ "rename_pattern": "items_(.+)"
426
+ }'
427
+ ```
428
+ - This specific command will restore any indices that match items_* and rename them so that the new index name will be suffixed with -copy
429
+ - The rename_pattern and rename_replacement parameters allow you to restore indices under new names
430
+
431
+ - **Updating Collection References**:
432
+ ```shell
433
+ curl -X "POST" "http://localhost:9200/items_my-collection-copy/_update_by_query" \
434
+ -H 'Content-Type: application/json; charset=utf-8' \
435
+ -d $'{
436
+ "query": {
437
+ "match_all": {}
438
+ },
439
+ "script": {
440
+ "lang": "painless",
441
+ "params": {
442
+ "collection": "my-collection-copy"
443
+ },
444
+ "source": "ctx._source.collection = params.collection"
445
+ }
446
+ }'
447
+ ```
448
+ - After restoring, the item documents have been restored in the new index (e.g., my-collection-copy), but the value of the collection field in those documents is still the original value of my-collection
449
+ - This command updates these values to match the new collection name using Elasticsearch's Update By Query feature
450
+
451
+ - **Creating a New Collection**:
452
+ ```shell
453
+ curl -X "POST" "http://localhost:8080/collections" \
454
+ -H 'Content-Type: application/json' \
455
+ -d $'{
456
+ "id": "my-collection-copy"
457
+ }'
458
+ ```
459
+ - The final step is to create a new collection through the API with the new name for each of the restored indices
460
+ - This gives you a copy of the collection that has a resource URI (/collections/my-collection-copy) and can be correctly queried by collection name
461
+
462
+ ### Reindexing
463
+
464
+ - **Overview**: Reindexing allows you to copy documents from one index to another, optionally transforming them in the process.
465
+
466
+ - **Use Cases**:
467
+ - Apply changes to documents
468
+ - Correct dynamically generated mappings
469
+ - Transform data (e.g., lowercase identifiers)
470
+ - The index templates will make sure that manually created indices will also have the correct mappings and settings
471
+
472
+ - **Example: Reindexing with Transformation**:
473
+ ```shell
474
+ curl -X "POST" "http://localhost:9200/_reindex" \
475
+ -H 'Content-Type: application/json' \
476
+ -d $'{
477
+ "source": {
478
+ "index": "items_my-collection-lower_my-collection-hex-000001"
479
+ },
480
+ "dest": {
481
+ "index": "items_my-collection-lower_my-collection-hex-000002"
482
+ },
483
+ "script": {
484
+ "source": "ctx._source.id = ctx._source.id.toLowerCase()",
485
+ "lang": "painless"
486
+ }
487
+ }'
488
+ ```
489
+ - In this example, we make a copy of an existing Item index but change the Item identifier to be lowercase
490
+ - The script parameter allows you to transform documents during the reindexing process
491
+
492
+ - **Updating Aliases**:
493
+ ```shell
494
+ curl -X "POST" "http://localhost:9200/_aliases" \
495
+ -H 'Content-Type: application/json' \
496
+ -d $'{
497
+ "actions": [
498
+ {
499
+ "remove": {
500
+ "index": "*",
501
+ "alias": "items_my-collection"
502
+ }
503
+ },
504
+ {
505
+ "add": {
506
+ "index": "items_my-collection-lower_my-collection-hex-000002",
507
+ "alias": "items_my-collection"
508
+ }
509
+ }
510
+ ]
511
+ }'
512
+ ```
513
+ - If you are happy with the data in the newly created index, you can move the alias items_my-collection to the new index
514
+ - This makes the modified Items with lowercase identifiers visible to users accessing my-collection in the STAC API
515
+ - Using aliases allows you to switch between different index versions without changing the API endpoint
516
+
517
+ ## Auth
518
+
519
+ - **Overview**: Authentication is an optional feature that can be enabled through Route Dependencies.
520
+ - **Implementation Options**:
521
+ - Basic authentication
522
+ - OAuth2 with Keycloak
523
+ - Custom route dependencies
524
+ - **Configuration**: Authentication can be configured using the `STAC_FASTAPI_ROUTE_DEPENDENCIES` environment variable.
525
+ - **Examples and Documentation**: Detailed examples and implementation guides can be found in the [examples/auth](examples/auth) directory.
526
+
527
+ ## Aggregation
528
+
529
+ - **Supported Aggregations**:
530
+ - Spatial aggregations of points and geometries
531
+ - Frequency distribution aggregation of any property including dates
532
+ - Temporal distribution of datetime values
533
+
534
+ - **Endpoint Locations**:
535
+ - Root Catalog level: `/aggregations`
536
+ - Collection level: `/<collection_id>/aggregations`
537
+
538
+ - **Implementation Details**: The `sfeos_helpers.aggregation` package provides specialized functionality for both Elasticsearch and OpenSearch backends.
539
+
540
+ - **Documentation**: Detailed information about supported aggregations can be found in [the aggregation docs](./docs/src/aggregation.md).
541
+
542
+
543
+ ## Rate Limiting
544
+
545
+ - **Overview**: Rate limiting is an optional security feature that controls API request frequency on a remote address basis.
546
+
547
+ - **Configuration**: Enabled by setting the `STAC_FASTAPI_RATE_LIMIT` environment variable:
548
+ ```
549
+ STAC_FASTAPI_RATE_LIMIT=500/minute
550
+ ```
551
+
552
+ - **Functionality**:
553
+ - Limits each client to a specified number of requests per time period (e.g., 500 requests per minute)
554
+ - Helps prevent API abuse and maintains system stability
555
+ - Ensures fair resource allocation among all clients
556
+
557
+ - **Examples**: Implementation examples are available in the [examples/rate_limit](examples/rate_limit) directory.
558
+
@@ -0,0 +1,20 @@
1
+ stac_fastapi/sfeos_helpers/mappings.py,sha256=z6GJFJUE7bRKF9ODc8_ddkb7JCOokMtj4p2LeaQqrQQ,8237
2
+ stac_fastapi/sfeos_helpers/version.py,sha256=OmdIBuUO48QSNasPq039QZ4jr1YGTWDPPnYtlSe5Hxg,45
3
+ stac_fastapi/sfeos_helpers/aggregation/__init__.py,sha256=Mym17lFh90by1GnoQgMyIKAqRNJnvCgVSXDYzjBiPQk,1210
4
+ stac_fastapi/sfeos_helpers/aggregation/client.py,sha256=JCUVBXsUXHdUXn59WaytGxB-R6OLhC_LApPm-pzQNTI,17818
5
+ stac_fastapi/sfeos_helpers/aggregation/format.py,sha256=qUW1jjh2EEjy-V7riliFR77grpi-AgsTmP76z60K5Lo,2011
6
+ stac_fastapi/sfeos_helpers/database/__init__.py,sha256=WAZc7Djw9VZHt-crkFkhtILVCZb8GzIegS6CpdGA4gc,2477
7
+ stac_fastapi/sfeos_helpers/database/datetime.py,sha256=L_bY0EtRi6b8XIN9zcHbFe-O2jFdItkgkNvkQ4Z1jyY,2279
8
+ stac_fastapi/sfeos_helpers/database/document.py,sha256=LtjX15gvaOuZC_k2t_oQhys_c-zRTLN5rwX0hNJkHnM,1725
9
+ stac_fastapi/sfeos_helpers/database/index.py,sha256=7xFNzOQzFxBAtQUKUmhKcqz5j3_HRPuwIecdEEWb0i0,4476
10
+ stac_fastapi/sfeos_helpers/database/mapping.py,sha256=4-MSd4xH5wg7yoC4aPjzYMDSEvP026bw4k2TfffMT5E,1387
11
+ stac_fastapi/sfeos_helpers/database/query.py,sha256=3aFby56ggvTxtBg1vH1AXw2P2_CloPIV-cwL260P47E,2972
12
+ stac_fastapi/sfeos_helpers/database/utils.py,sha256=UTUNQWOqpY_TpwXorBQtUFqkG06Ciew7-s5QZVxD-NE,1421
13
+ stac_fastapi/sfeos_helpers/filter/__init__.py,sha256=n3zL_MhEGOoxMz1KeijyK_UKiZ0MKPl90zHtYI5RAy8,1557
14
+ stac_fastapi/sfeos_helpers/filter/client.py,sha256=QwjYWXkevoVS7HPtoXfeSzDy-_GJnFhPJtJM49D14oU,4229
15
+ stac_fastapi/sfeos_helpers/filter/cql2.py,sha256=Cg9kRYD9CVkVSyRqOyB5oVXmlyteSn2bw88sqklGpUM,955
16
+ stac_fastapi/sfeos_helpers/filter/transform.py,sha256=1GEWQSp-rbq7_1nDVv1ApDbWxt8DswJWxwaxzV85gj4,4644
17
+ sfeos_helpers-5.0.0.dist-info/METADATA,sha256=U5Jw0DDLTAYbV1WcGq3EorqE-nRh084qKca6gA8-bX8,31173
18
+ sfeos_helpers-5.0.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
19
+ sfeos_helpers-5.0.0.dist-info/top_level.txt,sha256=vqn-D9-HsRPTTxy0Vk_KkDmTiMES4owwBQ3ydSZYb2s,13
20
+ sfeos_helpers-5.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.45.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ stac_fastapi
@@ -0,0 +1,31 @@
1
+ """Shared aggregation extension methods for stac-fastapi elasticsearch and opensearch backends.
2
+
3
+ This module provides shared functionality for implementing the STAC API Aggregation Extension
4
+ with Elasticsearch and OpenSearch. It includes:
5
+
6
+ 1. Functions for formatting aggregation responses
7
+ 2. Helper functions for handling aggregation parameters
8
+ 3. Base implementation of the AsyncBaseAggregationClient for Elasticsearch/OpenSearch
9
+
10
+ The aggregation package is organized as follows:
11
+ - client.py: Aggregation client implementation
12
+ - format.py: Response formatting functions
13
+
14
+ When adding new functionality to this package, consider:
15
+ 1. Will this code be used by both Elasticsearch and OpenSearch implementations?
16
+ 2. Is the functionality stable and unlikely to diverge between implementations?
17
+ 3. Is the function well-documented with clear input/output contracts?
18
+
19
+ Function Naming Conventions:
20
+ - Function names should be descriptive and indicate their purpose
21
+ - Parameter names should be consistent across similar functions
22
+ """
23
+
24
+ from .client import EsAsyncBaseAggregationClient
25
+ from .format import frequency_agg, metric_agg
26
+
27
+ __all__ = [
28
+ "EsAsyncBaseAggregationClient",
29
+ "frequency_agg",
30
+ "metric_agg",
31
+ ]