Package: azure-maps-render
Azure Maps Render Package client library for PythonThis package contains a Python SDK for Azure Maps Services for Render.
Read more about Azure Maps ServiceshereSource code|API reference documentation|Product documentationDisclaimerAzure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer tohttps://github.com/Azure/azure-sdk-for-python/issues/20691Getting startedPrerequisitesPython 3.7 or later is required to use this package.AnAzure subscriptionand anAzure Maps account.A deployed Maps Services resource. You can create the resource viaAzure PortalorAzure CLI.If you use Azure CLI, replace<resource-group-name>and<account-name>of your choice, and select a properpricing tierbased on your needs via the<sku-name>parameter. Please refer tothis pagefor more details.azmapsaccountcreate--resource-group<resource-group-name>--account-name<account-name>--sku<sku-name>Install the packageInstall the Azure Maps Service Render SDK.pipinstallazure-maps-renderCreate and Authenticate the MapsRenderClientTo create a client object to access the Azure Maps Render API, you will need acredentialobject. Azure Maps Render client also support two ways to authenticate.1. Authenticate with a Subscription Key CredentialYou 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 anAZURE_SUBSCRIPTION_KEYas thecredentialparameter into an instance ofAzureKeyCredential.fromazure.core.credentialsimportAzureKeyCredentialfromazure.maps.renderimportMapsRenderClientcredential=AzureKeyCredential(os.environ.get("AZURE_SUBSCRIPTION_KEY"))render_client=MapsRenderClient(credential=credential,)2. Authenticate with an Azure Active Directory credentialYou can authenticate withAzure Active Directory (AAD) token credentialusing theAzure Identity library.
Authentication by using AAD requires some initial setup:Installazure-identityRegister anew AAD applicationGrant access to Azure Maps by assigning the suitable role to your service principal. Please refer to theManage authentication page.After setup, you can choose which type ofcredentialfromazure.identityto use.
As an example,DefaultAzureCredentialcan be used to authenticate the client:Next, 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_SECRETYou will also need to specify the Azure Maps resource you intend to use by specifying theclientIdin the client options. The Azure Maps resource client id can be found in the Authentication sections in the Azure Maps resource. Please refer to thedocumentationon how to find it.fromazure.maps.renderimportMapsRenderClientfromazure.identityimportDefaultAzureCredentialcredential=DefaultAzureCredential()render_client=MapsRenderClient(client_id="<Azure Maps Client ID>",credential=credential)Key conceptsThe Azure Maps Render client library for Python allows you to interact with each of the components through the use of a dedicated client object.Sync ClientsMapsRenderClientis the primary client for developers using the Azure Maps Render client library for Python.
Once you initialized aMapsRenderClientclass, you can explore the methods on this client object to understand the different features of the Azure Maps Render service that you can access.Async ClientsThis library includes a complete async API supported on Python 3.5+. To use it, you must first install an async transport, such asaiohttp.
Seeazure-core documentationfor more information.Async clients and credentials should be closed when they're no longer needed. These
objects are async context managers and define asyncclosemethods.ExamplesThe following sections provide several code snippets covering some of the most common Azure Maps Render tasks, including:Get Maps AttributionGet Maps Static ImageGet Maps TileGet Maps TilesetGet Maps Copyright for WorldGet Maps AttributionThis request allows users to request map copyright attribution information for a
section of a tileset.fromazure.maps.renderimportMapsRenderClientresult=maps_render_client.get_map_attribution(tileset_id=TilesetID.MICROSOFT_BASE,zoom=6,bounds=BoundingBox(south=42.982261,west=24.980233,north=56.526017,east=1.355233))Get Maps TileThis 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.fromazure.maps.renderimportMapsRenderClientresult=maps_render_client.get_map_tile(tileset_id=TilesetID.MICROSOFT_BASE,z=6,x=9,y=22,tile_size="512")Get Maps TilesetThis request will give metadata for a tileset.fromazure.maps.renderimportMapsRenderClientresult=maps_render_client.get_map_tileset(tileset_id=TilesetID.MICROSOFT_BASE)Get Maps Static ImageThis 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.fromazure.maps.renderimportMapsRenderClientresult=maps_render_client.get_map_static_image(img_format="png",center=(52.41064,4.84228))# Save result to file as pngfile=open('result.png','wb')file.write(next(result))file.close()Get Maps Copyright for WorldThis request will serve copyright information for Render Tile service.fromazure.maps.renderimportMapsRenderClientresult=maps_render_client.get_copyright_for_world()TroubleshootingGeneralMaps Render clients raise exceptions defined inAzure Core.This list can be used for reference to catch thrown exceptions. To get the specific error code of the exception, use theerror_codeattribute, i.e,exception.error_code.LoggingThis library uses the standardlogginglibrary 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 thelogging_enableargument:importsysimportloggingfromazure.maps.renderimportMapsRenderClient# Create a logger for the 'azure.maps.render' SDKlogger=logging.getLogger('azure.maps.render')logger.setLevel(logging.DEBUG)# Configure a console outputhandler=logging.StreamHandler(stream=sys.stdout)logger.addHandler(handler)AdditionalStill running into issues? If you encounter any bugs or have suggestions, please file an issue in theIssuessection of the project.Next stepsMore sample codeGet started with ourMaps 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 RendersetAZURE_SUBSCRIPTION_KEY="<RealSubscriptionKey>"pipinstallazure-maps-render--pre

pythonsamples/sample_authentication.py
pythonsample/sample_get_copyright_caption.py
pythonsample/sample_get_copyright_for_tile.py
pythonsample/sample_get_copyright_for_world.py
pythonsample/sample_get_copyright_from_bounding_box.py
pythonsample/sample_get_map_attribution.py
pythonsample/sample_get_map_static_image.py
pythonsample/sample_get_map_tile.py
pythonsample/sample_get_map_tileset.pyNotes:--preflag can be optionally added, it is to include pre-release and development versions forpip install. By default,piponly finds stable versions.Further detail please refer toSamples IntroductionAdditional documentationFor more extensive documentation on Azure Maps Render, see theAzure Maps Render documentationon docs.microsoft.com.ContributingThis 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, visithttps://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 theMicrosoft Open Source Code of Conduct. For more information see theCode of Conduct FAQor contactopencode@microsoft.comwith any additional questions or comments.Release History1.0.0b2 (2023-07-13)Other ChangesDeprecate Elevation tile enumRemove python 3.6 support1.0.0b1 (2022-10-13)Features AddedInitial release