|
| 1 | +# stac-fastapi-pgstac |
| 2 | + |
| 3 | +[](https://github.com/stac-utils/stac-fastapi-pgstac/actions/workflows/cicd.yaml) |
| 4 | +[](https://pypi.org/project/stac-fastapi.pgstac) |
| 5 | +[](https://stac-utils.github.io/stac-fastapi-pgstac/) |
| 6 | +[](https://github.com/stac-utils/stac-fastapi-pgstac/blob/main/LICENSE) |
| 7 | + |
1 | 8 | <p align="center">
|
2 |
| - <img src="https://github.com/radiantearth/stac-site/raw/master/images/logo/stac-030-long.png" width=400> |
3 |
| - <p align="center">FastAPI implemention of the STAC API spec using <a href="https://github.com/stac-utils/pgstac">PGStac</a></p> |
4 |
| -</p> |
5 |
| -<p align="center"> |
6 |
| - <a href="https://github.com/stac-utils/stac-fastapi/actions?query=workflow%3Acicd" target="_blank"> |
7 |
| - <img src="https://github.com/stac-utils/stac-fastapi/workflows/stac-fastapi/badge.svg" alt="Test"> |
8 |
| - </a> |
9 |
| - <a href="https://pypi.org/project/stac-fastapi" target="_blank"> |
10 |
| - <img src="https://img.shields.io/pypi/v/stac-fastapi?color=%2334D058&label=pypi%20package" alt="Package version"> |
11 |
| - </a> |
12 |
| - <a href="https://github.com/stac-utils/stac-fastapi/blob/main/LICENSE" target="_blank"> |
13 |
| - <img src="https://img.shields.io/github/license/stac-utils/stac-fastapi.svg" alt="Downloads"> |
14 |
| - </a> |
| 9 | + <img src="https://user-images.githubusercontent.com/10407788/174893876-7a3b5b7a-95a5-48c4-9ff2-cc408f1b6af9.png" style="vertical-align: middle; max-width: 400px; max-height: 100px;" height=100 /> |
| 10 | + <img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" alt="FastAPI" style="vertical-align: middle; max-width: 400px; max-height: 100px;" width=200 /> |
15 | 11 | </p>
|
16 | 12 |
|
17 |
| ---- |
| 13 | +[PgSTAC](https://github.com/stac-utils/pgstac) backend for [stac-fastapi](https://github.com/stac-utils/stac-fastapi), the [FastAPI](https://fastapi.tiangolo.com/) implementation of the [STAC API spec](https://github.com/radiantearth/stac-api-spec) |
18 | 14 |
|
19 |
| -**Documentation**: [https://stac-utils.github.io/stac-fastapi/](https://stac-utils.github.io/stac-fastapi/) |
| 15 | +## Overview |
20 | 16 |
|
21 |
| -**Source Code**: [https://github.com/stac-utils/stac-fastapi](https://github.com/stac-utils/stac-fastapi) |
| 17 | +**stac-fastapi-pgstac** is an HTTP interface built in FastAPI. |
| 18 | +It validates requests and data sent to a [PgSTAC](https://github.com/stac-utils/pgstac) backend, and adds [links](https://github.com/radiantearth/stac-spec/blob/master/item-spec/item-spec.md#link-object) to the returned data. |
| 19 | +All other processing and search is provided directly using PgSTAC procedural sql / plpgsql functions on the database. |
| 20 | +PgSTAC stores all collection and item records as jsonb fields exactly as they come in allowing for any custom fields to be stored and retrieved transparently. |
22 | 21 |
|
23 |
| ---- |
| 22 | +## Usage |
24 | 23 |
|
25 |
| -Stac FastAPI using the [PGStac](https://github.com/stac-utils/pgstac) backend. |
| 24 | +PgSTAC is an external project and may be used by multiple front ends. |
| 25 | +For Stac FastAPI development, a Docker image (which is pulled as part of the docker-compose) is available via the [Github container registry](https://github.com/stac-utils/pgstac/pkgs/container/pgstac/81689794?tag=latest). |
| 26 | +The PgSTAC version required by **stac-fastapi-pgstac** is found in the [setup](http://github.com/stac-utils/stac-fastapi-pgstac/blob/main/setup.py) file. |
26 | 27 |
|
27 |
| -[PGStac](https://github.com/stac-utils/pgstac) is a separately managed PostgreSQL database that is designed for enhanced performance to be able to scale Stac FastAPI to be able to efficiently handle hundreds of millions of records. [PGStac](https://github.com/stac-utils/pgstac) automatically includes indexes on Item id, Collection id, Item Geometry, Item Datetime, and an Index for equality checks on any key in Item Properties. Additional indexes may be added to Item Properties to speed up the use of order, <, <=, >, and >= queries. |
| 28 | +### Sorting |
28 | 29 |
|
29 |
| -Stac FastAPI acts as the HTTP interface validating any requests and data that is sent to the [PGStac](https://github.com/stac-utils/pgstac) backend and adds in Link items on data return relative to the service host. All other processing and search is provided directly using PGStac procedural sql / plpgsql functions on the database. |
| 30 | +While the STAC [Sort Extension](https://github.com/stac-api-extensions/sort) is fully supported, [PgSTAC](https://github.com/stac-utils/pgstac) is particularly enhanced to be able to sort by datetime (either ascending or descending). |
| 31 | +Sorting by anything other than datetime (the default if no sort is specified) on very large STAC repositories without very specific query limits (ie selecting a single day date range) will not have the same performance. |
| 32 | +For more than millions of records it is recommended to either set a low connection timeout on PostgreSQL or to disable use of the Sort Extension. |
30 | 33 |
|
31 |
| -PGStac stores all collection and item records as jsonb fields exactly as they come in allowing for any custom fields to be stored and retrieved transparently. |
| 34 | +### Hydration |
32 | 35 |
|
33 |
| -While the Stac Sort Extension is fully supported, [PGStac](https://github.com/stac-utils/pgstac) is particularly enhanced to be able to sort by datetime (either ascending or descending). Sorting by anything other than datetime (the default if no sort is specified) on very large Stac repositories without very specific query limits (ie selecting a single day date range) will not have the same performance. For more than millions of records it is recommended to either set a low connection timeout on PostgreSQL or to disable use of the Sort Extension. |
| 36 | +To configure **stac-fastapi-pgstac** to [hydrate search result items in the API](https://stac-utils.github.io/pgstac/pgstac/#runtime-configurations), set the `USE_API_HYDRATE` environment variable to `true` or explicitly set the option in the PGStac Settings object. |
34 | 37 |
|
35 |
| -`stac-fastapi pgstac` was initially added to `stac-fastapi` by [developmentseed](https://github.com/developmentseed). |
| 38 | +### Migrations |
36 | 39 |
|
37 |
| -## Installation |
| 40 | +There is a Python utility as part of PgSTAC ([pypgstac](https://stac-utils.github.io/pgstac/pypgstac/)) that includes a migration utility. |
| 41 | +To use: |
38 | 42 |
|
39 | 43 | ```shell
|
40 |
| -git clone https://github.com/stac-utils/stac-fastapi.git |
41 |
| -cd stac-fastapi |
42 |
| -pip install -e \ |
43 |
| - stac_fastapi/api[dev] \ |
44 |
| - stac_fastapi/types[dev] \ |
45 |
| - stac_fastapi/extensions[dev] \ |
46 |
| - stac_fastapi/pgstac[dev,server] |
| 44 | +pypgstac migrate |
47 | 45 | ```
|
48 | 46 |
|
49 |
| -### Settings |
| 47 | +## Contributing |
50 | 48 |
|
51 |
| -To configure PGStac stac-fastapi to [hydrate search result items in the API](https://github.com/stac-utils/pgstac#runtime-configurations), set the `USE_API_HYDRATE` environment variable to `true` or explicitly set the option in the PGStac Settings object. |
| 49 | +See [CONTRIBUTING](https://github.com/stac-utils/stac-fastapi-pgstac/blob/main/CONTRIBUTING.md) for detailed contribution instructions. |
52 | 50 |
|
53 |
| -### Migrations |
| 51 | +To install: |
| 52 | + |
| 53 | +```shell |
| 54 | +git clone https://github.com/stac-utils/stac-fastapi-pgstac |
| 55 | +cd stac-fastapi-pgstac |
| 56 | +pip install -e ".[dev,server,docs]" |
| 57 | +``` |
| 58 | + |
| 59 | +To test: |
| 60 | + |
| 61 | +```shell |
| 62 | +make test |
| 63 | +``` |
54 | 64 |
|
55 |
| -PGStac is an external project and the may be used by multiple front ends. |
56 |
| -For Stac FastAPI development, a docker image (which is pulled as part of the docker-compose) is available at |
57 |
| -bitner/pgstac:[version] that has the full database already set up for PGStac. |
| 65 | +Use Github [Pull Requests](https://github.com/stac-utils/stac-fastapi-pgstac/pulls) to provide new features or to request review of draft code, and use [Issues](https://github.com/stac-utils/stac-fastapi-pgstac/issues) to report bugs or request new features. |
58 | 66 |
|
59 |
| -There is also a python utility as part of PGStac (pypgstac) that includes a migration utility. The pgstac |
60 |
| -version required by stac-fastapi/pgstac is pinned by using the pinned version of pypgstac in the [setup](http://github.com/stac-utils/stac-fastapi-pgstac/blob/main/setup.py) file. |
| 67 | +### Documentation |
61 | 68 |
|
62 |
| -In order to migrate database versions you can use the migration utility: |
| 69 | +To build the docs: |
63 | 70 |
|
64 | 71 | ```shell
|
65 |
| -pypgstac migrate |
| 72 | +make docs |
| 73 | +``` |
| 74 | + |
| 75 | +Then, serve the docs via a local HTTP server: |
| 76 | + |
| 77 | +```shell |
| 78 | +mkdocs serve |
66 | 79 | ```
|
| 80 | + |
| 81 | +## History |
| 82 | + |
| 83 | +**stac-fastapi-pgstac** was initially added to **stac-fastapi** by [developmentseed](https://github.com/developmentseed). |
| 84 | +In April of 2023, it was removed from the core **stac-fastapi** repository and moved to its current location (<http://github.com/stac-util/stac-fastapi-pgstac>). |
| 85 | + |
| 86 | +## License |
| 87 | + |
| 88 | +[MIT](https://github.com/stac-utils/stac-fastapi-pgstac/blob/main/LICENSE) |
| 89 | + |
| 90 | +<!-- markdownlint-disable-file MD033 --> |
0 commit comments