An implementation of STAC API based on the FastAPI framework and using the pgstac backend.
Project description
FastAPI implemention of the STAC API spec using PGStac
Documentation: https://stac-utils.github.io/stac-fastapi/
Source Code: https://github.com/stac-utils/stac-fastapi
Stac FastAPI using the PGStac backend.
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 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.
Stac FastAPI acts as the HTTP interface validating any requests and data that is sent to the 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.
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.
While the Stac Sort Extension is fully supported, 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.
stac-fastapi pgstac
was initially added to stac-fastapi
by developmentseed.
Installation
git clone https://github.com/stac-utils/stac-fastapi.git
cd stac-fastapi
pip install -e \
stac_fastapi/api[dev] \
stac_fastapi/types[dev] \
stac_fastapi/extensions[dev,tiles] \
stac_fastapi/pgstac[dev,server]
Local Development
Use docker-compose to deploy the application with a PGStac database. The docker-compose environment will run stac-fastapi/sqlalchemy on port 8081 and stac-fastapi/pgstac on port 8082.
docker-compose build
docker-compose up
Testing
The test suite will create a new database on the currently set up database that will have all data truncated between tests. The database must be running with docker-compose or you must have your environment pointing to a running database with PGStac installed to run the tests. All tests are run in the database named "pgstactestdb".
Run all tests:
make test-pgstac
Run individual tests by running pytest within the docker container:
make docker-shell
$ pytest -v
Migrations
PGStac is an external project and the may be used by multiple front ends. For Stac FastAPI development, a docker image (which is pulled as part of the docker-compose) is available at bitner/pgstac:[version] that has the full database already set up for PGStac.
There is also a python utility as part of PGStac (pypgstac) that includes a migration utility. The pgstac version required by stac-fastapi/pgstac is pinned by using the pinned version of pypgstac in the setup file.
In order to migrate database versions you can use the migration utility:
pypgstac migrate
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for stac-fastapi.pgstac-2.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a79a397440cc0ccacae049ff530e256b64f2743c5e3849355e93af914525ac5f |
|
MD5 | 3d4785c0032a1eb48c3a88b5259f4c2d |
|
BLAKE2b-256 | 44e3af227645e9ea0fa6925cf1e79a0fae0f0bd9203873b46dbf4fdd1d36f4be |
Hashes for stac_fastapi.pgstac-2.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec2854e3f6fb70922b46e2e36d051a08a3c3e750afe9d66c0824f6b7f638aea2 |
|
MD5 | 37d82caa5a55ee8260cde7517d45906a |
|
BLAKE2b-256 | 39910c875c104acacbb5592945fd493b147a039d22391654ff452694f4cef57c |