Python行星计算机SDK
项目描述
Python行星计算机SDK
用于与微软行星计算机交互的Python库。
有关行星计算机的一般问题或讨论,请使用microsoft/PlanetaryComputer存储库。
安装
pip install planetary-computer
如果您有API订阅密钥,您可以通过包含的配置CLI将其提供给库
planetarycomputer configure
或者,可以通过在PC_SDK_SUBSCRIPTION_KEY
环境变量中指定它来提供订阅密钥。与该服务交互不需要订阅密钥,但是拥有一个可以允许更少限制的速率限制。
用法
此库有助于对Azure Blob Storage URL进行签名。sign
函数直接操作HREF字符串,以及几个PySTAC对象:Asset
、Item
和ItemCollection
。此外,sign
函数还接受STAC API客户端的ItemSearch
,它执行搜索并返回所有资产都已签名的结果ItemCollection
。
自动签名
如果您使用pystac-client,我们建议您使用其自动签名结果的功能,使用planetary_computer.sign_inplace
import planetary_computer
import pystac_client
from pystac_client import Client
import planetary_computer, requests
api = Client.open(
'https://planetarycomputer.microsoft.com/api/stac/v1',
modifier=planetary_computer.sign_inplace,
)
现在,您从该客户端获取的所有结果都将被签名。
手动签名
或者,您可以手动调用您的结果上的planetary_computer.sign
。
from pystac import Asset, Item, ItemCollection
from pystac_client import ItemSearch
import planetary_computer as pc
# The sign function may be called directly on the Item
raw_item: Item = ...
item: Item = pc.sign(raw_item)
# Now use the item however you want. All appropriate assets are signed for read access.
# The sign function also works with an Asset
raw_asset: Asset = raw_item.assets['SR_B4']
asset = pc.sign(raw_asset)
# The sign function also works with an HREF
raw_href: str = raw_asset.href
href = pc.sign(raw_href)
# The sign function also works with an ItemCollection
raw_item_collection = ItemCollection([raw_item])
item_collection = pc.sign(raw_item_collection)
# The sign function also accepts an ItemSearch, and signs the resulting ItemCollection
search = ItemSearch(
url=...,
bbox=...,
collections=...,
limit=...,
max_items=...,
)
signed_item_collection = pc.sign(search)
便利方法
有时您需要直接与Blob存储容器交互,而不是使用STAC项目。为此,我们提供了两种便利方法。
planetary_computer.get_container_client
:获取一个azure.storage.blob.ContainerClient
planetary_computer.get_adlfs_filesystem
:获取一个adlfs.AzureBlobFilesystem
开发
以下步骤可以按照顺序在本地进行开发:
## Create and activate venv
python3 -m venv env
source env/bin/activate
## Install requirements
python3 -m pip install -r requirements-dev.txt
## Install locally
pip install -e .
## Format code
./scripts/format
## Run tests
./scripts/test
贡献
本项目欢迎贡献和建议。大多数贡献需要您同意贡献者许可协议(CLA),声明您有权,并且实际上确实授予我们使用您贡献的权利。有关详细信息,请访问https://cla.opensource.microsoft.com。
当您提交拉取请求时,CLA机器人会自动确定您是否需要提供CLA,并适当地装饰PR(例如,状态检查、评论)。只需遵循机器人提供的说明即可。您只需在所有使用我们CLA的存储库中这样做一次。
本项目已采用微软开源行为准则。有关更多信息,请参阅行为准则常见问题解答或通过opencode@microsoft.com联系以获取任何其他问题或评论。
商标
本项目可能包含项目、产品或服务的商标或徽标。微软商标或徽标的授权使用受微软商标和品牌指南的约束,并必须遵循。在此项目的修改版本中使用微软商标或徽标不得引起混淆或暗示微软的赞助。任何使用第三方商标或徽标的行为均受那些第三方政策的约束。
项目详情
planetary-computer-1.0.0.tar.gz的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 5958a8e1d8ba1aafc7ac45878df2d7d03405806ae31ed2e675333faebca960cc |
|
MD5 | d51b57ce8592625e901a634dd97becf0 |
|
BLAKE2b-256 | 9bd3ccfb0e823e9beb72b7e6b749f0985c4db1530d4e4a145b1b5d12f5de417e |