stac-fastapi-core 4.1.0__tar.gz → 5.0.0a0__tar.gz

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