Skip to content

Commit 49a7d6e

Browse files
committed
add deprecation warning
2 parents 61193b4 + 389706f commit 49a7d6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3398
-816
lines changed

Diff for: .github/workflows/cicd.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
python-version: ["3.7", "3.8", "3.9", "3.10"]
17+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1818

1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
2121

2222
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2
23+
uses: actions/setup-python@v4
2424
with:
2525
python-version: ${{ matrix.python-version }}
2626

2727
- name: Install dependencies
2828
run: |
2929
python -m pip install --upgrade pip
30-
python -m pip install tox codecov pre-commit
30+
python -m pip install tox pre-commit
31+
pre-commit install
3132
3233
# Run tox using the version of Python in `PATH`
3334
- name: Run Tox

Diff for: .github/workflows/release.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Release
22

33
on:
4+
workflow_dispatch:
45
release:
56
types:
67
- created
@@ -11,22 +12,22 @@ jobs:
1112
runs-on: ubuntu-latest
1213
if: ${{ github.repository }} == 'stac-utils/stac-pydantic'
1314
steps:
14-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1516

1617
- name: Set up Python 3.x
17-
uses: actions/setup-python@v2
18+
uses: actions/setup-python@v4
1819
with:
1920
python-version: "3.x"
2021

2122
- name: Install release dependencies
2223
run: |
2324
python -m pip install --upgrade pip
24-
pip install setuptools wheel twine
25+
python -m pip install build twine
2526
2627
- name: Build and publish package
2728
env:
2829
TWINE_USERNAME: ${{ secrets.PYPI_STACUTILS_USERNAME }}
2930
TWINE_PASSWORD: ${{ secrets.PYPI_STACUTILS_PASSWORD }}
3031
run: |
31-
python setup.py sdist bdist_wheel
32+
python -m build
3233
twine upload dist/*

Diff for: .gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ celerybeat-schedule
106106
# dotenv
107107
.env
108108

109+
# venv
110+
.venv
111+
109112
# Spyder project settings
110113
.spyderproject
111114
.spyproject
@@ -117,4 +120,4 @@ celerybeat-schedule
117120
/site
118121

119122
# skaffold temporary build/deploy files
120-
build.out
123+
build.out

Diff for: .pre-commit-config.yaml

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
13
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 22.3.0
4+
- repo: https://github.com/abravalheri/validate-pyproject
5+
rev: v0.16
46
hooks:
5-
- id: black
6-
language_version: python3
7-
args: ["--safe"]
7+
- id: validate-pyproject
8+
9+
- repo: https://github.com/pre-commit/pre-commit-hooks
10+
rev: v4.5.0
11+
hooks:
12+
- id: end-of-file-fixer
13+
- id: trailing-whitespace
14+
- id: check-yaml
15+
- id: check-added-large-files
16+
args: ["--maxkb=40960"]
817

918
- repo: https://github.com/PyCQA/isort
10-
rev: 5.10.1
19+
rev: 5.13.2
1120
hooks:
1221
- id: isort
13-
language_version: python3
22+
language_version: python
1423

15-
- repo: https://github.com/PyCQA/flake8
16-
rev: 4.0.1
24+
- repo: https://github.com/astral-sh/ruff-pre-commit
25+
rev: v0.3.5
1726
hooks:
18-
- id: flake8
19-
language_version: python3
27+
- id: ruff
28+
args: ["--fix"]
29+
- id: ruff-format
2030

2131
- repo: https://github.com/pre-commit/mirrors-mypy
22-
rev: v0.931
32+
rev: v1.9.0
2333
hooks:
2434
- id: mypy
25-
exclude: ^tests/
26-
args: [--strict]
27-
additional_dependencies: ["pydantic", "types-jsonschema", "types-setuptools", "types-requests"]
35+
language_version: python
36+
# No reason to run if only tests have changed. They intentionally break typing.
37+
exclude: tests/.*
38+
additional_dependencies:
39+
- types-requests

Diff for: CHANGELOG.txt

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
Unreleased
1+
3.1.0 (TBD)
2+
-----------------
3+
- Remove the deprecated `Context` extension (#138, @vincentsarago)
4+
- Rename `stac_pydantic.api.conformance.ConformanceClasses` to `stac_pydantic.api.conformance.Conformance`
5+
- Update pre-commit configuration and switch to astral-sh/ruff for linter and formater
6+
- Add official support for python 3.12
7+
- Enforce required `type` key for `Collection` and `Catalog` models
8+
- Add queryables link relation type (#123, @constantinius)
9+
- Fix STAC API Query Extension operator names from ne->neq, le->lte, and ge->gte (#120, @philvarner)
10+
11+
3.0.0 (2024-01-25)
212
------------------
3-
- Fix STAC API Query Extension operator names from ne->neq, le->lte, and ge->gte
13+
- Support pydantic>2.0 (@huard)
414

515
2.0.3 (2022-5-3)
616
------------------
@@ -106,4 +116,4 @@ Unreleased
106116
- Allow extra asset-level fields (#1)
107117
- Fix population by field name model config, allowing model creation without extension namespaces (#2)
108118
- Add enum of commonly used asset media types (#3)
109-
- Move geojson models to `geojson-pydantic` library (#4)
119+
- Move geojson models to `geojson-pydantic` library (#4)

Diff for: README.md

+92-25
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
1-
# stac-pydantic ![tests](https://github.com/arturo-ai/stac-pydantic/workflows/cicd/badge.svg)
2-
[Pydantic](https://pydantic-docs.helpmanual.io/) models for [STAC](https://github.com/radiantearth/stac-spec) Catalogs, Collections, Items, and the [STAC API](https://github.com/radiantearth/stac-api-spec) spec. Initially developed by [arturo-ai](https://github.com/arturo-ai).
1+
# stac-pydantic
2+
3+
[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/stac-utils/stac-pydantic/cicd.yml?style=for-the-badge)](https://github.com/stac-utils/stac-pydantic/actions/workflows/cicd.yml)
4+
5+
[Pydantic](https://pydantic-docs.helpmanual.io/) models for [STAC](https://github.com/radiantearth/stac-spec) Catalogs, Collections, Items, and the [STAC API](https://github.com/radiantearth/stac-api-spec) spec.
6+
Initially developed by [arturo-ai](https://github.com/arturo-ai).
7+
8+
The main purpose of this library is to provide reusable request/response models for tools such as [fastapi](https://fastapi.tiangolo.com/).
9+
For more comprehensive schema validation and robust extension support, use [pystac](https://github.com/stac-utils/pystac).
310

411
## Installation
5-
```
12+
13+
```shell
614
pip install stac-pydantic
715
```
816

917
For local development:
10-
```
11-
pip install -e .["dev"]
18+
19+
```shell
20+
pip install -e '.[dev,lint]'
1221
```
1322

14-
| stac-pydantic | STAC Version |
15-
|---------------|--------------|
16-
| 1.1.x | 0.9.0 |
17-
| 1.2.x | 1.0.0-beta.1 |
18-
| 1.3.x | 1.0.0-beta.2 |
19-
| 2.0.x | 1.0.0 |
23+
| stac-pydantic | STAC Version | STAC API Version | Pydantic Version |
24+
|--------------|---------------|------------------|-----------------|
25+
| 1.2.x | 1.0.0-beta.1 | <1* | ^1.6 |
26+
| 1.3.x | 1.0.0-beta.2 | <1* | ^1.6 |
27+
| 2.0.x | 1.0.0 | <1* | ^1.6 |
28+
| 3.0.x | 1.0.0 | 1.0.0 | ^2.4 |
29+
30+
\* various beta releases, specs not fully implemented
2031

2132
## Development
2233

@@ -31,11 +42,11 @@ pre-commit install
3142
Ensure you have all Python versions installed that the tests will be run against. If using pyenv, run:
3243

3344
```shell
34-
pyenv install 3.7.12
35-
pyenv install 3.8.12
36-
pyenv install 3.9.10
37-
pyenv install 3.10.2
38-
pyenv local 3.7.12 3.8.12 3.9.10 3.10.2
45+
pyenv install 3.8.18
46+
pyenv install 3.9.18
47+
pyenv install 3.10.13
48+
pyenv install 3.11.5
49+
pyenv local 3.8.18 3.9.18 3.10.13 3.11.5
3950
```
4051

4152
Run the entire test suite:
@@ -78,7 +89,8 @@ assert catalog.links[0].href == "item.json"
7889
```
7990

8091
### Extensions
81-
STAC defines many extensions which let the user customize the data in their catalog. `stac-pydantic.extensions.validate_extensions` will validate a `dict`, `Item`, `Collection` or `Catalog` against the schema urls provided in the `stac_extensions` property:
92+
93+
STAC defines many extensions which let the user customize the data in their catalog. `stac-pydantic.extensions.validate_extensions` will validate a `dict`, `Item`, `Collection` or `Catalog` against the schema urls provided in the `stac_extensions` property:
8294

8395
```python
8496
from stac_pydantic import Item
@@ -88,41 +100,96 @@ stac_item = {
88100
"id": "12345",
89101
"type": "Feature",
90102
"stac_extensions": [
91-
"https://stac-extensions.github.io/eo/v1.0.0/schema.json"
103+
"https://stac-extensions.github.io/eo/v1.0.0/schema.json"
92104
],
93105
"geometry": { "type": "Point", "coordinates": [0, 0] },
106+
"bbox": [0.0, 0.0, 0.0, 0.0],
94107
"properties": {
95108
"datetime": "2020-03-09T14:53:23.262208+00:00",
96109
"eo:cloud_cover": 25,
97110
},
98111
"links": [],
99-
"assets": [],
112+
"assets": {},
100113
}
101114

102-
model = Item(**stac_item)
115+
model = Item(**stac_item)
103116
validate_extensions(model, reraise_exception=True)
104-
assert getattr(model.properties, "eo:cloud_cover") == 25
117+
assert getattr(model.properties, "eo:cloud_cover") == 25
105118
```
106119

107120
The complete list of current STAC Extensions can be found [here](https://stac-extensions.github.io/).
108121

109122
#### Vendor Extensions
123+
110124
The same procedure described above works for any STAC Extension schema as long as it can be loaded from a public url.
111125

126+
### STAC API
127+
128+
The [STAC API Specs](https://github.com/radiantearth/stac-api-spec) extent the core STAC specification for implementing dynamic catalogs. STAC Objects used in an API context should always import models from the `api` subpackage. This package extends
129+
Catalog, Collection, and Item models with additional fields and validation rules and introduces Collections and ItemCollections models and Pagination/ Search Links.
130+
It also implements models for defining ItemSeach queries.
131+
132+
```python
133+
from stac_pydantic.api import Item, ItemCollection
134+
135+
stac_item = Item(**{
136+
"id": "12345",
137+
"type": "Feature",
138+
"stac_extensions": [],
139+
"geometry": { "type": "Point", "coordinates": [0, 0] },
140+
"bbox": [0.0, 0.0, 0.0, 0.0],
141+
"properties": {
142+
"datetime": "2020-03-09T14:53:23.262208+00:00",
143+
},
144+
"collection": "CS3",
145+
"links": [
146+
{
147+
"rel": "self",
148+
"href": "http://stac.example.com/catalog/collections/CS3-20160503_132130_04/items/CS3-20160503_132130_04.json"
149+
},
150+
{
151+
"rel": "collection",
152+
"href": "http://stac.example.com/catalog/CS3-20160503_132130_04/catalog.json"
153+
},
154+
{
155+
"rel": "root",
156+
"href": "http://stac.example.com/catalog"
157+
}],
158+
"assets": {},
159+
})
160+
161+
stac_item_collection = ItemCollection(**{
162+
"type": "FeatureCollection",
163+
"features": [stac_item],
164+
"links": [
165+
{
166+
"rel": "self",
167+
"href": "http://stac.example.com/catalog/search?collection=CS3",
168+
"type": "application/geo+json"
169+
},
170+
{
171+
"rel": "root",
172+
"href": "http://stac.example.com/catalog",
173+
"type": "application/json"
174+
}],
175+
})
176+
```
177+
112178
### Exporting Models
179+
113180
Most STAC extensions are namespaced with a colon (ex `eo:gsd`) to keep them distinct from other extensions. Because
114181
Python doesn't support the use of colons in variable names, we use [Pydantic aliasing](https://pydantic-docs.helpmanual.io/usage/model_config/#alias-generator)
115182
to add the namespace upon model export. This requires [exporting](https://pydantic-docs.helpmanual.io/usage/exporting_models/)
116-
the model with the `by_alias = True` parameter. A convenience method (``to_dict()``) is provided to export models with
117-
extension namespaces:
183+
the model with the `by_alias = True` parameter. Export methods (`model_dump()` and `model_dump_json()`) for models in this library have `by_alias` and `exclude_unset` st to `True` by default:
118184

119185
```python
120-
item_dict = item.to_dict()
186+
item_dict = item.model_dump()
121187
assert item_dict['properties']['landsat:row'] == item.properties.row == 250
122188
```
123189

124190
### CLI
125-
```
191+
192+
```text
126193
Usage: stac-pydantic [OPTIONS] COMMAND [ARGS]...
127194
128195
stac-pydantic cli group

0 commit comments

Comments
 (0)