titiler-pgstac 1.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation and other contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.1
2
+ Name: titiler.pgstac
3
+ Version: 1.2.3
4
+ Summary: Connect PgSTAC and TiTiler.
5
+ Keywords: COG,STAC,MosaicJSON,Fastapi,Dynamic tile server,pgSTAC
6
+ Author-email: Vincent Sarago <vincent@developmentseed.com>,David Bitner <david@developmentseed.com>
7
+ Requires-Python: >=3.8
8
+ Classifier: Intended Audience :: Information Technology
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Topic :: Scientific/Engineering :: GIS
17
+ Provides-Extra: dev
18
+ Provides-Extra: psycopg
19
+ Provides-Extra: psycopg-binary
20
+ Provides-Extra: psycopg-c
21
+ Provides-Extra: test
22
+ Project-URL: Changelog, https://stac-utils.github.io/titiler-pgstac/release-notes/
23
+ Project-URL: Documentation, https://stac-utils.github.io/titiler-pgstac/
24
+ Project-URL: Homepage, https://stac-utils.github.io/titiler-pgstac/
25
+ Project-URL: Issues, https://github.com/stac-utils/titiler-pgstac/issues
26
+ Project-URL: Source, https://github.com/stac-utils/titiler-pgstac
27
+ Description-Content-Type: text/markdown
28
+
29
+ <p align="center">
30
+ <img width="500" src="https://github.com/stac-utils/titiler-pgstac/assets/10407788/24a64ea9-fede-4ee8-ab8d-625c9e94db44"/>
31
+ <p align="center">Connect PgSTAC and TiTiler.</p>
32
+ </p>
33
+
34
+ <p align="center">
35
+ <a href="https://github.com/stac-utils/titiler-pgstac/actions?query=workflow%3ACI" target="_blank">
36
+ <img src="https://github.com/stac-utils/titiler-pgstac/workflows/CI/badge.svg" alt="Test">
37
+ </a>
38
+ <a href="https://codecov.io/gh/stac-utils/titiler-pgstac" target="_blank">
39
+ <img src="https://codecov.io/gh/stac-utils/titiler-pgstac/branch/main/graph/badge.svg" alt="Coverage">
40
+ </a>
41
+ <a href="https://pypi.org/project/titiler.pgstac" target="_blank">
42
+ <img src="https://img.shields.io/pypi/v/titiler.pgstac?color=%2334D058&label=pypi%20package" alt="Package version">
43
+ </a>
44
+ <a href="https://github.com/stac-utils/titiler-pgstac/blob/main/LICENSE" target="_blank">
45
+ <img src="https://img.shields.io/github/license/stac-utils/titiler-pgstac.svg" alt="License">
46
+ </a>
47
+ </p>
48
+
49
+ ---
50
+
51
+ **Documentation**: <a href="https://stac-utils.github.io/titiler-pgstac/" target="_blank">https://stac-utils.github.io/titiler-pgstac/</a>
52
+
53
+ **Source Code**: <a href="https://github.com/stac-utils/titiler-pgstac" target="_blank">https://github.com/stac-utils/titiler-pgstac</a>
54
+
55
+ ---
56
+
57
+ **TiTiler-PgSTAC** is a [TiTiler](https://github.com/developmentseed/titiler) extension that connects to a [PgSTAC](https://github.com/stac-utils/pgstac) database to create dynamic **mosaics** based on [search queries](https://github.com/radiantearth/stac-api-spec/tree/master/item-search).
58
+
59
+ ## Installation
60
+
61
+ To install from PyPI and run:
62
+
63
+ ```bash
64
+ # Make sure to have pip up to date
65
+ $ python -m pip install -U pip
66
+
67
+ # Install `psycopg` or `psycopg["binary"]` or `psycopg["c"]`
68
+ $ python -m pip install psycopg["binary"]
69
+
70
+ $ python -m pip install titiler.pgstac
71
+ ```
72
+
73
+ To install from sources and run for development:
74
+
75
+ ```
76
+ $ git clone https://github.com/stac-utils/titiler-pgstac.git
77
+ $ cd titiler-pgstac
78
+ $ python -m pip install -e .
79
+ ```
80
+
81
+ ### `PgSTAC` version
82
+
83
+ `titiler.pgstac` depends on `pgstac >=0.3.4` (https://github.com/stac-utils/pgstac/blob/main/CHANGELOG.md#v034).
84
+
85
+ ### `psycopg` requirement
86
+
87
+ `titiler.pgstac` depends on the `psycopg` library. Because there are three ways of installing this package (`psycopg` or , `psycopg["c"]`, `psycopg["binary"]`), the user must install this separately from `titiler.pgstac`.
88
+
89
+ - `psycopg`: no wheel, pure python implementation. It requires the `libpq` installed in the system.
90
+ - `psycopg["binary"]`: binary wheel distribution (shipped with libpq) of the `psycopg` package and is simpler for development. It requires development packages installed on the client machine.
91
+ - `psycopg["c"]`: a C (faster) implementation of the libpq wrapper. It requires the `libpq` installed in the system.
92
+
93
+ `psycopg[c]` or `psycopg` are generally recommended for production use.
94
+
95
+ In `titiler.pgstac` setup.py, we have added three options to let users choose which psycopg install to use:
96
+
97
+ - `pip install titiler.pgstac["psycopg"]`: pure python
98
+ - `pip install titiler.pgstac["psycopg-c"]`: use the C wrapper (requires development packages installed on the client machine)
99
+ - `pip install titiler.pgstac["psycopg-binary"]`: binary wheels
100
+
101
+ ## Launch
102
+
103
+ You'll need to have `POSTGRES_USER`, `POSTGRES_PASS`, `POSTGRES_DBNAME`, `POSTGRES_HOST`, `POSTGRES_PORT` variables set in your environment pointing to your Postgres database where pgstac has been installed.
104
+
105
+ ```
106
+ export POSTGRES_USER=username
107
+ export POSTGRES_PASS=password
108
+ export POSTGRES_DBNAME=postgis
109
+ export POSTGRES_HOST=database
110
+ export POSTGRES_PORT=5432
111
+ ```
112
+
113
+ ```
114
+ $ pip install uvicorn
115
+ $ uvicorn titiler.pgstac.main:app --reload
116
+ ```
117
+
118
+ ### Using Docker
119
+
120
+ ```
121
+ $ git clone https://github.com/stac-utils/titiler-pgstac.git
122
+ $ cd titiler-pgstac
123
+ $ docker-compose up --build tiler
124
+ ```
125
+
126
+ It runs `titiler.pgstac` using Gunicorn web server. To run Uvicorn based version:
127
+
128
+ ```
129
+ $ docker-compose up --build tiler-uvicorn
130
+ ```
131
+
132
+ ## Contribution & Development
133
+
134
+ See [CONTRIBUTING.md](https://github.com//stac-utils/titiler-pgstac/blob/main/CONTRIBUTING.md)
135
+
136
+ ## License
137
+
138
+ See [LICENSE](https://github.com//stac-utils/titiler-pgstac/blob/main/LICENSE)
139
+
140
+ ## Authors
141
+
142
+ See [contributors](https://github.com/stac-utils/titiler-pgstac/graphs/contributors) for a listing of individual contributors.
143
+
144
+ ## Changes
145
+
146
+ See [CHANGES.md](https://github.com/stac-utils/titiler-pgstac/blob/main/CHANGES.md).
147
+
@@ -0,0 +1,118 @@
1
+ <p align="center">
2
+ <img width="500" src="https://github.com/stac-utils/titiler-pgstac/assets/10407788/24a64ea9-fede-4ee8-ab8d-625c9e94db44"/>
3
+ <p align="center">Connect PgSTAC and TiTiler.</p>
4
+ </p>
5
+
6
+ <p align="center">
7
+ <a href="https://github.com/stac-utils/titiler-pgstac/actions?query=workflow%3ACI" target="_blank">
8
+ <img src="https://github.com/stac-utils/titiler-pgstac/workflows/CI/badge.svg" alt="Test">
9
+ </a>
10
+ <a href="https://codecov.io/gh/stac-utils/titiler-pgstac" target="_blank">
11
+ <img src="https://codecov.io/gh/stac-utils/titiler-pgstac/branch/main/graph/badge.svg" alt="Coverage">
12
+ </a>
13
+ <a href="https://pypi.org/project/titiler.pgstac" target="_blank">
14
+ <img src="https://img.shields.io/pypi/v/titiler.pgstac?color=%2334D058&label=pypi%20package" alt="Package version">
15
+ </a>
16
+ <a href="https://github.com/stac-utils/titiler-pgstac/blob/main/LICENSE" target="_blank">
17
+ <img src="https://img.shields.io/github/license/stac-utils/titiler-pgstac.svg" alt="License">
18
+ </a>
19
+ </p>
20
+
21
+ ---
22
+
23
+ **Documentation**: <a href="https://stac-utils.github.io/titiler-pgstac/" target="_blank">https://stac-utils.github.io/titiler-pgstac/</a>
24
+
25
+ **Source Code**: <a href="https://github.com/stac-utils/titiler-pgstac" target="_blank">https://github.com/stac-utils/titiler-pgstac</a>
26
+
27
+ ---
28
+
29
+ **TiTiler-PgSTAC** is a [TiTiler](https://github.com/developmentseed/titiler) extension that connects to a [PgSTAC](https://github.com/stac-utils/pgstac) database to create dynamic **mosaics** based on [search queries](https://github.com/radiantearth/stac-api-spec/tree/master/item-search).
30
+
31
+ ## Installation
32
+
33
+ To install from PyPI and run:
34
+
35
+ ```bash
36
+ # Make sure to have pip up to date
37
+ $ python -m pip install -U pip
38
+
39
+ # Install `psycopg` or `psycopg["binary"]` or `psycopg["c"]`
40
+ $ python -m pip install psycopg["binary"]
41
+
42
+ $ python -m pip install titiler.pgstac
43
+ ```
44
+
45
+ To install from sources and run for development:
46
+
47
+ ```
48
+ $ git clone https://github.com/stac-utils/titiler-pgstac.git
49
+ $ cd titiler-pgstac
50
+ $ python -m pip install -e .
51
+ ```
52
+
53
+ ### `PgSTAC` version
54
+
55
+ `titiler.pgstac` depends on `pgstac >=0.3.4` (https://github.com/stac-utils/pgstac/blob/main/CHANGELOG.md#v034).
56
+
57
+ ### `psycopg` requirement
58
+
59
+ `titiler.pgstac` depends on the `psycopg` library. Because there are three ways of installing this package (`psycopg` or , `psycopg["c"]`, `psycopg["binary"]`), the user must install this separately from `titiler.pgstac`.
60
+
61
+ - `psycopg`: no wheel, pure python implementation. It requires the `libpq` installed in the system.
62
+ - `psycopg["binary"]`: binary wheel distribution (shipped with libpq) of the `psycopg` package and is simpler for development. It requires development packages installed on the client machine.
63
+ - `psycopg["c"]`: a C (faster) implementation of the libpq wrapper. It requires the `libpq` installed in the system.
64
+
65
+ `psycopg[c]` or `psycopg` are generally recommended for production use.
66
+
67
+ In `titiler.pgstac` setup.py, we have added three options to let users choose which psycopg install to use:
68
+
69
+ - `pip install titiler.pgstac["psycopg"]`: pure python
70
+ - `pip install titiler.pgstac["psycopg-c"]`: use the C wrapper (requires development packages installed on the client machine)
71
+ - `pip install titiler.pgstac["psycopg-binary"]`: binary wheels
72
+
73
+ ## Launch
74
+
75
+ You'll need to have `POSTGRES_USER`, `POSTGRES_PASS`, `POSTGRES_DBNAME`, `POSTGRES_HOST`, `POSTGRES_PORT` variables set in your environment pointing to your Postgres database where pgstac has been installed.
76
+
77
+ ```
78
+ export POSTGRES_USER=username
79
+ export POSTGRES_PASS=password
80
+ export POSTGRES_DBNAME=postgis
81
+ export POSTGRES_HOST=database
82
+ export POSTGRES_PORT=5432
83
+ ```
84
+
85
+ ```
86
+ $ pip install uvicorn
87
+ $ uvicorn titiler.pgstac.main:app --reload
88
+ ```
89
+
90
+ ### Using Docker
91
+
92
+ ```
93
+ $ git clone https://github.com/stac-utils/titiler-pgstac.git
94
+ $ cd titiler-pgstac
95
+ $ docker-compose up --build tiler
96
+ ```
97
+
98
+ It runs `titiler.pgstac` using Gunicorn web server. To run Uvicorn based version:
99
+
100
+ ```
101
+ $ docker-compose up --build tiler-uvicorn
102
+ ```
103
+
104
+ ## Contribution & Development
105
+
106
+ See [CONTRIBUTING.md](https://github.com//stac-utils/titiler-pgstac/blob/main/CONTRIBUTING.md)
107
+
108
+ ## License
109
+
110
+ See [LICENSE](https://github.com//stac-utils/titiler-pgstac/blob/main/LICENSE)
111
+
112
+ ## Authors
113
+
114
+ See [contributors](https://github.com/stac-utils/titiler-pgstac/graphs/contributors) for a listing of individual contributors.
115
+
116
+ ## Changes
117
+
118
+ See [CHANGES.md](https://github.com/stac-utils/titiler-pgstac/blob/main/CHANGES.md).
@@ -0,0 +1,141 @@
1
+ [project]
2
+ name = "titiler.pgstac"
3
+ description = "Connect PgSTAC and TiTiler."
4
+ readme = "README.md"
5
+ requires-python = ">=3.8"
6
+ authors = [
7
+ { name = "Vincent Sarago", email = "vincent@developmentseed.com" },
8
+ { name = "David Bitner", email = "david@developmentseed.com" },
9
+ ]
10
+ keywords = [
11
+ "COG",
12
+ "STAC",
13
+ "MosaicJSON",
14
+ "Fastapi",
15
+ "Dynamic tile server",
16
+ "pgSTAC",
17
+ ]
18
+ classifiers = [
19
+ "Intended Audience :: Information Technology",
20
+ "Intended Audience :: Science/Research",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Programming Language :: Python :: 3.8",
23
+ "Programming Language :: Python :: 3.9",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Topic :: Scientific/Engineering :: GIS",
28
+ ]
29
+ dependencies = [
30
+ "titiler.core>=0.17.0,<0.18",
31
+ "titiler.mosaic>=0.17.0,<0.18",
32
+ "geojson-pydantic~=1.0",
33
+ "pydantic>=2.4,<3.0",
34
+ "pydantic-settings~=2.0",
35
+ ]
36
+ dynamic = []
37
+ version = "1.2.3"
38
+
39
+ [project.license]
40
+ file = "LICENSE"
41
+
42
+ [project.optional-dependencies]
43
+ psycopg = [
44
+ "psycopg[pool]",
45
+ ]
46
+ psycopg-c = [
47
+ "psycopg[c,pool]",
48
+ ]
49
+ psycopg-binary = [
50
+ "psycopg[binary,pool]",
51
+ ]
52
+ dev = [
53
+ "pre-commit",
54
+ ]
55
+ test = [
56
+ "pytest",
57
+ "pytest-cov",
58
+ "pytest-asyncio",
59
+ "httpx",
60
+ "pypgstac>=0.8,<0.9",
61
+ "psycopg2",
62
+ "pytest-pgsql",
63
+ ]
64
+
65
+ [project.urls]
66
+ Homepage = "https://stac-utils.github.io/titiler-pgstac/"
67
+ Documentation = "https://stac-utils.github.io/titiler-pgstac/"
68
+ Issues = "https://github.com/stac-utils/titiler-pgstac/issues"
69
+ Source = "https://github.com/stac-utils/titiler-pgstac"
70
+ Changelog = "https://stac-utils.github.io/titiler-pgstac/release-notes/"
71
+
72
+ [build-system]
73
+ requires = [
74
+ "pdm-pep517",
75
+ ]
76
+ build-backend = "pdm.pep517.api"
77
+
78
+ [tool.pdm.version]
79
+ source = "file"
80
+ path = "titiler/pgstac/__init__.py"
81
+
82
+ [tool.pdm.build]
83
+ includes = [
84
+ "titiler/pgstac",
85
+ ]
86
+ excludes = [
87
+ "tests/",
88
+ "**/.mypy_cache",
89
+ "**/.DS_Store",
90
+ ]
91
+
92
+ [tool.coverage.run]
93
+ branch = true
94
+ parallel = true
95
+
96
+ [tool.coverage.report]
97
+ exclude_lines = [
98
+ "no cov",
99
+ "if __name__ == .__main__.:",
100
+ "if TYPE_CHECKING:",
101
+ ]
102
+
103
+ [tool.isort]
104
+ profile = "black"
105
+ known_first_party = [
106
+ "titiler",
107
+ ]
108
+ known_third_party = [
109
+ "rasterio",
110
+ "morecantile",
111
+ "rio_tiler",
112
+ "cogeo_mosaic",
113
+ "geojson_pydantic",
114
+ ]
115
+ default_section = "THIRDPARTY"
116
+
117
+ [tool.ruff]
118
+ select = [
119
+ "D1",
120
+ "E",
121
+ "W",
122
+ "F",
123
+ "C",
124
+ "B",
125
+ ]
126
+ ignore = [
127
+ "E501",
128
+ "B008",
129
+ "B905",
130
+ ]
131
+
132
+ [tool.mypy]
133
+ no_implicit_optional = true
134
+ strict_optional = true
135
+ namespace_packages = true
136
+ explicit_package_bases = true
137
+
138
+ [tool.pytest.ini_options]
139
+ filterwarnings = [
140
+ "ignore::rasterio.errors.NotGeoreferencedWarning",
141
+ ]
@@ -0,0 +1,3 @@
1
+ """titiler.pgstac"""
2
+
3
+ __version__ = "1.2.3"
@@ -0,0 +1,43 @@
1
+ """Database connection handling."""
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+ from fastapi import FastAPI
6
+ from psycopg_pool import ConnectionPool
7
+
8
+ from titiler.pgstac.settings import PostgresSettings
9
+
10
+
11
+ async def connect_to_db(
12
+ app: FastAPI,
13
+ settings: Optional[PostgresSettings] = None,
14
+ pool_kwargs: Optional[Dict[str, Any]] = None,
15
+ ) -> None:
16
+ """Connect to Database."""
17
+ if not settings:
18
+ settings = PostgresSettings()
19
+
20
+ pool_kwargs = (
21
+ pool_kwargs
22
+ if pool_kwargs is not None
23
+ else {"options": "-c search_path=pgstac,public -c application_name=pgstac"}
24
+ )
25
+
26
+ app.state.dbpool = ConnectionPool(
27
+ conninfo=str(settings.database_url),
28
+ min_size=settings.db_min_conn_size,
29
+ max_size=settings.db_max_conn_size,
30
+ max_waiting=settings.db_max_queries,
31
+ max_idle=settings.db_max_idle,
32
+ num_workers=settings.db_num_workers,
33
+ kwargs=pool_kwargs,
34
+ )
35
+
36
+ # Make sure the pool is ready
37
+ # ref: https://www.psycopg.org/psycopg3/docs/advanced/pool.html#pool-startup-check
38
+ app.state.dbpool.wait()
39
+
40
+
41
+ async def close_db_connection(app: FastAPI) -> None:
42
+ """Close Pool."""
43
+ app.state.dbpool.close()