Package: here-location-services
HERE Location Services for PythonA Python client forHERE Location Services.UsageGeocoding using HERE Geocoding & Search API.Isolines using HERE Isoline Routing API.PrerequisitesBefore you can installHERE Location Services for Python, run its test-suite, or use the example notebooks to make sure you meet the following prerequisites:A Python installation, 3.6+ recommended, with thepipcommand available to install dependencies.In order to use Location services APIs, authentication is required.
There are two ways to authenticate:Authentication using an API key:For API key-based authentication you will need a HERE developer account, freely available underHERE Developer Portal.AnAPI keyfrom theHERE Developer Portal, in an environment variable namedLS_API_KEYwhich you can set like this (with a valid value, of course):$exportLS_API_KEY="MY-LS-API-KEY"OAuth token-based authentication:For OAuth token authentication you will need an account on the HERE Platform.
To get more details on the HERE Platform account please check our documentationGet a HERE account.
Once you have the account follow the below steps to get credentials:Go toHERE Platform Applications and Keysand register a new app.Create a key for the app and download the generatedcredentials. propertiesfile.The HERE platform generated app credentials should look similar to the example below:here.user.id = <example_here>
here.client.id = <example_here>
here.access.key.id = <example_here>
here.access.key.secret = <example_here>
here.token.endpoint.url = <example_here>You can provide your credentials using any of the following methods:Default credentialsEnvironment variablesCredentials fileDefault credentialsPlace the credentials file intoFor Linux/MacOS:$HOME/.here/credentials.propertiesFor Windows:%USERPROFILE%\.here\credentials.propertiesCode snippet to instantiate LS object:fromhere_location_servicesimportLS# platform credentials will be picked from the default credentials file's location mentioned above# and api_key should not be set in env variable LS_API_KEY.ls=LS()Environment VariablesYou can override default credentials by assigning values to the following environment variables:HERE_USER_ID
HERE_CLIENT_ID
HERE_ACCESS_KEY_ID
HERE_ACCESS_KEY_SECRET
HERE_TOKEN_ENDPOINT_URLCode snippet to instantiate LS object:fromhere_location_servicesimportLSfromhere_location_servicesimportPlatformCredentialsls=LS(platform_credentials=PlatformCredentials.from_env())Credentials FileYou can specify any credentials file as an alternative to that found in~/.here/credentials.properties. An error is generated if there is no file present at the path, or if the file is not properly formatted.
Code snippet to instantiate LS object:fromhere_location_servicesimportLSfromhere_location_servicesimportPlatformCredentialsplatform_credentials=PlatformCredentials.from_credentials_file("<Path_to_file>")ls=LS(platform_credentials=platform_credentials)InstallationInstallHERE Location Services for Pythonwith conda from the Anacondaconda-forge channelusing the below command:$condainstall-cconda-forgehere-location-servicesInstallHERE Location Services for PythonfromPyPIusing the below command:$pipinstallhere-location-servicesInstallHERE Location Services for Pythonfrom GitHub using the below command:$pipinstall-egit+https://github.com/heremaps/here-location-services-python#egg=here-location-servicesRun Test SuiteRun the test suite using below commands:$pipinstall-rrequirements_dev.txt
$pytest-v--cov=here_location_servicestestsDocumentationDocumentation is availablehere.Run the below commands to build the docs locally:$pipinstall-e.
$pipinstall-rrequirements_dev.txt
$shscripts/build_docs.shHello World ExampleThe following are tiny "Hello World" like examples that you can run to have a successful first XYZ experience right after installation!Using API keyimportjsonimportosfromhere_location_servicesimportLSLS_API_KEY=os.environ.get("LS_API_KEY")# Get API KEY from environment.ls=LS(api_key=LS_API_KEY)address="Invalidenstr 116, 10115 Berlin, Germany"geo=ls.geocode(query=address)print(json.dumps(geo.to_geojson(),indent=2,sort_keys=True))Using OAuth tokenimportjsonfromhere_location_servicesimportLSfromhere_location_servicesimportPlatformCredentialscredentials=PlatformCredentials.from_default()ls=LS(platform_credentials=credentials)address="Invalidenstr 116, 10115 Berlin, Germany"geo=ls.geocode(query=address)print(json.dumps(geo.to_geojson(),indent=2,sort_keys=True))LicenseCopyright (C) 2019-2021 HERE Europe B.V.See theLicensefile at the root of this project for license details.