### Install Planet SDK for Python using pip Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide This snippet demonstrates how to install the Planet SDK for Python using the `pip` package manager. This is the standard and recommended method for setting up the SDK in your Python environment. ```bash pip install planet ``` -------------------------------- ### Manually Construct Planet Data Filters in Python Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide Provides an example of how to manually create a Planet Data API filter as a Python dictionary, which directly corresponds to the required JSON blob. This allows for direct integration of pre-existing Data API filters into the SDK. ```Python sfilter = { 'type': 'AndFilter', 'config': [ {'type': 'PermissionFilter', 'config': ['assets:download']}, { 'type': 'DateRangeFilter', 'field_name': 'acquired', 'config': {'gt': '2022-06-01T01:00:00Z'} } ] } ``` -------------------------------- ### Initialize Planet Client with PL_API_KEY environment variable Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide This Python code initializes the main `Planet` client class. It automatically detects the Planet API key from the `PL_API_KEY` environment variable, simplifying the authentication process for most use cases. ```python from planet import Planet pl = Planet() # automatically detects PL_API_KEY ``` -------------------------------- ### Search Planet Catalog with Python SDK Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide Demonstrates how to search for items in the Planet catalog using the `data.search()` method of the Planet Python SDK. It returns an iterator that yields search results, allowing for efficient retrieval of catalog items. ```Python from planet import Planet pl = Planet() for item in pl.data.search(['PSScene'], limit=5): print(item) ``` -------------------------------- ### Download and Validate Single Planet Asset with Python SDK Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide Outlines the multi-step process for downloading a single asset from the Planet Data API, including activating the asset, waiting for activation, downloading, and validating the checksum. Progress reporting is included to track long-running processes. ```Python def download_and_validate(): pl = Planet() # get asset description item_type_id = 'PSScene' item_id = '20221003_002705_38_2461' asset_type_id = 'ortho_analytic_4b' asset = pl.data.get_asset(item_type_id, item_id, asset_type_id) # activate asset pl.data.activate_asset(asset) # wait for asset to become active asset = pl.data.wait_asset(asset, callback=print) # download asset path = pl.data.download_asset(asset) # validate download file pl.data.validate_checksum(asset, path) ``` -------------------------------- ### Set PL_API_KEY environment variable for Planet SDK Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide This command sets the `PL_API_KEY` environment variable in your shell, which the Planet SDK for Python uses for authentication. Ensure you replace `your_api_key` with your actual Planet API key before execution. ```bash export PL_API_KEY=your_api_key ``` -------------------------------- ### List Planet SDK Python Features API Collections Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide This snippet demonstrates how to retrieve and iterate through existing feature collections using the Planet SDK for Python. It uses 'pl.features.list_collections()' to fetch all collections and then prints each one. ```Python collections = pl.features.list_collections() for collection in collections: print(collection) ``` -------------------------------- ### Place and Download Planet Orders with Python SDK Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide Explains how to place an order for multiple assets using the Planet Orders API client. It demonstrates building an order request, creating the order, waiting for its completion, and finally downloading the ordered assets, noting potential quota usage. ```Python from planet import Planet, order_request def main(): pl = Planet() image_ids = ["20200925_161029_69_2223"] request = order_request.build_request( name='test_order', products=[ order_request.product( item_ids=image_ids, product_bundle='analytic_8b_udm2', item_type='PSScene', fallback_bundle='analytic_udm2,analytic_3b_udm2') ] ) order = pl.orders.create_order(request) # wait for the order to be ready # note: this may take several minutes. pl.orders.wait(order['id']) pl.orders.download_order(order['id'], overwrite=True) ``` -------------------------------- ### Authenticate Planet SDK using Session class and APIKeyAuth Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide This Python snippet illustrates an alternative authentication method using the `Session` class and `APIKeyAuth`. This approach is useful when you prefer to explicitly pass the API key within your code, rather than relying on environment variables. ```python from planet import Auth, Session, Auth from planet.auth import APIKeyAuth pl = Planet(session=Session(auth=APIKeyAuth(key='your_api_key'))) ``` -------------------------------- ### Create Planet SDK Python Scene Subscription Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide This snippet demonstrates how to build and create a scene subscription using the Planet SDK for Python. It utilizes the 'planet.subscription_request' module to define source and delivery parameters, specifically for AWS S3. Be aware that executing this code will create a subscription and consume quota based on your Planet plan. ```Python from planet.subscription_request import catalog_source, build_request, amazon_s3 source = catalog_source( ["PSScene"], ["ortho_analytic_4b"], geometry={ "type": "Polygon", "coordinates": [ [ [37.791595458984375, 14.84923123791421], [37.90214538574219, 14.84923123791421], [37.90214538574219, 14.945448293647944], [37.791595458984375, 14.945448293647944], [37.791595458984375, 14.84923123791421] ] ] }, start_time=datetime.now(), publishing_stages=["standard"], time_range_type="acquired", ) request = build_request("Standard PSScene Ortho Analytic", source=source, delivery={}) # define a delivery method. In this example, we're using AWS S3. delivery = amazon_s3(ACCESS_KEY_ID, SECRET_ACCESS_KEY, "test", "us-east-1") # finally, create the subscription subscription = pl.subscriptions.create_subscription(request) ``` -------------------------------- ### Create Planet SDK Python Features API Collection Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide This snippet illustrates how to create a new feature collection within the Features API using the Planet SDK for Python. Collections created via the SDK will be visible and manageable through the Features API and Features Manager. ```Python new_collection = pl.features.create_collection(title="my collection", description="a new collection") ``` -------------------------------- ### Apply Data Filters with Python data_filter Module Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide Shows how to construct complex data search filters using the `planet.data_filter` module, combining multiple conditions like permissions and date ranges. This method programmatically builds the request JSON, ensuring correct filter syntax. ```Python from datetime import datetime from planet import data_filter def main(): pl = Planet() sfilter = data_filter.and_filter([ data_filter.permission_filter(), data_filter.date_range_filter('acquired', gt=datetime(2022, 6, 1, 1)) ]) for item in pl.data.search(['PSScene'], filter=sfilter, limit=10): print(item["id"]) ``` -------------------------------- ### Filter Planet Search by Geometry in Python Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide Illustrates how to filter Planet catalog search results by a specified geographic geometry using the `geometry` parameter in the `data.search()` method. The geometry is defined as a GeoJSON Polygon, enabling spatial queries. ```Python geom = { "coordinates": [ [ [ -125.41267816101056, 46.38901501783491 ], [ -125.41267816101056, 41.101114161051015 ], [ -115.51426167332103, 41.101114161051015 ], [ -115.51426167332103, 46.38901501783491 ], [ -125.41267816101056, 46.38901501783491 ] ] ], "type": "Polygon" } for item in pl.data.search(['PSScene'], geometry=geom, limit=5): print(item) ``` -------------------------------- ### List Planet SDK Python Features API Items in Collection Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide This snippet shows how to list and iterate through individual features (items) within a specified collection using the Planet SDK for Python. It requires a 'collection_id' to identify the target collection. ```Python items = pl.features.list_items(collection_id) for item in items: print(item) ``` -------------------------------- ### Planet SDK Python API Exception Hierarchy Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide This documentation outlines the exception hierarchy for the Planet SDK for Python. All SDK exceptions inherit from 'PlanetError'. Client-side errors are raised as 'ClientError', while server-side errors are specific exceptions inheriting from 'APIError', containing the original server message. ```APIDOC All exceptions inherit from the base exception called `PlanetError`. Client-side errors are raised as `ClientError`. Server-side errors are raised as specific exceptions based on the http code. These specific exceptions all inherit from `APIError` and contain the original error message returned by the server. ``` -------------------------------- ### Use Planet SDK Python Features API Items as Geometries Source: https://planet-sdk-for-python-v2.readthedocs.io/en/latest/python/sdk-guide/latest/python/sdk-guide This snippet demonstrates how to directly use Features API items as geometries for other SDK methods, such as data searches. When passed, the feature reference will be used, linking searches or subscriptions to your feature. Note that reserving quota for features is not currently supported directly in the SDK. ```Python # collection_id: the ID of a collection in Features API items = pl.features.list_items(collection_id) example_feature = next(items) results = pl.data.search(["PSScene"], geometry=example_feature) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.