Skip to content

Module stac_fastapi.core.serializers

Serializers.

Variables

logger

Classes

CatalogSerializer

class CatalogSerializer(

)

Serialization methods for STAC catalogs.

Ancestors (in MRO)

  • stac_fastapi.core.serializers.Serializer
  • abc.ABC

Static methods

db_to_stac

def db_to_stac(
    catalog: dict,
    request: starlette.requests.Request,
    extensions: list[str] | None = None
) -> stac_fastapi.types.stac.Catalog

Transform database model to STAC catalog.

Parameters:

Name Type Description Default
catalog None The database catalog dictionary. None
request None The incoming starlette request. None
extensions None List of enabled API extensions. None

Returns:

Type Description
None A stac_types.Catalog object with dynamic links.
def generate_poly_hierarchy_links(
    base_url: str,
    resource_id: str,
    resource_type: str,
    parent_ids: list[str],
    context_parent_id: str | None = None
) -> list[dict]

Generate HATEOAS links for poly-hierarchical STAC resources.

This helper method generates parent, related, canonical, and duplicate links for resources that can belong to multiple catalogs (poly-hierarchy).

Parameters:

Name Type Description Default
base_url None The base URL of the API. None
resource_id None The ID of the resource (collection or catalog). None
resource_type None Either "Collection" or "Catalog". None
parent_ids None List of parent catalog IDs. None
context_parent_id None The current catalog context (if accessing via scoped endpoint).
None means accessing via global endpoint (e.g., /collections/{id}).
None

Returns:

Type Description
None List of link dictionaries following STAC link relation conventions.

stac_to_db

def stac_to_db(
    catalog: stac_fastapi.core.models.Catalog,
    request: starlette.requests.Request
) -> dict

Transform STAC Catalog to database-ready STAC catalog.

Parameters:

Name Type Description Default
catalog None The STAC Catalog object. None
request None The incoming starlette request. None

Returns:

Type Description
None A dictionary representation of the catalog for the database.

CollectionSerializer

class CollectionSerializer(

)

Serialization methods for STAC collections.

Ancestors (in MRO)

  • stac_fastapi.core.serializers.Serializer
  • abc.ABC

Static methods

db_to_stac

def db_to_stac(
    collection: dict,
    request: starlette.requests.Request,
    extensions: list[str] | None = None
) -> stac_fastapi.types.stac.Collection

Transform database model to STAC collection.

Parameters:

Name Type Description Default
collection None The database collection dictionary. None
request None The incoming starlette request. None
extensions None List of enabled API extensions. None

Returns:

Type Description
None A stac_types.Collection object with dynamic links.

db_to_stac_in_catalog

def db_to_stac_in_catalog(
    collection: dict,
    request: starlette.requests.Request,
    catalog_id: str,
    extensions: list[str] | None = None
) -> stac_fastapi.types.stac.Collection

Transform database model to STAC collection within a catalog context.

Parameters:

Name Type Description Default
collection None The database collection dictionary. None
request None The incoming starlette request. None
catalog_id None The ID of the specific catalog context. None
extensions None List of enabled API extensions. None

Returns:

Type Description
None A stac_types.Collection object scoped to the provided catalog.
def generate_poly_hierarchy_links(
    base_url: str,
    resource_id: str,
    resource_type: str,
    parent_ids: list[str],
    context_parent_id: str | None = None
) -> list[dict]

Generate HATEOAS links for poly-hierarchical STAC resources.

This helper method generates parent, related, canonical, and duplicate links for resources that can belong to multiple catalogs (poly-hierarchy).

Parameters:

Name Type Description Default
base_url None The base URL of the API. None
resource_id None The ID of the resource (collection or catalog). None
resource_type None Either "Collection" or "Catalog". None
parent_ids None List of parent catalog IDs. None
context_parent_id None The current catalog context (if accessing via scoped endpoint).
None means accessing via global endpoint (e.g., /collections/{id}).
None

Returns:

Type Description
None List of link dictionaries following STAC link relation conventions.

stac_to_db

def stac_to_db(
    collection: stac_fastapi.types.stac.Collection,
    request: starlette.requests.Request
) -> dict

Transform STAC Collection to database-ready STAC collection.

Parameters:

Name Type Description Default
collection None The STAC collection object. None
request None The incoming starlette request. None

Returns:

Type Description
None A dictionary representation of the collection for the database.

ItemSerializer

class ItemSerializer(

)

Serialization methods for STAC items.

Ancestors (in MRO)

  • stac_fastapi.core.serializers.Serializer
  • abc.ABC

Static methods

db_to_stac

def db_to_stac(
    item: dict,
    base_url: str,
    request: starlette.requests.Request = None,
    extensions: list[str] | None = None
) -> stac_fastapi.types.stac.Item

Transform database-ready STAC item to STAC item.

Parameters:

Name Type Description Default
item None The database item dictionary. None
base_url None The base URL of the API. None
request None The incoming starlette request for context. None
extensions None List of enabled API extensions. None

Returns:

Type Description
None A stac_types.Item object.
def generate_poly_hierarchy_links(
    base_url: str,
    resource_id: str,
    resource_type: str,
    parent_ids: list[str],
    context_parent_id: str | None = None
) -> list[dict]

Generate HATEOAS links for poly-hierarchical STAC resources.

This helper method generates parent, related, canonical, and duplicate links for resources that can belong to multiple catalogs (poly-hierarchy).

Parameters:

Name Type Description Default
base_url None The base URL of the API. None
resource_id None The ID of the resource (collection or catalog). None
resource_type None Either "Collection" or "Catalog". None
parent_ids None List of parent catalog IDs. None
context_parent_id None The current catalog context (if accessing via scoped endpoint).
None means accessing via global endpoint (e.g., /collections/{id}).
None

Returns:

Type Description
None List of link dictionaries following STAC link relation conventions.

stac_to_db

def stac_to_db(
    stac_data: stac_fastapi.types.stac.Item,
    base_url: str
) -> dict

Transform STAC item to database-ready STAC item.

Parameters:

Name Type Description Default
stac_data None The STAC item to be transformed. None
base_url None The base URL of the API. None

Returns:

Type Description
None A dictionary representation of the item ready for database insertion.

Serializer

class Serializer(

)

Defines serialization methods between the API and the data model.

Ancestors (in MRO)

  • abc.ABC

Descendants

  • stac_fastapi.core.serializers.ItemSerializer
  • stac_fastapi.core.serializers.CollectionSerializer
  • stac_fastapi.core.serializers.CatalogSerializer

Static methods

db_to_stac

def db_to_stac(
    item: dict,
    base_url: str
) -> Any

Transform database model to STAC object.

def generate_poly_hierarchy_links(
    base_url: str,
    resource_id: str,
    resource_type: str,
    parent_ids: list[str],
    context_parent_id: str | None = None
) -> list[dict]

Generate HATEOAS links for poly-hierarchical STAC resources.

This helper method generates parent, related, canonical, and duplicate links for resources that can belong to multiple catalogs (poly-hierarchy).

Parameters:

Name Type Description Default
base_url None The base URL of the API. None
resource_id None The ID of the resource (collection or catalog). None
resource_type None Either "Collection" or "Catalog". None
parent_ids None List of parent catalog IDs. None
context_parent_id None The current catalog context (if accessing via scoped endpoint).
None means accessing via global endpoint (e.g., /collections/{id}).
None

Returns:

Type Description
None List of link dictionaries following STAC link relation conventions.

stac_to_db

def stac_to_db(
    stac_object: Any,
    base_url: str
) -> dict

Transform STAC object to database model.