# 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](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed) | [Package (PyPi)](https://pypi.org/project/azure-storage-blob-changefeed/) | [API reference documentation](https://aka.ms/azsdk-python-storage-blob-changefeed-ref) | [Product documentation](https://docs.microsoft.com/azure/storage/) | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob-changefeed/samples)
## Getting started
### Prerequisites
* Python 3.8 or later is required to use this package. For more details, please read our page on [Azure SDK for Python version support policy](https://github.com/Azure/azure-sdk-for-python/wiki/Azure-SDKs-Python-version-support-policy).
* You must have an [Azure subscription](https://azure.microsoft.com/free/) and an
[Azure storage account](https://docs.microsoft.com/azure/storage/blobs/data-lake-storage-quickstart-create-account) to use this package.
### Install the package
Install the Azure Storage Blob ChangeFeed client library for Python with [pip](https://pypi.org/project/pip/):
```bash
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](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal),
[Azure PowerShell](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-powershell),
or [Azure CLI](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-cli):
```bash
# 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](https://docs.microsoft.com/azure/storage/blobs/storage-blob-change-feed?tabs=azure-portal#enable-and-disable-the-change-feed),
[Azure PowerShell](https://docs.microsoft.com/azure/storage/blobs/storage-blob-change-feed?tabs=azure-powershell#enable-and-disable-the-change-feed)
or [Template](https://docs.microsoft.com/azure/storage/blobs/storage-blob-change-feed?tabs=template#enable-and-disable-the-change-feed).
### 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](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/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](#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:
```python
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](#client-creation-with-a-connection-string)
* [Enumerating Events Within a Time Range](#enumerating-events-within-a-time-range)
* [Enumerating All Events](#enumerating-all-events)
* [Enumerating Events by Page](#enumerating-events-by-page)
### Client creation with a connection string
Create the ChangeFeedClient using the connection string to your Azure Storage account.
```python
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.
```python
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.
```python
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.
```python
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](https://docs.python.org/3/library/logging.html) 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:
```python
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](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-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](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob-changefeed/samples/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](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
Raw data
{
"_id": null,
"home_page": "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob-changefeed",
"name": "azure-storage-blob-changefeed",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "azure, azure sdk",
"author": "Microsoft Corporation",
"author_email": "ascl@microsoft.com",
"download_url": "https://files.pythonhosted.org/packages/24/02/714ed4dc52e0ad3752525ed6298561c8ee28330f5c541f25be360db7c426/azure-storage-blob-changefeed-12.0.0b5.tar.gz",
"platform": null,
"description": "# Azure Storage Blob ChangeFeed client library for Python\n\nThis 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.\n\n\n[Source code](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed) | [Package (PyPi)](https://pypi.org/project/azure-storage-blob-changefeed/) | [API reference documentation](https://aka.ms/azsdk-python-storage-blob-changefeed-ref) | [Product documentation](https://docs.microsoft.com/azure/storage/) | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob-changefeed/samples)\n\n\n## Getting started\n\n### Prerequisites\n* Python 3.8 or later is required to use this package. For more details, please read our page on [Azure SDK for Python version support policy](https://github.com/Azure/azure-sdk-for-python/wiki/Azure-SDKs-Python-version-support-policy).\n* You must have an [Azure subscription](https://azure.microsoft.com/free/) and an\n[Azure storage account](https://docs.microsoft.com/azure/storage/blobs/data-lake-storage-quickstart-create-account) to use this package.\n\n### Install the package\nInstall the Azure Storage Blob ChangeFeed client library for Python with [pip](https://pypi.org/project/pip/):\n\n```bash\npip install azure-storage-blob-changefeed --pre\n```\n\n### Create a storage account\nIf you wish to create a new storage account, you can use the\n[Azure Portal](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal),\n[Azure PowerShell](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-powershell),\nor [Azure CLI](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-cli):\n\n```bash\n# Create a new resource group to hold the storage account -\n# if using an existing resource group, skip this step\naz group create --name my-resource-group --location westus2\n\n# Create the storage account\naz storage account create -n my-storage-account-name -g my-resource-group\n```\n\nTo enable changefeed you can use:\n[Azure Portal](https://docs.microsoft.com/azure/storage/blobs/storage-blob-change-feed?tabs=azure-portal#enable-and-disable-the-change-feed),\n[Azure PowerShell](https://docs.microsoft.com/azure/storage/blobs/storage-blob-change-feed?tabs=azure-powershell#enable-and-disable-the-change-feed)\nor [Template](https://docs.microsoft.com/azure/storage/blobs/storage-blob-change-feed?tabs=template#enable-and-disable-the-change-feed).\n\n### Authenticate the client\n\nInteraction 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.\n\n#### Get credentials\n\nTo authenticate the client you have a few options:\n1. Use a SAS token string\n2. Use an account shared access key\n3. Use a token credential from [azure.identity](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity)\n\nAlternatively, you can authenticate with a storage connection string using the `from_connection_string` method. See example: [Client creation with a connection string](#client-creation-with-a-connection-string).\n\nYou can omit the credential if your account URL already has a SAS token.\n\n#### Create client\n\nOnce you have your account URL and credentials ready, you can create the ChangeFeedClient:\n\n```python\nfrom azure.storage.blob.changefeed import ChangeFeedClient\n\nservice = ChangeFeedClient(account_url=\"https://<my-storage-account-name>.blob.core.windows.net/\", credential=credential)\n```\n\n## Key concepts\n\n#### Clients\n\nThe Blob ChangeFeed SDK provides one client:\n* 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.\n\n## Examples\n\nThe following sections provide several code snippets covering some of the most common Storage Blob ChangeFeed, including:\n\n* [Client creation with a connection string](#client-creation-with-a-connection-string)\n* [Enumerating Events Within a Time Range](#enumerating-events-within-a-time-range)\n* [Enumerating All Events](#enumerating-all-events)\n* [Enumerating Events by Page](#enumerating-events-by-page)\n\n\n### Client creation with a connection string\nCreate the ChangeFeedClient using the connection string to your Azure Storage account.\n\n```python\nfrom azure.storage.blob.changefeed import ChangeFeedClient\n\nservice = ChangeFeedClient.from_connection_string(conn_str=\"my_connection_string\")\n```\n### Enumerating Events Within a Time Range\nList all events within a time range.\n\n```python\nfrom datetime import datetime\nfrom azure.storage.blob.changefeed import ChangeFeedClient\n\ncf_client = ChangeFeedClient(\"https://{}.blob.core.windows.net\".format(\"YOUR_ACCOUNT_NAME\"),\n credential=\"Your_ACCOUNT_KEY\")\nstart_time = datetime(2020, 1, 6)\nend_time = datetime(2020, 3, 4)\nchange_feed = cf_client.list_changes(start_time=start_time, end_time=end_time)\n\n# print range of events\nfor event in change_feed:\n print(event)\n```\n\n### Enumerating All Events\nList all events.\n\n```python\nfrom azure.storage.blob.changefeed import ChangeFeedClient\n\ncf_client = ChangeFeedClient(\"https://{}.blob.core.windows.net\".format(\"YOUR_ACCOUNT_NAME\"),\n credential=\"Your_ACCOUNT_KEY\")\nchange_feed = cf_client.list_changes()\n\n# print all events\nfor event in change_feed:\n print(event)\n```\n\n### Enumerating Events by Page\nList events by page.\n\n```python\nfrom azure.storage.blob.changefeed import ChangeFeedClient\n\ncf_client = ChangeFeedClient(\"https://{}.blob.core.windows.net\".format(\"YOUR_ACCOUNT_NAME\"),\n credential=\"Your_ACCOUNT_KEY\")\n\nchange_feed = cf_client.list_changes().by_page()\n\n# print first page of events\nchange_feed_page1 = next(change_feed)\nfor event in change_feed_page1:\n print(event)\n```\n\n## Troubleshooting\n\n### Logging\nThis library uses the standard\n[logging](https://docs.python.org/3/library/logging.html) library for logging.\nBasic information about HTTP sessions (URLs, headers, etc.) is logged at INFO\nlevel.\n\nDetailed DEBUG level logging, including request/response bodies and unredacted\nheaders, can be enabled on a client with the `logging_enable` argument:\n```python\nimport sys\nimport logging\nfrom azure.storage.blob.changefeed import ChangeFeedClient\n\n# Create a logger for the 'azure.storage.blob.changefeed' SDK\nlogger = logging.getLogger('azure.storage')\nlogger.setLevel(logging.DEBUG)\n\n# Configure a console output\nhandler = logging.StreamHandler(stream=sys.stdout)\nlogger.addHandler(handler)\n\n# This client will log detailed information about its HTTP sessions, at DEBUG level\nservice_client = ChangeFeedClient.from_connection_string(\"your_connection_string\", logging_enable=True)\n```\n\n## Next steps\n\n### More sample code\n\nGet started with our [Azure Blob ChangeFeed samples](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob-changefeed/samples).\n\nSeveral 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:\n\n* [change_feed_samples.py](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob-changefeed/samples/change_feed_samples.py) - Examples for authenticating and operating on the client:\n * list events by page\n * list all events\n * list events in a time range\n * list events starting from a continuation token\n\n\n## Contributing\nThis 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.\n\nWhen 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.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Microsoft Azure Storage Blob ChangeFeed Client Library for Python",
"version": "12.0.0b5",
"project_urls": {
"Homepage": "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob-changefeed"
},
"split_keywords": [
"azure",
" azure sdk"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "bbd3b8a929eb2b577c146ae765fb42e020c334f63d269114d67031709835e25b",
"md5": "1f002c306a710bb2604400595eeeabde",
"sha256": "829eb3ae2df53a837f26a9addd74ac74b536f87731c446899edf9d1bf9c92e09"
},
"downloads": -1,
"filename": "azure_storage_blob_changefeed-12.0.0b5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1f002c306a710bb2604400595eeeabde",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 12918,
"upload_time": "2024-04-16T21:46:53",
"upload_time_iso_8601": "2024-04-16T21:46:53.261336Z",
"url": "https://files.pythonhosted.org/packages/bb/d3/b8a929eb2b577c146ae765fb42e020c334f63d269114d67031709835e25b/azure_storage_blob_changefeed-12.0.0b5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "2402714ed4dc52e0ad3752525ed6298561c8ee28330f5c541f25be360db7c426",
"md5": "4796dc8559fc5fd1c47f2af80addbb15",
"sha256": "42172b2f170ca2e8075bd4d70021fbeb1e0b402dea5e885941834ad3eb57f7bc"
},
"downloads": -1,
"filename": "azure-storage-blob-changefeed-12.0.0b5.tar.gz",
"has_sig": false,
"md5_digest": "4796dc8559fc5fd1c47f2af80addbb15",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 19725,
"upload_time": "2024-04-16T21:46:51",
"upload_time_iso_8601": "2024-04-16T21:46:51.519011Z",
"url": "https://files.pythonhosted.org/packages/24/02/714ed4dc52e0ad3752525ed6298561c8ee28330f5c541f25be360db7c426/azure-storage-blob-changefeed-12.0.0b5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-16 21:46:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Azure",
"github_project": "azure-sdk-for-python",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "azure-storage-blob-changefeed"
}