Platform Operations

Accessing the HERE Platform

The HERE Data SDK for Python provides interaction with HERE platform through the Platform object. There are two standard platform environments supported by the SDK:

Each of these platform environments has its own set of credentials. If you are accessing the default environment and using default credentials, create a Platform object as shown below:

from here.platform import Platform
platform = Platform()

To interact with a different environment and/or provide alternate credentials, pass either or both of the corresponding optional parameters in the Platform constructor:

from here.platform import Platform
from here.platform.environment import Environment
platform = Platform(credentials=platform_cred, environment=Environment.CHINA)

See the Credentials section of this document for details of the different ways to provide credentials.

Create the Platform Object With HTTP Proxies

If you need to use a HTTP proxy, you can create and retrieve the Platform object by passing a proxy configuration. For more details, see Proxies.

from here.platform import Platform
proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}
platform = Platform(proxies=proxies)

Create the Platform Object With Adapter

If you plan to use pandas/GeoPandas in your code, you should create the Platform object passing a GeoPandasAdapter. This will adapt all of the standard platform operations to work seamlessly with the data structures provided by pandas/GeoPandas. See the Using GeoPandas section of this document for information on working with the GeoPandasAdapter.

from here.geopandas_adapter import GeoPandasAdapter
from here.platform import Platform
platform = Platform(adapter=GeoPandasAdapter())

Support for Local Catalogs

A local catalog is a special catalog encoded in a file and stored in your ~/.here/local/ directory. No authentication and no access to the external network are needed to use local catalogs. Local catalogs can be optionally created and stored in memory, rather than persisted on disk, which makes them especially useful during development and automated testing.

To learn more about local catalogs and how to install/run a Local Data Service, refer to the official documentation here.

In order to access such local catalogs with HERE Data SDK for Python, you must create a Platform object specifying LOCAL as the environment:

from here.platform import Platform
from here.platform.environment import Environment
platform = Platform(environment=Environment.LOCAL)

Notes

  • Your Local Data Server must be running and available via http://127.0.0.1:31005 before creating the Platform object
  • No credentials are needed to create a Platform object with environment=Environment.LOCAL
  • SDK methods which do make sense in a local environment (e.g. Platform.get_status()) raise an exception if called

Platform Operations

When you have created a Platform object, you can:

Below you will find a list of common operations at the platform level. Refer to later sections of this document to learn about the catalog and project operations available to you for catalog and project objects. For details on optional arguments and return types of methods presented, refer to the API documentation.

Get the Platform Environment

from here.platform import Platform
platform = Platform()
env = platform.environment

Get the Platform Config

from here.platform import Platform
platform = Platform()
config = platform.platform_config

Single field

config.api
'api.platform.here.com'

All fields

config.__dict__
{
    'api': 'api.platform.here.com',
    'portal_url': 'https://platform.here.com',
    'status_url': 'https://status.here.com/status',
    'platform_status_url': 'https://status.here.com/api/here/v1/status',
    'account_url': 'https://account.api.here.com'
}

Get the Platform Status

from here.platform import Platform
platform = Platform()
status = platform.get_status()
status
{'result': {'status': 'ok', 'description': 'all systems operational'}}

Get Catalog Object

Get the catalog object of the given HRN. An error is generated if the catalog does not exist or if your credentials are not valid.

from here.platform import Platform
platform = Platform()
hrn = "hrn:here:data::olp-here:oma-3"
catalog = platform.get_catalog(hrn=hrn)

Check if Catalog Exists

Check if a catalog exists for a given HRN. Returns True or False depending on whether the catalog exists.

from here.platform import Platform
platform = Platform()
hrn = "hrn:here:data::olp-here:rib-2"
result = platform.catalog_exists(hrn=hrn)
result
True

Create Catalog

Create a catalog and get the generated catalog object.

from here.platform import Platform
platform = Platform()
catalog = platform.create_catalog(id="catalog-id", name="name-of-the-catalog",
             summary="summary of the catalog", description="description of the catalog",
             tags=["tag1", "tag2"])

Create Catalog with Layers

You can define and create one or more layers at the time of catalog creation.

layer1 = {
    "id": "temp-layer",
    "name": "temp-layer-name",
    "summary": "temp-layer-summary",
    "description": "temp-layer-description",
    "contentType": "application/json",
    "layerType": "volatile",
    "partitioning": {
        "scheme": "generic"
    }
}

catalog = platform.create_catalog(id=catalog_id, name='name-of-the-catalog',
                             summary='summary-of-the-catalog', description='description-of-the-catalog', layers=[layer1],
                             tags=["test", "analytics"])

Clone Existing Catalog

In addition to creating catalogs "from scratch", you can create a new catalog by cloning an existing one. The new clone will have same configuration details as the source but will be empty of data.

# Clone a catalog and all of its layers
    platform = Platform()
    weather_na = platform.get_catalog("hrn:here:data::olp-here:live-weather-na")
    weather_na_details = weather_na.get_details()
    cat = platform.clone_catalog(
        source=weather_na,
        id="weather-clone-all-layers",
        description="weather-clone-catalog",
    )
    cat_details = cat.get_details()

If you would like your clone to contain only a subset of the layers in the source catalog, add the list of layers to keep in layers argument.

# Clone catalog and one of its layers
    platform = Platform()
    weather_na = platform.get_catalog("hrn:here:data::olp-here:live-weather-na")
    weather_na_details = weather_na.get_details()
    cat = platform.clone_catalog(
        source=weather_na,
        id="weather-clone-one-layer",
        description="weather-clone-catalog",
        layers=["latest-data"],
    )
    cat_details = cat.get_details()

List Catalogs

List all the catalogs accessible on the HERE platform. Optionally, search and return only catalogs specified by filter criteria. Filter critera are given as exact values for any item in catalog details (name, coverage, owner, etc.). A list of Catalog objects is returned.

from here.platform import Platform
platform = Platform()
list_of_catalogs = platform.list_catalogs(coverage='CN')

List Layers

List all layers of all catalogs accessible on the HERE platform. Optionally, search and return only layers of catalog which satisfies the filter. Filter will be applied to catalog. A list of Layer objects of filtered catalogs will be returned.

from here.platform import Platform
platform = Platform()
list_of_layers = platform.list_layers(layerType = 'index')

Modify Catalog

Modify the catalog details, including name, summary, and description. This replaces the complete details of the catalog. After this call succeedes, obtain a new catalog via get_catalog to have access to the modified details, including affected layers. This is used to modify catalog fields.

from here.platform import Platform
platform = Platform()
platform.modify_catalog(hrn="hrn:here:data::olp-here:update", name='updated-name',
                        description='updated-description')

Update Catalog

Update any descriptive and structural information in the catalog. To update a catalog, send a new version of your catalog configuration with the updated data and any required fields.

from here.platform import Platform
platform = Platform()
platform.update_catalog(hrn='hrn:here:data::olp-here:update', id='update', name='update-name',
                        summary='update-summary', description='update-description')

Update Catalog - Add layers

The update_catalog method allows you to add one or more new layers to an existing catalog.

from here.platform import Platform
platform = Platform()
layer1 = {
    "id": "temp-layer1",
    "name": "temp-layer1-update-name",
    "summary": "temp-layer1-summary",
    "description": "temp-layer1-description",
    "contentType": "application/json",
    "layerType": "volatile",
    "partitioning": {"scheme": "generic"},
}
layer2 = {
    "id": "temp-layer2",
    "name": "temp-layer2-update-name",
    "summary": "temp-layer2-summary",
    "description": "temp-layer2-description",
    "contentType": "application/json",
    "layerType": "volatile",
    "partitioning": {"scheme": "generic"},
}

platform.update_catalog(catalog.hrn, id=catalog_id, name="updated-name2", summary="updated-summary2", description="updated-description2", layers=[layer1,layer2])

# Refresh the updated catalog
catalog = platform.get_catalog(catalog.hrn)

Adding or Updating a Single Layer

If you wish to add or update only one layer you can use the simplified catalog level add_layer and update_layer methods. See the Catalog Operations section for details.

Delete Catalog

Delete a catalog together with the layers it contains.

from here.platform import Platform
platform = Platform()
platform.delete_catalog(hrn='hrn:here:data::olp-here:sample-catalog')

Get Project

Get a project object for the given HRN.

from here.platform import Platform
platform = Platform()
project_object = platform.get_project("hrn:here:authorization::olp-here:project/test")

Create Project

from here.platform import Platform
platform = Platform()
created_project_object = platform.create_project("hrn:here:authorization::olp-here:sample-test-project")

List Projects

Get the list of projects where you are a project admin or a member based on the can_manage and is_member.

from here.platform import Platform
platform = Platform()
project_list = platform.list_projects()

Update Project

Update the project metadata.

from here.platform import Platform
platform = Platform()
project_list = platform.update_project(hrn ="hrn:here:authorization::olp-here:sample-test-project" ,
                                       project_name="sample-project-name", project_desc="sample project desc")

Delete Project

Delete a project together with the catalogs it contains.

from here.platform import Platform
platform = Platform()
project_list = platform.delete_project("hrn:here:authorization::olp-here:sample-test-project")

Leave Project

Leave the specified project.

from here.platform import Platform
platform = Platform()
project_list = platform.leave_project("hrn:here:authorization::olp-here:sample-test-project")

results matching ""

    No results matching ""