Skip to main content

Read and download STAC assets across platforms and providers

Project description

stac-asset

GitHub Workflow Status Read the Docs PyPI Contributor Covenant

Download STAC Assets using a variety of authentication schemes.

Installation

pip install stac-asset

To use the command-line interface (CLI):

pip install 'stac-asset[cli]'

Usage

We have a Python API and a command-line interface (CLI).

API

Here's how to download a STAC Item and all of its assets to the current working directory. The correct client will be guessed from the assets' href. Each asset's href will be updated to point to the local file.

import pystac
import stac_asset
import asyncio

async def main():
    href = "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/simple-item.json"
    item = pystac.read_file(href)
    item = await stac_asset.download_item(item, ".")
    return item

asyncio.run(main())

If you're working in a fully synchronous application, you can use our blocking interface:

import stac_asset.blocking
href = "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/simple-item.json"
item = pystac.read_file(href)
item = stac_asset.blocking.download_item(item, ".")

CLI

To download an item using the command line:

stac-asset download \
    https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/simple-item.json

To download all assets from the results of a pystac-client search, and save the item collection to a file named item-collection.json:

stac-client search https://planetarycomputer.microsoft.com/api/stac/v1 \
        -c landsat-c2-l2 \
        --max-items 1 | \
    stac-asset download > item-collection.json

If you'd like to only download certain assets, e.g. a preview image, you can use the include -i flag:

stac-client search https://planetarycomputer.microsoft.com/api/stac/v1 \
        -c landsat-c2-l2 \
        --max-items 1 | \
    stac-asset download -i rendered_preview -q

See the documentation for more examples and complete API and CLI documentation.

Clients

This library comes with several clients, each tailored for a specific data provider model and authentication scheme. Some clients require some setup before use; they are called out in this table, and the details are provided below.

Name Description Notes
HttpClient Simple HTTP client without any authentication
S3Client Simple S3 client Use requester_pays=True in the client initializer to enable access to requester pays buckets, e.g. USGS landsat's public AWS archive
FilesystemClient Moves files from place to place on a local filesystem Mostly used for testing
PlanetaryComputerClient Signs urls with the Planetary Computer Authentication API No additional setup required, works out of the box
EarthdataClient Uses a token-based authentication to download data, from some Earthdata providers, e.g. DAACs Requires creation of a personal access token, see section below

For information about configuring each client, see the API documentation for that client.

Versioning

This project does its best to adhere to semantic versioning. Any module, class, constant, or function that does not begin with a _ is considered part of our public API for versioning purposes. Our command-line interface (CLI) is NOT considered part of our public API, and may change in breaking ways at any time. If you need stability promises, use our API.

Contributing

Use Github issues to report bugs and request new features. Use Github pull requests to fix bugs and propose new features.

Developing

Clone, install with the dev dependencies, and install pre-commit:

git clone git@github.com:stac-utils/stac-asset.git
cd stac-asset
pip install '.[dev]'
pre-commit install

Testing

All network-touching tests are disabled by default, because we can't use pytest-vcr (https://github.com/kevin1024/vcrpy/issues/597), and repeatedly hitting the network during testing and CI is bad behavior. To enable network-touching tests:

pytest --network-access

Some tests are client-specific and need your environment to be configured correctly. See each client's documentation for instructions on setting up your environment for each client.

Docs

Install the documentation dependencies:

pip install -e '.[docs]'

Then, build the docs:

make -C docs html && open docs/_build/html/index.html

It can be handy to use sphinx-autobuild if you're doing a lot of doc work:

pip install sphinx-autobuild
sphinx-autobuild --watch src docs docs/_build/html

License

Apache-2.0

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-asset-0.2.2.tar.gz (31.0 kB view details)

Uploaded Source

Built Distribution

stac_asset-0.2.2-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file stac-asset-0.2.2.tar.gz.

File metadata

  • Download URL: stac-asset-0.2.2.tar.gz
  • Upload date:
  • Size: 31.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for stac-asset-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ceb7f3192b22246ea45c911487ecfc91000a3db57fec8fecc42f5c5a83d9247a
MD5 4b8b7ac0ccdd97b4c0335d39f747439f
BLAKE2b-256 f5c134b35443a44c6efe9a466d94d183ed67fa11b763acbe43ac88763053e4ef

See more details on using hashes here.

File details

Details for the file stac_asset-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: stac_asset-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for stac_asset-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 af853a640dacb2f1e6687294307624dd7742c435bdafb712f363de121b11a45d
MD5 f408915b4dae7e9d2977f16436cfd8a5
BLAKE2b-256 eff609cb04784349f1d8c914c0279fa04dd4b56ebede17e48d80fb0387dea5cc

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