Skip to content

Commit 89dfe75

Browse files
Merge pull request #118 from duckontheweb/add/117-query-param-auth
Allow query parameters
2 parents 17d3909 + a01f4c8 commit 89dfe75

File tree

6 files changed

+878
-12
lines changed

6 files changed

+878
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010

1111
- Adds `--block-network` option to all test commands to ensure no network requests are made during unit tests
1212
[#119](https://github.com/stac-utils/pystac-client/pull/119)
13+
- `parameters` argument to `StacApiIO`, `Client.open`, and `Client.from_file` to allow query string parameters to be passed to all requests
14+
[#118](https://github.com/stac-utils/pystac-client/pull/118)
1315

1416
### Fixed
1517

pystac_client/client.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ def __repr__(self):
2727
return '<Client id={}>'.format(self.id)
2828

2929
@classmethod
30-
def open(cls,
31-
url: str,
32-
headers: Dict[str, str] = None,
33-
ignore_conformance: bool = False) -> "Client":
30+
def open(
31+
cls,
32+
url: str,
33+
headers: Dict[str, str] = None,
34+
parameters: Optional[Dict[str, Any]] = None,
35+
ignore_conformance: bool = False,
36+
) -> "Client":
3437
"""Opens a STAC Catalog or API
3538
This function will read the root catalog of a STAC Catalog or API
3639
@@ -44,7 +47,7 @@ def open(cls,
4447
Return:
4548
catalog : A :class:`Client` instance for this Catalog/API
4649
"""
47-
cat = cls.from_file(url, headers=headers)
50+
cat = cls.from_file(url, headers=headers, parameters=parameters)
4851
search_link = cat.get_links('search')
4952
# if there is a search link, but no conformsTo advertised, ignore conformance entirely
5053
# NOTE: this behavior to be deprecated as implementations become conformant
@@ -54,17 +57,20 @@ def open(cls,
5457
return cat
5558

5659
@classmethod
57-
def from_file(cls,
58-
href: str,
59-
stac_io: Optional[pystac.StacIO] = None,
60-
headers: Optional[Dict] = {}) -> "Client":
60+
def from_file(
61+
cls,
62+
href: str,
63+
stac_io: Optional[pystac.StacIO] = None,
64+
headers: Optional[Dict] = {},
65+
parameters: Optional[Dict] = None,
66+
) -> "Client":
6167
"""Open a STAC Catalog/API
6268
6369
Returns:
6470
Client: A Client (PySTAC Catalog) of the root Catalog for this Catalog/API
6571
"""
6672
if stac_io is None:
67-
stac_io = StacApiIO(headers=headers)
73+
stac_io = StacApiIO(headers=headers, parameters=parameters)
6874

6975
cat = super().from_file(href, stac_io)
7076

pystac_client/stac_api_io.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,27 @@
3636

3737

3838
class StacApiIO(DefaultStacIO):
39-
def __init__(self, headers: Optional[Dict] = None, conformance: Optional[List[str]] = None):
39+
def __init__(
40+
self,
41+
headers: Optional[Dict] = None,
42+
conformance: Optional[List[str]] = None,
43+
parameters: Optional[Dict] = None,
44+
):
4045
"""Initialize class for API IO
4146
4247
Args:
4348
headers : Optional dictionary of headers to include in all requests
49+
conformance : Optional list of `Conformance Classes
50+
<https://github.com/radiantearth/stac-api-spec/blob/master/overview.md#conformance-classes>`__.
51+
parameters: Optional dictionary of query string parameters to include in all requests.
4452
4553
Return:
4654
StacApiIO : StacApiIO instance
4755
"""
4856
# TODO - this should super() to parent class
4957
self.session = Session()
5058
self.session.headers.update(headers or {})
59+
self.session.params.update(parameters or {})
5160

5261
self._conformance = conformance
5362

0 commit comments

Comments
 (0)