Skip to content

Commit 1adae09

Browse files
Sync client base_url option (#1171)
* update base url option * simplify to base_url
1 parent 4dbe92b commit 1adae09

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

planet/cli/subscriptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def subscriptions(ctx, base_url):
8787
"pending",
8888
"completed",
8989
"suspended",
90-
"failed"
90+
"failed",
91+
"invalid",
9192
]),
9293
multiple=True,
9394
help="Select subscriptions in one or more states. Default is all.")

planet/sync/client.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .subscriptions import SubscriptionsAPI
77
from planet.http import Session
88
from planet.__version__ import __version__
9+
from planet.constants import PLANET_BASE_URL
910

1011
SYNC_CLIENT_X_PLANET_APP = "python-sdk-sync"
1112

@@ -37,17 +38,27 @@ class Planet:
3738
Parameters:
3839
session: Optional Session. The Session can be provided allowing for customization, and
3940
will default to standard behavior when not provided.
41+
base_url: Optional base URL for Planet APIs. Defaults to (https://api.planet.com).
42+
Each API will append its specific path suffix (/data/v1, /compute/ops, etc.).
4043
4144
"""
4245

43-
def __init__(self, session: Optional[Session] = None) -> None:
46+
def __init__(self,
47+
session: Optional[Session] = None,
48+
base_url: Optional[str] = None) -> None:
4449
self._session = session or Session()
4550
self._session._client.headers.update({
4651
"X-Planet-App": SYNC_CLIENT_X_PLANET_APP,
4752
"User-Agent": f"planet-client-python/{__version__}/sync",
4853
})
4954

50-
self.data = DataAPI(self._session)
51-
self.orders = OrdersAPI(self._session)
52-
self.subscriptions = SubscriptionsAPI(self._session)
53-
self.features = FeaturesAPI(self._session)
55+
# Use provided base URL or default
56+
planet_base = base_url or PLANET_BASE_URL
57+
58+
# Create API instances with service-specific URL paths
59+
self.data = DataAPI(self._session, f"{planet_base}/data/v1/")
60+
self.orders = OrdersAPI(self._session, f"{planet_base}/compute/ops")
61+
self.subscriptions = SubscriptionsAPI(
62+
self._session, f"{planet_base}/subscriptions/v1/")
63+
self.features = FeaturesAPI(self._session,
64+
f"{planet_base}/features/v1/ogc/my/")

tests/unit/test_client.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2025 Planet Labs PBC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
# use this file except in compliance with the License. You may obtain a copy of
5+
# the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations under
13+
# the License.
14+
"""Tests for the synchronous Planet client."""
15+
16+
from planet.sync import Planet
17+
18+
19+
class TestPlanetSyncClient:
20+
"""Test cases for the Planet synchronous client."""
21+
22+
def test_planet_default_initialization(self):
23+
"""Test that Planet client initializes correctly with defaults."""
24+
pl = Planet()
25+
26+
assert pl.data is not None
27+
assert pl.data._client._base_url == "https://api.planet.com/data/v1"
28+
29+
assert pl.orders is not None
30+
assert pl.orders._client._base_url == "https://api.planet.com/compute/ops"
31+
32+
assert pl.subscriptions is not None
33+
assert pl.subscriptions._client._base_url == "https://api.planet.com/subscriptions/v1"
34+
35+
assert pl.features is not None
36+
assert pl.features._client._base_url == "https://api.planet.com/features/v1/ogc/my"
37+
38+
def test_planet_custom_base_url_initialization(self):
39+
"""Test that Planet client accepts custom base URL."""
40+
pl = Planet(base_url="https://custom.planet.com")
41+
42+
assert pl.data is not None
43+
assert pl.data._client._base_url == "https://custom.planet.com/data/v1"
44+
45+
assert pl.orders is not None
46+
assert pl.orders._client._base_url == "https://custom.planet.com/compute/ops"
47+
48+
assert pl.subscriptions is not None
49+
assert pl.subscriptions._client._base_url == "https://custom.planet.com/subscriptions/v1"
50+
51+
assert pl.features is not None
52+
assert pl.features._client._base_url == "https://custom.planet.com/features/v1/ogc/my"

0 commit comments

Comments
 (0)