Planetary Computer¶
obstore.auth.planetary_computer.PlanetaryComputerCredentialProvider ¶
A CredentialProvider for AzureStore for accessing Planetary Computer data resources.
This credential provider uses requests
, and will error if that cannot be imported.
Examples:
from obstore.store import AzureStore
from obstore.auth.planetary_computer import PlanetaryComputerCredentialProvider
url = "https://naipeuwest.blob.core.windows.net/naip/v002/mt/2023/mt_060cm_2023/"
# Construct an AzureStore with this credential provider.
#
# The account, container, and container prefix are passed down to AzureStore
# automatically.
store = AzureStore(credential_provider=PlanetaryComputerCredentialProvider(url))
# List some items in the container
items = next(store.list())
# Fetch a thumbnail
path = "44106/m_4410602_nw_13_060_20230712_20240103.200.jpg"
image_content = store.get(path).bytes()
# Write out the image content to a file in the current directory
with open("thumbnail.jpg", "wb") as f:
f.write(image_content)
__init__ ¶
__init__(
url: str | None = None,
*,
account_name: str | None = None,
container_name: str | None = None,
session: Session | None = None,
subscription_key: str | None = None,
sas_url: str | None = None,
) -> None
Construct a new PlanetaryComputerCredentialProvider.
Parameters:
-
url
(str | None
, default:None
) –Either the
https
orabfs
URL of blob storage to mount to, such as"https://daymeteuwest.blob.core.windows.net/daymet-zarr/daily"
or"abfs://daymet-zarr/daily/hi.zarr"
.For
abfs
URLs,account_name
must be provided.For
https
URLs, neitheraccount_name
norcontainer_name
may be provided.If
url
is not provided,account_name
andcontainer_name
must be provided. Defaults toNone
.
Other Parameters:
-
account_name
(str | None
) –The Azure storage account name. Must be provided for
abfs
URLs. Ifurl
is not provided, both this andcontainer_name
must be provided. Defaults toNone
. -
container_name
(str | None
) –The Azure storage container name. If
url
is not provided, both this andaccount_name
must be provided. Defaults toNone
. -
session
(Session | None
) –The requests session to use for making requests to the Planetary Computer token API. Defaults to
None
. -
subscription_key
(str | None
) –A Planetary Computer subscription key.
Precedence is as follows:
- Uses the passed-in value if not
None
. - Uses the environment variable
PC_SDK_SUBSCRIPTION_KEY
if set. - Uses the value of
PC_SDK_SUBSCRIPTION_KEY
in~/.planetarycomputer/settings.env
, if that file exists (requirespython-dotenv
as a dependency). - Defaults to
None
, which may apply request throttling.
- Uses the passed-in value if not
-
sas_url
(str | None
) –The URL base for requesting new Planetary Computer SAS tokens.
Precedence is as follows:
- Uses the passed-in value if not
None
. - Uses the environment variable
PC_SDK_SAS_URL
if set. - Uses the value of
PC_SDK_SAS_URL
in~/.planetarycomputer/settings.env
, if that file exists (requirespython-dotenv
as a dependency). - Defaults to
"https://planetarycomputer.microsoft.com/api/sas/v1/token"
.
- Uses the passed-in value if not
from_asset
classmethod
¶
from_asset(
asset: Asset | dict[str, Any],
*,
session: Session | None = None,
subscription_key: str | None = None,
sas_url: str | None = None,
) -> Self
Create from a STAC Asset.
Parameters:
Other Parameters:
-
session
(Session | None
) –The requests session, passed on as a keyword argument to
__init__
. -
subscription_key
(str | None
) –A Planetary Computer subscription key, passed on as a keyword argument to
__init__
. -
sas_url
(str | None
) –The URL base for requesting new Planetary Computer SAS tokens, passed on as a keyword argument to
__init__
.
Examples:
import pystac_client
from obstore.auth.planetary_computer import PlanetaryComputerCredentialProvider
stac_url = "https://planetarycomputer.microsoft.com/api/stac/v1/"
catalog = pystac_client.Client.open(stac_url)
collection = catalog.get_collection("daymet-daily-hi")
asset = collection.assets["zarr-abfs"]
credential_provider = PlanetaryComputerCredentialProvider.from_asset(asset)
obstore.auth.planetary_computer.PlanetaryComputerAsyncCredentialProvider ¶
A CredentialProvider for AzureStore for accessing Planetary Computer data resources.
__init__ ¶
__init__(
url: str | None = None,
*,
account_name: str | None = None,
container_name: str | None = None,
session: ClientSession | None = None,
subscription_key: str | None = None,
sas_url: str | None = None,
) -> None
Construct a new PlanetaryComputerAsyncCredentialProvider.
This credential provider uses aiohttp
, and will error if that cannot be
imported.
Refer to PlanetaryComputerCredentialProvider for argument explanations.
from_asset
classmethod
¶
from_asset(
asset: Asset | dict[str, Any],
*,
session: ClientSession | None = None,
subscription_key: str | None = None,
sas_url: str | None = None,
) -> Self
Create from a STAC Asset.
Refer to PlanetaryComputerCredentialProvider.from_asset for argument explanations.