Skip to main content

Microsoft Azure Storage Blob ChangeFeed Client Library for Python

Project description

Azure Storage Blob ChangeFeed client library for Python

This preview package for Python enables users to get blob change feed events. These events can be lazily generated, iterated by page, retrieved for a specific time interval, or iterated from a specific continuation token.

Source code | Package (PyPi) | API reference documentation | Product documentation | Samples

Getting started

Prerequisites

Install the package

Install the Azure Storage Blob ChangeFeed client library for Python with pip:

pip install azure-storage-blob-changefeed --pre

Create a storage account

If you wish to create a new storage account, you can use the Azure Portal, Azure PowerShell, or Azure CLI:

# Create a new resource group to hold the storage account -
# if using an existing resource group, skip this step
az group create --name my-resource-group --location westus2

# Create the storage account
az storage account create -n my-storage-account-name -g my-resource-group

To enable changefeed you can use: Azure Portal, Azure PowerShell or Template.

Authenticate the client

Interaction with Blob ChangeFeed client starts with an instance of the ChangeFeedClient class. You need an existing storage account, its URL, and a credential to instantiate the client object.

Get credentials

To authenticate the client you have a few options:

  1. Use a SAS token string
  2. Use an account shared access key
  3. Use a token credential from azure.identity

Alternatively, you can authenticate with a storage connection string using the from_connection_string method. See example: Client creation with a connection string.

You can omit the credential if your account URL already has a SAS token.

Create client

Once you have your account URL and credentials ready, you can create the ChangeFeedClient:

from azure.storage.blob.changefeed import ChangeFeedClient

service = ChangeFeedClient(account_url="https://<my-storage-account-name>.blob.core.windows.net/", credential=credential)

Key concepts

Clients

The Blob ChangeFeed SDK provides one client:

  • ChangeFeedClient: this client allows you to get change feed events by page, get all change feed events, get events in a time range, start listing events with a continuation token.

Examples

The following sections provide several code snippets covering some of the most common Storage Blob ChangeFeed, including:

Client creation with a connection string

Create the ChangeFeedClient using the connection string to your Azure Storage account.

from azure.storage.blob.changefeed import ChangeFeedClient

service = ChangeFeedClient.from_connection_string(conn_str="my_connection_string")

Enumerating Events Within a Time Range

List all events within a time range.

from datetime import datetime
from azure.storage.blob.changefeed import ChangeFeedClient

cf_client = ChangeFeedClient("https://{}.blob.core.windows.net".format("YOUR_ACCOUNT_NAME"),
                             credential="Your_ACCOUNT_KEY")
start_time = datetime(2020, 1, 6)
end_time = datetime(2020, 3, 4)
change_feed = cf_client.list_changes(start_time=start_time, end_time=end_time)

# print range of events
for event in change_feed:
    print(event)

Enumerating All Events

List all events.

from azure.storage.blob.changefeed import ChangeFeedClient

cf_client = ChangeFeedClient("https://{}.blob.core.windows.net".format("YOUR_ACCOUNT_NAME"),
                             credential="Your_ACCOUNT_KEY")
change_feed = cf_client.list_changes()

# print all events
for event in change_feed:
    print(event)

Enumerating Events by Page

List events by page.

from azure.storage.blob.changefeed import ChangeFeedClient

cf_client = ChangeFeedClient("https://{}.blob.core.windows.net".format("YOUR_ACCOUNT_NAME"),
                             credential="Your_ACCOUNT_KEY")

change_feed = cf_client.list_changes().by_page()

# print first page of events
change_feed_page1 = next(change_feed)
for event in change_feed_page1:
    print(event)

Troubleshooting

Logging

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.storage.blob.changefeed import ChangeFeedClient

# Create a logger for the 'azure.storage.blob.changefeed' SDK
logger = logging.getLogger('azure.storage')
logger.setLevel(logging.DEBUG)

# Configure a console output
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)

# This client will log detailed information about its HTTP sessions, at DEBUG level
service_client = ChangeFeedClient.from_connection_string("your_connection_string", logging_enable=True)

Next steps

More sample code

Get started with our Azure Blob ChangeFeed samples.

Several Storage Blob ChangeFeed 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 Blob ChangeFeed:

  • change_feed_samples.py - Examples for authenticating and operating on the client:
    • list events by page
    • list all events
    • list events in a time range
    • list events starting from a continuation token

Contributing

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure-storage-blob-changefeed-12.0.0b3.zip (31.8 kB view details)

Uploaded Source

Built Distribution

azure_storage_blob_changefeed-12.0.0b3-py2.py3-none-any.whl (12.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file azure-storage-blob-changefeed-12.0.0b3.zip.

File metadata

  • Download URL: azure-storage-blob-changefeed-12.0.0b3.zip
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for azure-storage-blob-changefeed-12.0.0b3.zip
Algorithm Hash digest
SHA256 067385d75e6c0a89ec9b8d57c0e13d44b0bb18e51c8a8d74e51e6d548b8aa9bc
MD5 99a9ceb5005ee30fb525ee5fe2887aad
BLAKE2b-256 18284c6801acc5d850452a7e40bfdaed408c35f4bc98e31e13f3901349d1f6ac

See more details on using hashes here.

File details

Details for the file azure_storage_blob_changefeed-12.0.0b3-py2.py3-none-any.whl.

File metadata

  • Download URL: azure_storage_blob_changefeed-12.0.0b3-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for azure_storage_blob_changefeed-12.0.0b3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3f736eb02ddd098344dd80d7f8992414b0207724377d6cda2d2c3593f760375b
MD5 c8e2e54d26b779e919703ce39adae12d
BLAKE2b-256 122875d8e240012cb1c20e3d6f0a1c69b69abba8b0470c4a822deb23cbcf5f8c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page