stac-fastapi-elasticsearch 4.2.0__py3-none-any.whl → 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.
@@ -1,382 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: stac-fastapi-elasticsearch
3
- Version: 4.2.0
4
- Summary: An implementation of STAC API based on the FastAPI framework with both Elasticsearch and Opensearch.
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==4.2.0
19
- Requires-Dist: elasticsearch[async]~=8.18.0
20
- Requires-Dist: uvicorn~=0.23.0
21
- Requires-Dist: starlette<0.36.0,>=0.35.0
22
- Provides-Extra: dev
23
- Requires-Dist: pytest~=7.0.0; extra == "dev"
24
- Requires-Dist: pytest-cov~=4.0.0; extra == "dev"
25
- Requires-Dist: pytest-asyncio~=0.21.0; extra == "dev"
26
- Requires-Dist: pre-commit~=3.0.0; extra == "dev"
27
- Requires-Dist: requests<3.0.0,>=2.32.0; extra == "dev"
28
- Requires-Dist: ciso8601~=2.3.0; extra == "dev"
29
- Requires-Dist: httpx<0.28.0,>=0.24.0; extra == "dev"
30
- Provides-Extra: docs
31
- Requires-Dist: mkdocs~=1.4.0; extra == "docs"
32
- Requires-Dist: mkdocs-material~=9.0.0; extra == "docs"
33
- Requires-Dist: pdocs~=1.2.0; extra == "docs"
34
- Provides-Extra: server
35
- Requires-Dist: uvicorn[standard]~=0.23.0; extra == "server"
36
-
37
- # stac-fastapi-elasticsearch-opensearch (sfeos)
38
-
39
- <!-- markdownlint-disable MD033 MD041 -->
40
-
41
- <p align="left">
42
- <img src="https://github.com/radiantearth/stac-site/raw/master/images/logo/stac-030-long.png" width=600>
43
- <p align="left"><b>Elasticsearch and Opensearch backends for the stac-fastapi project.</b></p>
44
- <p align="left"><b>Featuring stac-fastapi.core for simplifying the creation and maintenance of custom STAC api backends.</b></p>
45
- </p>
46
-
47
-
48
- [![PyPI version](https://badge.fury.io/py/stac-fastapi-elasticsearch.svg)](https://badge.fury.io/py/stac-fastapi-elasticsearch) [![PyPI version](https://badge.fury.io/py/stac-fastapi-opensearch.svg)](https://badge.fury.io/py/stac-fastapi-opensearch)
49
- [![Join the chat at https://gitter.im/stac-fastapi-elasticsearch/community](https://badges.gitter.im/stac-fastapi-elasticsearch/community.svg)](https://gitter.im/stac-fastapi-elasticsearch/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
50
-
51
-
52
- ---
53
-
54
- **Online Documentation**: [https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch](https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch/)
55
-
56
- **Source Code**: [https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch)
57
-
58
-
59
- ---
60
-
61
- ### Notes:
62
-
63
- - Our Api core library can be used to create custom backends. See [stac-fastapi-mongo](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo) for a working example.
64
- - Reach out on our [Gitter](https://app.gitter.im/#/room/#stac-fastapi-elasticsearch_community:gitter.im) channel or feel free to add to our [Discussions](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/discussions) page here on github.
65
- - There is [Postman](https://documenter.getpostman.com/view/12888943/2s8ZDSdRHA) documentation here for examples on how to run some of the API routes locally - after starting the elasticsearch backend via the compose.yml file.
66
- - The `/examples` folder shows an example of running stac-fastapi-elasticsearch from PyPI in docker without needing any code from the repository. There is also a Postman collection here that you can load into Postman for testing the API routes.
67
-
68
-
69
- ### Performance Note
70
-
71
- 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.
72
-
73
- **You can now control this setting via the `ENABLE_DIRECT_RESPONSE` environment variable.**
74
-
75
- When enabled (`ENABLE_DIRECT_RESPONSE=true`), endpoints return Starlette Response objects directly, bypassing FastAPI's default serialization for improved performance. **However, all FastAPI dependencies (including authentication, custom status codes, and validation) are disabled for all routes.**
76
-
77
- This mode is best suited for public or read-only APIs where authentication and custom logic are not required. Default is `false` for safety.
78
-
79
- See: [issue #347](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/issues/347)
80
-
81
-
82
- ### To install from PyPI:
83
-
84
- ```bash
85
- # For versions 4.0.0a1 and newer (PEP 625 compliant naming):
86
- pip install stac-fastapi-elasticsearch # Elasticsearch backend
87
- pip install stac-fastapi-opensearch # Opensearch backend
88
- pip install stac-fastapi-core # Core library
89
-
90
- # For versions 4.0.0a0 and older:
91
- pip install stac-fastapi.elasticsearch # Elasticsearch backend
92
- pip install stac-fastapi.opensearch # Opensearch backend
93
- pip install stac-fastapi.core # Core library
94
- ```
95
-
96
- > **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.
97
-
98
- ### To install and run via pre-built Docker Images
99
-
100
- We provide ready-to-use Docker images through GitHub Container Registry ([ElasticSearch](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pkgs/container/stac-fastapi-es) and [OpenSearch](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pkgs/container/stac-fastapi-os) backends). You can easily pull and run these images:
101
-
102
- ```shell
103
- # For Elasticsearch backend
104
- docker pull ghcr.io/stac-utils/stac-fastapi-es:latest
105
-
106
- # For OpenSearch backend
107
- docker pull ghcr.io/stac-utils/stac-fastapi-os:latest
108
- ```
109
-
110
- ## Run Elasticsearch API backend on localhost:8080
111
-
112
- You need to ensure [**Docker Compose**](https://docs.docker.com/compose/install/) or [**Podman Compose**](https://podman-desktop.io/docs/compose) installed and running on your machine. In the following command instead of `docker compose` you can use `podman-compose` as well.
113
-
114
- ```shell
115
- docker compose up elasticsearch app-elasticsearch
116
- ```
117
-
118
- By default, Docker Compose uses Elasticsearch 8.x and OpenSearch 2.11.1.
119
- If you wish to use a different version, put the following in a
120
- file named `.env` in the same directory you run Docker Compose from:
121
-
122
- ```shell
123
- ELASTICSEARCH_VERSION=8.11.0
124
- OPENSEARCH_VERSION=2.11.1
125
- ENABLE_DIRECT_RESPONSE=false
126
- ```
127
- 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.
128
-
129
- #### **Configuration reference keys:**
130
-
131
- You can customize additional settings in your `.env` file:
132
- ###### Key variables to configure:
133
-
134
- | Variable | Description | Default | Required |
135
- |------------------------------|--------------------------------------------------------------------------------------|--------------------------|---------------------------------------------------------------------------------------------|
136
- | `ES_HOST` | Hostname for external Elasticsearch/OpenSearch. | `localhost` | Optional |
137
- | `ES_PORT` | Port for Elasticsearch/OpenSearch. | `9200` (ES) / `9202` (OS)| Optional |
138
- | `ES_USE_SSL` | Use SSL for connecting to Elasticsearch/OpenSearch. | `false` | Optional |
139
- | `ES_VERIFY_CERTS` | Verify SSL certificates when connecting. | `false` | Optional |
140
- | `STAC_FASTAPI_TITLE` | Title of the API in the documentation. | `stac-fastapi-elasticsearch` or `stac-fastapi-opensearch` | Optional |
141
- | `STAC_FASTAPI_DESCRIPTION` | Description of the API in the documentation. | N/A | Optional |
142
- | `STAC_FASTAPI_VERSION` | API version. | `2.1` | Optional |
143
- | `STAC_FASTAPI_LANDING_PAGE_ID` | Landing page ID | `stac-fastapi` | Optional |
144
- | `APP_HOST` | Server bind address. | `0.0.0.0` | Optional |
145
- | `APP_PORT` | Server port. | `8080` | Optional |
146
- | `ENVIRONMENT` | Runtime environment. | `local` | Optional |
147
- | `WEB_CONCURRENCY` | Number of worker processes. | `10` | Optional |
148
- | `RELOAD` | Enable auto-reload for development. | `true` | Optional |
149
- | `STAC_FASTAPI_RATE_LIMIT` | API rate limit per client. | `200/minute` | Optional |
150
- | `BACKEND` | Tests-related variable | `elasticsearch` or `opensearch` based on the backend | Optional |
151
- | `ELASTICSEARCH_VERSION` | Version of Elasticsearch to use. | `8.11.0` | Optional | |
152
- | `OPENSEARCH_VERSION` | OpenSearch version | `2.11.1` | Optional
153
- | `ENABLE_DIRECT_RESPONSE` | Enable direct response for maximum performance (disables all FastAPI dependencies, including authentication, custom status codes, and validation) | `false` | Optional
154
- | `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 |
155
- | `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 |
156
- | `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 |
157
-
158
- > [!NOTE]
159
- > 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.
160
-
161
- ## Interacting with the API
162
-
163
- To create a new Collection:
164
-
165
- ```shell
166
- curl -X "POST" "http://localhost:8080/collections" \
167
- -H 'Content-Type: application/json; charset=utf-8' \
168
- -d $'{
169
- "id": "my_collection"
170
- }'
171
- ```
172
-
173
- Note: this "Collections Transaction" behavior is not part of the STAC API, but may be soon.
174
-
175
- ## Configure the API
176
-
177
- By default the API title and description are set to `stac-fastapi-<backend>`. Change the API title and description from the default by setting the `STAC_FASTAPI_TITLE` and `STAC_FASTAPI_DESCRIPTION` environment variables, respectively.
178
-
179
- By default the API will read from and write to the `collections` and `items_<collection name>` indices. To change the API collections index and the items index prefix, change the `STAC_COLLECTIONS_INDEX` and `STAC_ITEMS_INDEX_PREFIX` environment variables.
180
-
181
- The application root path is left as the base url by default. If deploying to AWS Lambda with a Gateway API, you will need to define the app root path to be the same as the Gateway API stage name where you will deploy the API. The app root path can be defined with the `STAC_FASTAPI_ROOT_PATH` environment variable (`/v1`, for example)
182
-
183
- ## Collection pagination
184
-
185
- The collections route handles optional `limit` and `token` parameters. The `links` field that is
186
- returned from the `/collections` route contains a `next` link with the token that can be used to
187
- get the next page of results.
188
-
189
- ```shell
190
- curl -X "GET" "http://localhost:8080/collections?limit=1&token=example_token"
191
- ```
192
-
193
- ## Ingesting Sample Data CLI Tool
194
-
195
- ```shell
196
- Usage: data_loader.py [OPTIONS]
197
-
198
- Load STAC items into the database.
199
-
200
- Options:
201
- --base-url TEXT Base URL of the STAC API [required]
202
- --collection-id TEXT ID of the collection to which items are added
203
- --use-bulk Use bulk insert method for items
204
- --data-dir PATH Directory containing collection.json and feature
205
- collection file
206
- --help Show this message and exit.
207
- ```
208
-
209
- ```shell
210
- python3 data_loader.py --base-url http://localhost:8080
211
- ```
212
-
213
-
214
- ## Elasticsearch Mappings
215
-
216
- Mappings apply to search index, not source. The mappings are stored in index templates on application startup.
217
- These templates will be used implicitly when creating new Collection and Item indices.
218
-
219
-
220
- ## Managing Elasticsearch Indices
221
- ### Snapshots
222
-
223
- This section covers how to create a snapshot repository and then create and restore snapshots with this.
224
-
225
- Create a snapshot repository. This puts the files in the `elasticsearch/snapshots` in this git repo clone, as
226
- the elasticsearch.yml and compose files create a mapping from that directory to
227
- `/usr/share/elasticsearch/snapshots` within the Elasticsearch container and grant permissions on using it.
228
-
229
- ```shell
230
- curl -X "PUT" "http://localhost:9200/_snapshot/my_fs_backup" \
231
- -H 'Content-Type: application/json; charset=utf-8' \
232
- -d $'{
233
- "type": "fs",
234
- "settings": {
235
- "location": "/usr/share/elasticsearch/snapshots/my_fs_backup"
236
- }
237
- }'
238
- ```
239
-
240
- The next step is to create a snapshot of one or more indices into this snapshot repository. This command creates
241
- a snapshot named `my_snapshot_2` and waits for the action to be completed before returning. This can also be done
242
- asynchronously, and queried for status. The `indices` parameter determines which indices are snapshotted, and
243
- can include wildcards.
244
-
245
- ```shell
246
- curl -X "PUT" "http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2?wait_for_completion=true" \
247
- -H 'Content-Type: application/json; charset=utf-8' \
248
- -d $'{
249
- "metadata": {
250
- "taken_because": "dump of all items",
251
- "taken_by": "pvarner"
252
- },
253
- "include_global_state": false,
254
- "ignore_unavailable": false,
255
- "indices": "items_my-collection"
256
- }'
257
- ```
258
-
259
- To see the status of this snapshot:
260
-
261
- ```shell
262
- curl http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2
263
- ```
264
-
265
- To see all the snapshots:
266
-
267
- ```shell
268
- curl http://localhost:9200/_snapshot/my_fs_backup/_all
269
- ```
270
-
271
- To restore a snapshot, run something similar to the following. This specific command will restore any indices that
272
- match `items_*` and rename them so that the new index name will be suffixed with `-copy`.
273
-
274
- ```shell
275
- curl -X "POST" "http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2/_restore?wait_for_completion=true" \
276
- -H 'Content-Type: application/json; charset=utf-8' \
277
- -d $'{
278
- "include_aliases": false,
279
- "include_global_state": false,
280
- "ignore_unavailable": true,
281
- "rename_replacement": "items_$1-copy",
282
- "indices": "items_*",
283
- "rename_pattern": "items_(.+)"
284
- }'
285
- ```
286
-
287
- Now the item documents have been restored in to the new index (e.g., `my-collection-copy`), but the value of the
288
- `collection` field in those documents is still the original value of `my-collection`. To update these to match the
289
- new collection name, run the following Elasticsearch Update By Query command, substituting the old collection name
290
- into the term filter and the new collection name into the script parameter:
291
-
292
- ```shell
293
- curl -X "POST" "http://localhost:9200/items_my-collection-copy/_update_by_query" \
294
- -H 'Content-Type: application/json; charset=utf-8' \
295
- -d $'{
296
- "query": {
297
- "match_all": {}
298
- },
299
- "script": {
300
- "lang": "painless",
301
- "params": {
302
- "collection": "my-collection-copy"
303
- },
304
- "source": "ctx._source.collection = params.collection"
305
- }
306
- }'
307
- ```
308
-
309
- Then, create a new collection through the api with the new name for each of the restored indices:
310
-
311
- ```shell
312
- curl -X "POST" "http://localhost:8080/collections" \
313
- -H 'Content-Type: application/json' \
314
- -d $'{
315
- "id": "my-collection-copy"
316
- }'
317
- ```
318
-
319
- Voila! You have a copy of the collection now that has a resource URI (`/collections/my-collection-copy`) and can be
320
- correctly queried by collection name.
321
-
322
- ### Reindexing
323
- This section covers how to reindex documents stored in Elasticsearch/OpenSearch.
324
- A reindex operation might be useful to apply changes to documents or to correct dynamically generated mappings.
325
-
326
- The index templates will make sure that manually created indices will also have the correct mappings and settings.
327
-
328
- In this example, we will make a copy of an existing Item index `items_my-collection-lower_my-collection-hex-000001` but change the Item identifier to be lowercase.
329
-
330
- ```shell
331
- curl -X "POST" "http://localhost:9200/_reindex" \
332
- -H 'Content-Type: application/json' \
333
- -d $'{
334
- "source": {
335
- "index": "items_my-collection-lower_my-collection-hex-000001"
336
- },
337
- "dest": {
338
- "index": "items_my-collection-lower_my-collection-hex-000002"
339
- },
340
- "script": {
341
- "source": "ctx._source.id = ctx._source.id.toLowerCase()",
342
- "lang": "painless"
343
- }
344
- }'
345
- ```
346
-
347
- If we are happy with the data in the newly created index, we can move the alias `items_my-collection` to the new index `items_my-collection-lower_my-collection-hex-000002`.
348
- ```shell
349
- curl -X "POST" "http://localhost:9200/_aliases" \
350
- -h 'Content-Type: application/json' \
351
- -d $'{
352
- "actions": [
353
- {
354
- "remove": {
355
- "index": "*",
356
- "alias": "items_my-collection"
357
- }
358
- },
359
- {
360
- "add": {
361
- "index": "items_my-collection-lower_my-collection-hex-000002",
362
- "alias": "items_my-collection"
363
- }
364
- }
365
- ]
366
- }'
367
- ```
368
-
369
- The modified Items with lowercase identifiers will now be visible to users accessing `my-collection` in the STAC API.
370
-
371
-
372
- ## Auth
373
-
374
- Authentication is an optional feature that can be enabled through `Route Dependencies` examples can be found and a more detailed explanation in [examples/auth](examples/auth).
375
-
376
- ## Aggregation
377
-
378
- Aggregation of points and geometries, as well as frequency distribution aggregation of any other property including dates is supported in stac-fatsapi-elasticsearch-opensearch. Aggregations can be defined at the root Catalog level (`/aggregations`) and at the Collection level (`/<collection_id>/aggregations`). Details for supported aggregations can be found in [the aggregation docs](./docs/src/aggregation.md)
379
-
380
- ## Rate Limiting
381
-
382
- Rate limiting is an optional security feature that controls API request frequency on a remote address basis. It's enabled by setting the `STAC_FASTAPI_RATE_LIMIT` environment variable, e.g., `500/minute`. This limits each client to 500 requests per minute, helping prevent abuse and maintain API stability. Implementation examples are available in the [examples/rate_limit](examples/rate_limit) directory.
@@ -1,10 +0,0 @@
1
- stac_fastapi/elasticsearch/__init__.py,sha256=w_MZutYLreNV372sCuO46bPb0TngmPs4u8737ueS0wE,31
2
- stac_fastapi/elasticsearch/app.py,sha256=JQRKE9gfr0mTgkG5QdyNLIOFb8G6NXpQ_HklYHJpocs,4983
3
- stac_fastapi/elasticsearch/config.py,sha256=y2b7BP3lQfUgTIga1Uk39kk8RJZ6nzymKKOcdiBu49M,5134
4
- stac_fastapi/elasticsearch/database_logic.py,sha256=gE8hi7wPNMbi6Xknw6h73pCmzaBWBn4SYEVCM-4qqbU,51111
5
- stac_fastapi/elasticsearch/version.py,sha256=XAYr-IO1hoDdSshTkYzWFp3wj4AdjSQwUik30pTEaAo,45
6
- stac_fastapi_elasticsearch-4.2.0.dist-info/METADATA,sha256=GU_EroLaZkNatiKaKCp1Hl5R8NhyF9Lr4npSNJJ062Y,21906
7
- stac_fastapi_elasticsearch-4.2.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
8
- stac_fastapi_elasticsearch-4.2.0.dist-info/entry_points.txt,sha256=aCKixki0LpUl64UPsPMtiNvfdyq-QsTCxVjJ54VF6Jk,82
9
- stac_fastapi_elasticsearch-4.2.0.dist-info/top_level.txt,sha256=vqn-D9-HsRPTTxy0Vk_KkDmTiMES4owwBQ3ydSZYb2s,13
10
- stac_fastapi_elasticsearch-4.2.0.dist-info/RECORD,,