Skip to content

Sync client base_url option #1171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion planet/cli/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def subscriptions(ctx, base_url):
"pending",
"completed",
"suspended",
"failed"
"failed",
"invalid",
]),
multiple=True,
help="Select subscriptions in one or more states. Default is all.")
Expand Down
21 changes: 16 additions & 5 deletions planet/sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .subscriptions import SubscriptionsAPI
from planet.http import Session
from planet.__version__ import __version__
from planet.constants import PLANET_BASE_URL

SYNC_CLIENT_X_PLANET_APP = "python-sdk-sync"

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

"""

def __init__(self, session: Optional[Session] = None) -> None:
def __init__(self,
session: Optional[Session] = None,
base_url: Optional[str] = None) -> None:
self._session = session or Session()
self._session._client.headers.update({
"X-Planet-App": SYNC_CLIENT_X_PLANET_APP,
"User-Agent": f"planet-client-python/{__version__}/sync",
})

self.data = DataAPI(self._session)
self.orders = OrdersAPI(self._session)
self.subscriptions = SubscriptionsAPI(self._session)
self.features = FeaturesAPI(self._session)
# Use provided base URL or default
planet_base = base_url or PLANET_BASE_URL

# Create API instances with service-specific URL paths
self.data = DataAPI(self._session, f"{planet_base}/data/v1/")
self.orders = OrdersAPI(self._session, f"{planet_base}/compute/ops")
self.subscriptions = SubscriptionsAPI(
self._session, f"{planet_base}/subscriptions/v1/")
self.features = FeaturesAPI(self._session,
f"{planet_base}/features/v1/ogc/my/")
52 changes: 52 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2025 Planet Labs PBC.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Tests for the synchronous Planet client."""

from planet.sync import Planet


class TestPlanetSyncClient:
"""Test cases for the Planet synchronous client."""

def test_planet_default_initialization(self):
"""Test that Planet client initializes correctly with defaults."""
pl = Planet()

assert pl.data is not None
assert pl.data._client._base_url == "https://api.planet.com/data/v1"

assert pl.orders is not None
assert pl.orders._client._base_url == "https://api.planet.com/compute/ops"

assert pl.subscriptions is not None
assert pl.subscriptions._client._base_url == "https://api.planet.com/subscriptions/v1"

assert pl.features is not None
assert pl.features._client._base_url == "https://api.planet.com/features/v1/ogc/my"

def test_planet_custom_base_url_initialization(self):
"""Test that Planet client accepts custom base URL."""
pl = Planet(base_url="https://custom.planet.com")

assert pl.data is not None
assert pl.data._client._base_url == "https://custom.planet.com/data/v1"

assert pl.orders is not None
assert pl.orders._client._base_url == "https://custom.planet.com/compute/ops"

assert pl.subscriptions is not None
assert pl.subscriptions._client._base_url == "https://custom.planet.com/subscriptions/v1"

assert pl.features is not None
assert pl.features._client._base_url == "https://custom.planet.com/features/v1/ogc/my"