Skip to content

config

stac_fastapi.pgstac.config

Postgres API configuration.

PostgresSettings

Bases: BaseSettings

Postgres-specific API settings.

Attributes:

  • postgres_user (str) –

    postgres username.

  • postgres_pass (str) –

    postgres password.

  • postgres_host_reader (str) –

    hostname for the reader connection.

  • postgres_host_writer (str) –

    hostname for the writer connection.

  • postgres_port (int) –

    database port.

  • postgres_dbname (str) –

    database name.

  • use_api_hydrate (str) –

    perform hydration of stac items within stac-fastapi.

  • invalid_id_chars (str) –

    list of characters that are not allowed in item or collection ids.

Source code in stac_fastapi/pgstac/config.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class PostgresSettings(BaseSettings):
    """Postgres-specific API settings.

    Attributes:
        postgres_user: postgres username.
        postgres_pass: postgres password.
        postgres_host_reader: hostname for the reader connection.
        postgres_host_writer: hostname for the writer connection.
        postgres_port: database port.
        postgres_dbname: database name.
        use_api_hydrate: perform hydration of stac items within stac-fastapi.
        invalid_id_chars: list of characters that are not allowed in item or collection ids.
    """

    postgres_user: str
    postgres_pass: str
    postgres_host_reader: str
    postgres_host_writer: str
    postgres_port: int
    postgres_dbname: str

    db_min_conn_size: int = 1
    db_max_conn_size: int = 10
    db_max_queries: int = 50000
    db_max_inactive_conn_lifetime: float = 300

    server_settings: ServerSettings = ServerSettings()

    model_config = {"env_file": ".env", "extra": "ignore"}

    @property
    def reader_connection_string(self):
        """Create reader psql connection string."""
        return f"postgresql://{self.postgres_user}:{quote(self.postgres_pass)}@{self.postgres_host_reader}:{self.postgres_port}/{self.postgres_dbname}"

    @property
    def writer_connection_string(self):
        """Create writer psql connection string."""
        return f"postgresql://{self.postgres_user}:{quote(self.postgres_pass)}@{self.postgres_host_writer}:{self.postgres_port}/{self.postgres_dbname}"

    @property
    def testing_connection_string(self):
        """Create testing psql connection string."""
        return f"postgresql://{self.postgres_user}:{quote(self.postgres_pass)}@{self.postgres_host_writer}:{self.postgres_port}/pgstactestdb"

reader_connection_string property

reader_connection_string

Create reader psql connection string.

testing_connection_string property

testing_connection_string

Create testing psql connection string.

writer_connection_string property

writer_connection_string

Create writer psql connection string.

ServerSettings

Bases: BaseModel

Server runtime parameters.

Attributes:

  • search_path (str) –

    Postgres search path. Defaults to "pgstac,public".

  • application_name (str) –

    PgSTAC Application name. Defaults to 'pgstac'.

Source code in stac_fastapi/pgstac/config.py
37
38
39
40
41
42
43
44
45
46
47
48
class ServerSettings(BaseModel):
    """Server runtime parameters.

    Attributes:
        search_path: Postgres search path. Defaults to "pgstac,public".
        application_name: PgSTAC Application name. Defaults to 'pgstac'.
    """

    search_path: str = "pgstac,public"
    application_name: str = "pgstac"

    model_config = SettingsConfigDict(extra="allow")

Settings

Bases: ApiSettings

Api Settings.

Source code in stac_fastapi/pgstac/config.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class Settings(ApiSettings):
    """Api Settings."""

    use_api_hydrate: bool = False
    invalid_id_chars: List[str] = DEFAULT_INVALID_ID_CHARS
    base_item_cache: Type[BaseItemCache] = DefaultBaseItemCache

    cors_origins: str = "*"
    cors_methods: str = "GET,POST,OPTIONS"

    testing: bool = False

    @field_validator("cors_origins")
    def parse_cors_origin(cls, v):
        """Parse CORS origins."""
        return [origin.strip() for origin in v.split(",")]

    @field_validator("cors_methods")
    def parse_cors_methods(cls, v):
        """Parse CORS methods."""
        return [method.strip() for method in v.split(",")]

parse_cors_methods

parse_cors_methods(v)

Parse CORS methods.

Source code in stac_fastapi/pgstac/config.py
114
115
116
117
@field_validator("cors_methods")
def parse_cors_methods(cls, v):
    """Parse CORS methods."""
    return [method.strip() for method in v.split(",")]

parse_cors_origin

parse_cors_origin(v)

Parse CORS origins.

Source code in stac_fastapi/pgstac/config.py
109
110
111
112
@field_validator("cors_origins")
def parse_cors_origin(cls, v):
    """Parse CORS origins."""
    return [origin.strip() for origin in v.split(",")]