|
| 1 | +# Azure Purview Account client library for Python |
| 2 | + |
| 3 | +Azure Purview Account is a fully managed cloud service. |
| 4 | + |
| 5 | +**Please rely heavily on the [service's documentation][account_product_documentation] and our [client docs][request_builders_and_client] to use this library** |
| 6 | + |
| 7 | +[Source code][source_code] | [Package (PyPI)][account_pypi] | [API reference documentation][account_ref_docs]| [Product documentation][account_product_documentation] |
| 8 | + |
| 9 | +## Getting started |
| 10 | + |
| 11 | +### Prerequisites |
| 12 | + |
| 13 | +- Python 2.7, or 3.6 or later is required to use this package. |
| 14 | +- You must have an [Azure subscription][azure_subscription] and a [Purview][purview_resource] to use this package. |
| 15 | + |
| 16 | +#### Create a Purview Resource |
| 17 | + |
| 18 | +Follow [these][purview_resource] instructions to create your Purview resource |
| 19 | + |
| 20 | +### Install the package |
| 21 | + |
| 22 | +Install the Azure Purview Account client library for Python with [pip][pip]: |
| 23 | + |
| 24 | +```bash |
| 25 | +pip install azure-purview-account |
| 26 | +``` |
| 27 | + |
| 28 | +### Authenticate the client |
| 29 | + |
| 30 | +To use an [Azure Active Directory (AAD) token credential][authenticate_with_token], |
| 31 | +provide an instance of the desired credential type obtained from the |
| 32 | +[azure-identity][azure_identity_credentials] library. |
| 33 | + |
| 34 | +To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip] and |
| 35 | +[enable AAD authentication on your Purview resource][enable_aad] |
| 36 | + |
| 37 | +After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use. |
| 38 | +As an example, [DefaultAzureCredential][default_azure_credential] |
| 39 | +can be used to authenticate the client: |
| 40 | + |
| 41 | +Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: |
| 42 | +AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET |
| 43 | + |
| 44 | +Use the returned token credential to authenticate the client: |
| 45 | + |
| 46 | +```python |
| 47 | +from azure.purview.account import PurviewAccountClient |
| 48 | +from azure.identity import DefaultAzureCredential |
| 49 | + |
| 50 | +credential = DefaultAzureCredential() |
| 51 | +client = PurviewAccountClient(endpoint="https://<my-account-name>.purview.azure.com", credential=credential) |
| 52 | +``` |
| 53 | + |
| 54 | +## Key concepts |
| 55 | + |
| 56 | +### Client |
| 57 | + |
| 58 | +## Examples |
| 59 | + |
| 60 | +The following section shows you how to initialize and authenticate your client, then list all of your keys. |
| 61 | + |
| 62 | +- [Get Keys](#get-keys "Get All Keys") |
| 63 | + |
| 64 | +### Get Keys |
| 65 | + |
| 66 | +```python |
| 67 | +from azure.purview.account import PurviewAccountClient |
| 68 | +from azure.identity import DefaultAzureCredential |
| 69 | + |
| 70 | +credential = DefaultAzureCredential() |
| 71 | +client = PurviewAccountClient(endpoint="https://<my-account-name>.purview.azure.com", credential=credential) |
| 72 | +response = client.accounts.get_access_keys() |
| 73 | +print(response) |
| 74 | +``` |
| 75 | + |
| 76 | +## Troubleshooting |
| 77 | + |
| 78 | +### General |
| 79 | + |
| 80 | +The Purview Account client will raise exceptions if status code of your responses is not defined. |
| 81 | + |
| 82 | +### Logging |
| 83 | + |
| 84 | +This library uses the standard |
| 85 | +[logging][python_logging] library for logging. |
| 86 | +Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO |
| 87 | +level. |
| 88 | + |
| 89 | +Detailed DEBUG level logging, including request/response bodies and unredacted |
| 90 | +headers, can be enabled on a client with the `logging_enable` keyword argument: |
| 91 | + |
| 92 | +```python |
| 93 | +import sys |
| 94 | +import logging |
| 95 | +from azure.identity import DefaultAzureCredential |
| 96 | +from azure.purview.account import PurviewAccountClient |
| 97 | + |
| 98 | +# Create a logger for the 'azure' SDK |
| 99 | +logger = logging.getLogger('azure') |
| 100 | +logger.setLevel(logging.DEBUG) |
| 101 | + |
| 102 | +# Configure a console output |
| 103 | +handler = logging.StreamHandler(stream=sys.stdout) |
| 104 | +logger.addHandler(handler) |
| 105 | + |
| 106 | +endpoint = "https://<my-account-name>.purview.azure.com" |
| 107 | +credential = DefaultAzureCredential() |
| 108 | + |
| 109 | +# This client will log detailed information about its HTTP sessions, at DEBUG level |
| 110 | +client = PurviewAccountClient(endpoint=endpoint, credential=credential, logging_enable=True) |
| 111 | +``` |
| 112 | + |
| 113 | +Similarly, `logging_enable` can enable detailed logging for a single call, |
| 114 | +even when it isn't enabled for the client: |
| 115 | + |
| 116 | +```python |
| 117 | +result = client.accounts.get_access_keys(logging_enable=True) |
| 118 | +``` |
| 119 | + |
| 120 | +## Next steps |
| 121 | + |
| 122 | +For more generic samples, see our [client docs][request_builders_and_client]. |
| 123 | + |
| 124 | +## Contributing |
| 125 | + |
| 126 | +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]. |
| 127 | + |
| 128 | +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. |
| 129 | + |
| 130 | +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. |
| 131 | + |
| 132 | +<!-- LINKS --> |
| 133 | + |
| 134 | +[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/purview/ |
| 135 | +[account_pypi]: https://pypi.org/project/azure-purview-catalog/#history |
| 136 | +[account_ref_docs]: https://azure.github.io/azure-sdk-for-python/ |
| 137 | +[account_product_documentation]: https://azure.microsoft.com/services/purview/ |
| 138 | +[azure_subscription]: https://azure.microsoft.com/free/ |
| 139 | +[purview_resource]: https://docs.microsoft.com/azure/purview/create-catalog-portal |
| 140 | +[pip]: https://pypi.org/project/pip/ |
| 141 | +[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token |
| 142 | +[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials |
| 143 | +[azure_identity_pip]: https://pypi.org/project/azure-identity/ |
| 144 | +[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential |
| 145 | +[request_builders_and_client]: https://aka.ms/azsdk/python/protocol/quickstart |
| 146 | +[enable_aad]: https://docs.microsoft.com/azure/purview/create-catalog-portal#add-a-security-principal-to-a-data-plane-role |
| 147 | +[python_logging]: https://docs.python.org/3.5/library/logging.html |
| 148 | +[cla]: https://cla.microsoft.com |
| 149 | +[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ |
| 150 | +[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ |
| 151 | +[coc_contact]: mailto:opencode@microsoft.com |
0 commit comments