Skip to content

Add support for loading from pystac objects #282

@hrodmn

Description

@hrodmn

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions