Skip to main content

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

Test Package version Downloads


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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stac-fastapi.pgstac-2.1.1.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

stac_fastapi.pgstac-2.1.1-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file stac-fastapi.pgstac-2.1.1.tar.gz.

File metadata

  • Download URL: stac-fastapi.pgstac-2.1.1.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for stac-fastapi.pgstac-2.1.1.tar.gz
Algorithm Hash digest
SHA256 a79a397440cc0ccacae049ff530e256b64f2743c5e3849355e93af914525ac5f
MD5 3d4785c0032a1eb48c3a88b5259f4c2d
BLAKE2b-256 44e3af227645e9ea0fa6925cf1e79a0fae0f0bd9203873b46dbf4fdd1d36f4be

See more details on using hashes here.

File details

Details for the file stac_fastapi.pgstac-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: stac_fastapi.pgstac-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for stac_fastapi.pgstac-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec2854e3f6fb70922b46e2e36d051a08a3c3e750afe9d66c0824f6b7f638aea2
MD5 37d82caa5a55ee8260cde7517d45906a
BLAKE2b-256 39910c875c104acacbb5592945fd493b147a039d22391654ff452694f4cef57c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page