Azure Monitor Query client library Python samples

Samples

The following code samples show common scenarios with the Azure Monitor Query client library.

For examples on authenticating with the Azure Monitor service, see sample_authentication.py and sample_authentication_async.py.

Logs query samples

Notebook samples

Prerequisites

Setup

  1. Install the latest version of the Azure Monitor Query library:
pip install azure-monitor-query
  1. Clone or download this sample repository.
  2. Open the samples folder in Visual Studio Code or your IDE of choice.
  3. To run most of this samples, you need azure-identity and pandas. Although, those dependencies are optional and can be replaced.
pip install azure-identity pandas
  1. To run the async samples, you need an asynchronous HTTP framework like aiohttp:
pip install aiohttp

Run the samples

  1. Open a terminal window and cd to the directory that the samples are saved in.
  2. Set the environment variables specified in the sample file you wish to run.
  3. Follow the usage described in the file. For example, python sample_logs_single_query.py.

Next steps

To learn more about Azure Monitor, see the Azure Monitor service documentation.