|
| 1 | +# Azure Purview Scanning client library for Python |
| 2 | + |
| 3 | +Azure Purview Scanning is a fully managed cloud service whose users can scan your data into your data estate (also known as your **catalog**). Scanning is a process by which the catalog connects directly to a data source on a user-specified schedule. |
| 4 | + |
| 5 | +- Scan your data into your catalog |
| 6 | +- Examine your data |
| 7 | +- Extract schemas from your data |
| 8 | + |
| 9 | +**Please rely heavily on the [service's documentation][scanning_product_documentation] and our [client docs][request_builders_and_client] to use this library** |
| 10 | + |
| 11 | +[Source code][source_code] | [Package (PyPI)][scanning_pypi] | [API reference documentation][scanning_ref_docs]| [Product documentation][scanning_product_documentation] |
| 12 | + |
| 13 | +## Getting started |
| 14 | + |
| 15 | +### Prerequisites |
| 16 | + |
| 17 | +- Python 2.7, or 3.6 or later is required to use this package. |
| 18 | +- You must have an [Azure subscription][azure_subscription] and a [Purview][purview_resource] to use this package. |
| 19 | + |
| 20 | +#### Create a Purview Resource |
| 21 | + |
| 22 | +Follow [these][purview_resource] instructions to create your Purview resource |
| 23 | + |
| 24 | +### Install the package |
| 25 | + |
| 26 | +Install the Azure Purview Scanning client library for Python with [pip][pip]: |
| 27 | + |
| 28 | +```bash |
| 29 | +pip install azure-purview-scanning |
| 30 | +``` |
| 31 | + |
| 32 | +### Authenticate the client |
| 33 | + |
| 34 | +To use an [Azure Active Directory (AAD) token credential][authenticate_with_token], |
| 35 | +provide an instance of the desired credential type obtained from the |
| 36 | +[azure-identity][azure_identity_credentials] library. |
| 37 | + |
| 38 | +To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip] and |
| 39 | +[enable AAD authentication on your Purview resource][enable_aad] |
| 40 | + |
| 41 | +After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use. |
| 42 | +As an example, [DefaultAzureCredential][default_azure_credential] |
| 43 | +can be used to authenticate the client: |
| 44 | + |
| 45 | +Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: |
| 46 | +AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET |
| 47 | + |
| 48 | +Use the returned token credential to authenticate the client: |
| 49 | + |
| 50 | +```python |
| 51 | +from azure.purview.scanning import PurviewScanningClient |
| 52 | +from azure.identity import DefaultAzureCredential |
| 53 | + |
| 54 | +credential = DefaultAzureCredential() |
| 55 | +client = PurviewScanningClient(endpoint="https://<my-account-name>.scanning.purview.azure.com", credential=credential) |
| 56 | +``` |
| 57 | + |
| 58 | +## Key concepts |
| 59 | + |
| 60 | +### Client |
| 61 | + |
| 62 | +This package offers request builders so you can build http requests and send these requests to the service using the `send_request` method. |
| 63 | +For more information on how to use request builders and our clients, see [here][request_builders_and_client]. |
| 64 | + |
| 65 | +## Examples |
| 66 | + |
| 67 | +The following section shows you how to initialize and authenticate your client, then list all of your data sources. |
| 68 | + |
| 69 | +- [List All Data Sources](#list-all-data-sources "List All Data Sources") |
| 70 | + |
| 71 | +### List All Data Sources |
| 72 | + |
| 73 | +```python |
| 74 | +from azure.purview.scanning import PurviewScanningClient |
| 75 | +from azure.identity import DefaultAzureCredential |
| 76 | +from azure.purview.scanning.rest import data_sources |
| 77 | +from azure.core.exceptions import HttpResponseError |
| 78 | + |
| 79 | +credential = DefaultAzureCredential() |
| 80 | +client = PurviewScanningClient(endpoint="https://<my-account-name>.scanning.purview.azure.com", credential=credential) |
| 81 | + |
| 82 | +request = data_sources.build_list_all_request() |
| 83 | + |
| 84 | +response = client.send_request(request) |
| 85 | +try: |
| 86 | + response.raise_for_status() |
| 87 | + json_response = response.json() |
| 88 | + |
| 89 | + assert len(json_response['value']) == json_response['count'] |
| 90 | + for value in json_response['value']: |
| 91 | + print(value) |
| 92 | + |
| 93 | +except HttpResponseError as e: |
| 94 | + print(e) |
| 95 | +``` |
| 96 | + |
| 97 | +## Troubleshooting |
| 98 | + |
| 99 | +### General |
| 100 | + |
| 101 | +The Purview Scanning client will raise exceptions defined in [Azure Core][azure_core] if you call `.raise_for_status()` on your responses. |
| 102 | + |
| 103 | +### Logging |
| 104 | + |
| 105 | +This library uses the standard |
| 106 | +[logging][python_logging] library for logging. |
| 107 | +Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO |
| 108 | +level. |
| 109 | + |
| 110 | +Detailed DEBUG level logging, including request/response bodies and unredacted |
| 111 | +headers, can be enabled on a client with the `logging_enable` keyword argument: |
| 112 | + |
| 113 | +```python |
| 114 | +import sys |
| 115 | +import logging |
| 116 | +from azure.identity import DefaultAzureCredential |
| 117 | +from azure.purview.scanning import PurviewScanningClient |
| 118 | + |
| 119 | +# Create a logger for the 'azure' SDK |
| 120 | +logger = logging.getLogger('azure') |
| 121 | +logger.setLevel(logging.DEBUG) |
| 122 | + |
| 123 | +# Configure a console output |
| 124 | +handler = logging.StreamHandler(stream=sys.stdout) |
| 125 | +logger.addHandler(handler) |
| 126 | + |
| 127 | +endpoint = "https://<my-account-name>.scanning.purview.azure.com" |
| 128 | +credential = DefaultAzureCredential() |
| 129 | + |
| 130 | +# This client will log detailed information about its HTTP sessions, at DEBUG level |
| 131 | +client = PurviewScanningClient(endpoint=endpoint, credential=credential, logging_enable=True) |
| 132 | +``` |
| 133 | + |
| 134 | +Similarly, `logging_enable` can enable detailed logging for a single `send_request` call, |
| 135 | +even when it isn't enabled for the client: |
| 136 | + |
| 137 | +```python |
| 138 | +result = client.send_request(request, logging_enable=True) |
| 139 | +``` |
| 140 | + |
| 141 | +## Next steps |
| 142 | + |
| 143 | +For more generic samples, see our [client docs][request_builders_and_client]. |
| 144 | + |
| 145 | +## Contributing |
| 146 | + |
| 147 | +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 [cla.microsoft.com][cla]. |
| 148 | + |
| 149 | +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. |
| 150 | + |
| 151 | +This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments. |
| 152 | + |
| 153 | +<!-- LINKS --> |
| 154 | + |
| 155 | +[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/purview/azure-purview-scanning/azure/purview/scanning |
| 156 | +[scanning_pypi]: https://aka.ms/azsdk/python/purviewscanning/pypi |
| 157 | +[scanning_ref_docs]: https://aka.ms/azsdk/python/purviewscanning/ref-docs |
| 158 | +[scanning_product_documentation]: https://azure.microsoft.com/services/purview/ |
| 159 | +[azure_subscription]: https://azure.microsoft.com/free/ |
| 160 | +[purview_resource]: https://docs.microsoft.com/azure/purview/create-catalog-portal |
| 161 | +[pip]: https://pypi.org/project/pip/ |
| 162 | +[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token |
| 163 | +[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity#credentials |
| 164 | +[azure_identity_pip]: https://pypi.org/project/azure-identity/ |
| 165 | +[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity#defaultazurecredential |
| 166 | +[request_builders_and_client]: https://aka.ms/azsdk/python/protocol/quickstart |
| 167 | +[enable_aad]: https://docs.microsoft.com/azure/purview/create-catalog-portal#add-a-security-principal-to-a-data-plane-role |
| 168 | +[python_logging]: https://docs.python.org/3.5/library/logging.html |
| 169 | +[cla]: https://cla.microsoft.com |
| 170 | +[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ |
| 171 | +[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ |
| 172 | +[coc_contact]: mailto:opencode@microsoft.com |
0 commit comments