stac-utils / stac-utils/pgstac
Add support for loading from pystac objects
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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