> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# PyStac

> PySTAC is a library for working with SpatioTemporal Asset Catalogs (STAC) in Python 3. A Python demo notebook from ganymede.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/geospatial/pystac/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/geospatial/pystac/pystac.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/geospatial/pystac.ipynb)

Description:
- PySTAC is a library for working with SpatioTemporal Asset Catalogs (STAC) in Python 3.

Resources:
- [GitHub] https://github.com/stac-utils/pystac
- [Docs] https://pystac.readthedocs.io/en/stable/

## Example 1

Write a STAC catalog to a file and read it back

```python
import json
from pathlib import Path

from pystac import Catalog

tmp = "/tmp/demo_notebooks"
Path(tmp).mkdir(exist_ok=True)

# Example stac catalog
example_catalog = {
  "type": "Catalog",
  "stac_version": "1.0.0",
  "stac_extensions": [],
  "id": "landsat-stac-collection-catalog",
  "title": "STAC for Landsat data",
  "description": "STAC for Landsat data",
  "links": [
    {
      "href": "./catalog.json",
      "rel": "self"
    },
    {
      "href": "./catalog.json",
      "rel": "root"
    },
    {
      "href": "./landsat-8-l1/collection.json",
      "rel": "child"
    }
  ]
}

# Create a json file locally with the dict
with open(f"{tmp}/stac_catalog.json", 'w') as f:
    json.dump(example_catalog, f)

# Print attrs from the catalog
root_catalog = Catalog.from_file(f"{tmp}/stac_catalog.json")
print(f"ID: {root_catalog.id}")
print(f"Title: {root_catalog.title or 'N/A'}")
print(f"Description: {root_catalog.description or 'N/A'}")
```
