Package: azure-storage-blob-changefeed
Azure Storage Blob ChangeFeed client library for PythonThis 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|SamplesGetting startedPrerequisitesPython 3.6 or later is required to use this package.You must have anAzure subscriptionand anAzure storage accountto use this package.Install the packageInstall the Azure Storage Blob ChangeFeed client library for Python withpip:pipinstallazure-storage-blob-changefeed--preCreate a storage accountIf you wish to create a new storage account, you can use theAzure Portal,Azure PowerShell,
orAzure CLI:# Create a new resource group to hold the storage account -# if using an existing resource group, skip this stepazgroupcreate--namemy-resource-group--locationwestus2# Create the storage accountazstorageaccountcreate-nmy-storage-account-name-gmy-resource-groupTo enable changefeed you can use:Azure Portal,Azure PowerShellorTemplate.Authenticate the clientInteraction 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 credentialsTo authenticate the client you have a few options:Use a SAS token stringUse an account shared access keyUse a token credential fromazure.identityAlternatively, you can authenticate with a storage connection string using thefrom_connection_stringmethod. See example:Client creation with a connection string.You can omit the credential if your account URL already has a SAS token.Create clientOnce you have your account URL and credentials ready, you can create the ChangeFeedClient:fromazure.storage.blob.changefeedimportChangeFeedClientservice=ChangeFeedClient(account_url="https://<my-storage-account-name>.blob.core.windows.net/",credential=credential)Key conceptsClientsThe 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.ExamplesThe following sections provide several code snippets covering some of the most common Storage Blob ChangeFeed, including:Client creation with a connection stringEnumerating Events Within a Time RangeEnumerating All EventsEnumerating Events by PageClient creation with a connection stringCreate the ChangeFeedClient using the connection string to your Azure Storage account.fromazure.storage.blob.changefeedimportChangeFeedClientservice=ChangeFeedClient.from_connection_string(conn_str="my_connection_string")Enumerating Events Within a Time RangeList all events within a time range.fromdatetimeimportdatetimefromazure.storage.blob.changefeedimportChangeFeedClientcf_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 eventsforeventinchange_feed:print(event)Enumerating All EventsList all events.fromazure.storage.blob.changefeedimportChangeFeedClientcf_client=ChangeFeedClient("https://{}.blob.core.windows.net".format("YOUR_ACCOUNT_NAME"),credential="Your_ACCOUNT_KEY")change_feed=cf_client.list_changes()# print all eventsforeventinchange_feed:print(event)Enumerating Events by PageList events by page.fromazure.storage.blob.changefeedimportChangeFeedClientcf_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 eventschange_feed_page1=next(change_feed)foreventinchange_feed_page1:print(event)TroubleshootingLoggingThis 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.storage.blob.changefeedimportChangeFeedClient# Create a logger for the 'azure.storage.blob.changefeed' SDKlogger=logging.getLogger('azure.storage')logger.setLevel(logging.DEBUG)# Configure a console outputhandler=logging.StreamHandler(stream=sys.stdout)logger.addHandler(handler)# This client will log detailed information about its HTTP sessions, at DEBUG levelservice_client=ChangeFeedClient.from_connection_string("your_connection_string",logging_enable=True)Next stepsMore sample codeGet started with ourAzure 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 pagelist all eventslist events in a time rangelist events starting from a continuation tokenContributingThis 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.