![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
This package contains a Python SDK for Azure Maps Services for Render. Read more about Azure Maps Services here
Source code | API reference documentation | Product documentation
Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer to https://github.com/Azure/azure-sdk-for-python/issues/20691
If you use Azure CLI, replace <resource-group-name>
and <account-name>
of your choice, and select a proper pricing tier based on your needs via the <sku-name>
parameter. Please refer to this page for more details.
az maps account create --resource-group <resource-group-name> --account-name <account-name> --sku <sku-name>
Install the Azure Maps Service Render SDK.
pip install azure-maps-render
To create a client object to access the Azure Maps Render API, you will need a credential object. Azure Maps Render client also support three ways to authenticate.
You can authenticate with your Azure Maps Subscription Key.
Once the Azure Maps Subscription Key is created, set the value of the key as environment variable: AZURE_SUBSCRIPTION_KEY
.
Then pass an AZURE_SUBSCRIPTION_KEY
as the credential
parameter into an instance of AzureKeyCredential.
from azure.core.credentials import AzureKeyCredential
from azure.maps.render import MapsRenderClient
credential = AzureKeyCredential(os.environ.get("AZURE_SUBSCRIPTION_KEY"))
render_client = MapsRenderClient(
credential=credential,
)
Shared access signature (SAS) tokens are authentication tokens created using the JSON Web token (JWT) format and are cryptographically signed to prove authentication for an application to the Azure Maps REST API.
To authenticate with a SAS token in Python, you'll need to generate one using the azure-mgmt-maps package.
We need to tell user to install azure-mgmt-maps
: pip install azure-mgmt-maps
Here's how you can generate the SAS token using the list_sas method from azure-mgmt-maps:
from azure.identity import DefaultAzureCredential
from azure.mgmt.maps import AzureMapsManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-maps
# USAGE
python account_list_sas.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = AzureMapsManagementClient(
credential=DefaultAzureCredential(),
subscription_id="your-subscription-id",
)
response = client.accounts.list_sas(
resource_group_name="myResourceGroup",
account_name="myMapsAccount",
maps_account_sas_parameters={
"expiry": "2017-05-24T11:42:03.1567373Z",
"maxRatePerSecond": 500,
"principalId": "your-principal-id",
"regions": ["eastus"],
"signingKey": "primaryKey",
"start": "2017-05-24T10:42:03.1567373Z",
},
)
print(response)
Once the SAS token is created, set the value of the token as environment variable: AZURE_SAS_TOKEN
.
Then pass an AZURE_SAS_TOKEN
as the credential
parameter into an instance of AzureSasCredential.
import os
from azure.core.credentials import AzureSASCredential
from azure.maps.render import MapsRenderClient
credential = AzureSASCredential(os.environ.get("AZURE_SAS_TOKEN"))
render_client = MapsRenderClient(
credential=credential,
)
You can authenticate with Microsoft Entra ID token credential using the Azure Identity library. Authentication by using Microsoft Entra ID requires some initial setup:
After setup, you can choose which type of credential from azure.identity
to use.
As an example, DefaultAzureCredential
can be used to authenticate the client:
Next, set the values of the client ID, tenant ID, and client secret of the Microsoft Entra ID application as environment variables:
AZURE_CLIENT_ID
, AZURE_TENANT_ID
, AZURE_CLIENT_SECRET
You will also need to specify the Azure Maps resource you intend to use by specifying the clientId
in the client options. The Azure Maps resource client id can be found in the Authentication sections in the Azure Maps resource. Please refer to the documentation on how to find it.
from azure.maps.render import MapsRenderClient
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()
render_client = MapsRenderClient(
client_id="<Azure Maps Client ID>",
credential=credential
)
The Azure Maps Render client library for Python allows you to interact with each of the components through the use of a dedicated client object.
MapsRenderClient
is the primary client for developers using the Azure Maps Render client library for Python.
Once you initialized a MapsRenderClient
class, you can explore the methods on this client object to understand the different features of the Azure Maps Render service that you can access.
This library includes a complete async API supported on Python 3.8+. To use it, you must first install an async transport, such as aiohttp. See azure-core documentation for more information.
Async clients and credentials should be closed when they're no longer needed. These
objects are async context managers and define async close
methods.
The following sections provide several code snippets covering some of the most common Azure Maps Render tasks, including:
This request allows users to request map copyright attribution information for a section of a tileset.
from azure.core.credentials import AzureKeyCredential
from azure.maps.render import MapsRenderClient
from azure.maps.render import TilesetID
maps_render_client = MapsRenderClient(credential=AzureKeyCredential(subscription_key))
result = maps_render_client.get_map_attribution(
tileset_id=TilesetID.MICROSOFT_BASE,
zoom=6,
bounds=[42.982261, 24.980233, 56.526017, 1.355233],
)
This request will return map tiles in vector or raster formats typically to be integrated into a map control or SDK. Some example tiles that can be requested are Azure Maps road tiles, real-time Weather Radar tiles. By default, Azure Maps uses vector tiles for its web map control (Web SDK) and Android SDK.
from azure.core.credentials import AzureKeyCredential
from azure.maps.render import MapsRenderClient
from azure.maps.render import TilesetID
maps_render_client = MapsRenderClient(credential=AzureKeyCredential(subscription_key))
result = maps_render_client.get_map_tile(
tileset_id=TilesetID.MICROSOFT_BASE,
z=6,
x=9,
y=22,
tile_size="512"
)
This request will give metadata for a tileset.
from azure.core.credentials import AzureKeyCredential
from azure.maps.render import MapsRenderClient
from azure.maps.render import TilesetID
maps_render_client = MapsRenderClient(credential=AzureKeyCredential(subscription_key))
result = maps_render_client.get_map_tileset(tileset_id=TilesetID.MICROSOFT_BASE)
This request will provide the static image service renders a user-defined, rectangular image containing a map section using a zoom level from 0 to 20. The static image service renders a user-defined, rectangular image containing a map section using a zoom level from 0 to 20. And also save the result to file as png.
from azure.maps.render import MapsRenderClient
maps_render_client = MapsRenderClient(credential=AzureKeyCredential(subscription_key))
result = maps_render_client.get_map_static_image(
zoom=10,
bounding_box_private=[13.228, 52.4559, 13.5794, 52.629]
)
This request will serve copyright information for Render Tile service.
from azure.core.credentials import AzureKeyCredential
from azure.maps.render import MapsRenderClient
maps_render_client = MapsRenderClient(credential=AzureKeyCredential(subscription_key))
result = maps_render_client.get_copyright_for_world()
Maps Render clients raise exceptions defined in Azure Core.
This list can be used for reference to catch thrown exceptions. To get the specific error code of the exception, use the error_code
attribute, i.e, exception.error_code
.
This library uses the standard logging library for logging. Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO level.
Detailed DEBUG level logging, including request/response bodies and unredacted headers, can be enabled on a client with the logging_enable
argument:
import sys
import logging
from azure.maps.render import MapsRenderClient
# Create a logger for the 'azure.maps.render' SDK
logger = logging.getLogger('azure.maps.render')
logger.setLevel(logging.DEBUG)
# Configure a console output
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)
Still running into issues? If you encounter any bugs or have suggestions, please file an issue in the Issues section of the project.
Get started with our Maps Render samples (Async Version samples).
Several Azure Maps Render Python SDK samples are available to you in the SDK's GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Maps Render
set AZURE_SUBSCRIPTION_KEY="<RealSubscriptionKey>"
pip install azure-maps-render --pre
python samples/sample_authentication.py
python samples/sample_get_copyright_caption.py
python samples/sample_get_copyright_for_tile.py
python samples/sample_get_copyright_for_world.py
python samples/sample_get_copyright_from_bounding_box.py
python samples/sample_get_map_attribution.py
python samples/sample_get_map_static_image.py
python samples/sample_get_map_tile.py
python samples/sample_get_map_tileset.py
Notes:
--pre
flag can be optionally added, it is to include pre-release and development versions forpip install
. By default,pip
only finds stable versions.
Further detail please refer to Samples Introduction
For more extensive documentation on Azure Maps Render, see the Azure Maps Render documentation on docs.microsoft.com.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
2024-04-01
FAQs
Microsoft Azure Maps Render Client Library for Python
We found that azure-maps-render demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.