stac-utils / stac-utils/pgstac

Add support for loading from pystac objects

Open
#282 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PLpgSQL
Stars
223
Forks
57
PR merge metrics
No merged PRs in 30d

Description

Would it make sense to add support for loading Collection, Item, and ItemCollection objects from pystac? It could be useful in python workflows that generate STAC metadata and load directly into pgstac.

Right now, I do something like this:

import io
import json

from pypgstac.db import PgstacDB
from pypgstac.load import Loader, Methods
from pystac import ItemCollection
from stactools.package import create_item

# fire up pgstac loader
db = PgstacDB()
loader = Loader(db=db)

# create item collection
item_collection = ItemCollection(
  create_item(href) for href in hrefs
)

# write to ndjson and load into pgstac
buffer = io.BytesIO()
for item in item_collection:
    item.collection_id = COLLECTION_ID_FORMAT.format(
        region=region.value, product=product.value
    )

    buffer.write((json.dumps(item.to_dict()) + "\n").encode("utf-8"))

buffer.seek(0)

loader.load_items(buffer, insert_mode=Methods.upsert)

It isn't that hard to write to ndjson and pass that to load_items, but it would be nice if that operation was handled by pypgstac!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Loader.load_items entry point and the PgstacDB and Methods.upsert usage shown in the example. Review how pystac Collection, Item, and ItemCollection objects are currently converted or loaded, then define the supported input forms and verify that direct loading preserves the existing upsert behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.