|
| 1 | +# Azure AgriFood Farming client library for Python |
| 2 | + |
| 3 | +## Getting started |
| 4 | + |
| 5 | +### Prerequisites |
| 6 | + |
| 7 | +- Python 2.7, or 3.6 or later is required to use this package. |
| 8 | +- You must have an [Azure subscription][azure_subscription] and an AgriFood resource to use this package. |
| 9 | + |
| 10 | +#### Create an AgriFood Resource |
| 11 | + |
| 12 | +### Install the package |
| 13 | + |
| 14 | +Install the Azure AgriFood Farming client library for Python with [pip][pip]: |
| 15 | + |
| 16 | +```bash |
| 17 | +pip install azure-agrifood-farming |
| 18 | +``` |
| 19 | + |
| 20 | +### Authenticate the client |
| 21 | + |
| 22 | +To use an [Azure Active Directory (AAD) token credential][authenticate_with_token], |
| 23 | +provide an instance of the desired credential type obtained from the |
| 24 | +[azure-identity][azure_identity_credentials] library. |
| 25 | + |
| 26 | +To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip] and |
| 27 | +enable AAD authentication on your AgriFood resource (ADD LINK). |
| 28 | + |
| 29 | +After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use. |
| 30 | +As an example, [DefaultAzureCredential][default_azure_credential] |
| 31 | +can be used to authenticate the client: |
| 32 | + |
| 33 | +Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: |
| 34 | +AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET |
| 35 | + |
| 36 | +Use the returned token credential to authenticate the client: |
| 37 | + |
| 38 | +```python |
| 39 | +from azure.agrifood.farming import FarmBeatsClient |
| 40 | +from azure.identity import DefaultAzureCredential |
| 41 | + |
| 42 | +credential = DefaultAzureCredential() |
| 43 | +client = FarmBeatsClient(endpoint="https://<my-account-name>.farmbeats.azure.net", credential=credential) |
| 44 | +``` |
| 45 | + |
| 46 | +## Key concepts |
| 47 | + |
| 48 | +## Examples |
| 49 | + |
| 50 | +The following section shows you how to initialize and authenticate your client, then get all of your type-defs. |
| 51 | + |
| 52 | +## Troubleshooting |
| 53 | + |
| 54 | +### General |
| 55 | + |
| 56 | +The AgriFood Farming client will raise exceptions defined in [Azure Core][azure_core] if you call `.raise_for_status()` on your responses. |
| 57 | + |
| 58 | +### Logging |
| 59 | + |
| 60 | +This library uses the standard |
| 61 | +[logging][python_logging] library for logging. |
| 62 | +Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO |
| 63 | +level. |
| 64 | + |
| 65 | +Detailed DEBUG level logging, including request/response bodies and unredacted |
| 66 | +headers, can be enabled on a client with the `logging_enable` keyword argument: |
| 67 | + |
| 68 | +```python |
| 69 | +import sys |
| 70 | +import logging |
| 71 | +from azure.identity import DefaultAzureCredential |
| 72 | +from azure.agrifood.farming import FarmBeatsClient |
| 73 | + |
| 74 | +# Create a logger for the 'azure' SDK |
| 75 | +logger = logging.getLogger('azure') |
| 76 | +logger.setLevel(logging.DEBUG) |
| 77 | + |
| 78 | +# Configure a console output |
| 79 | +handler = logging.StreamHandler(stream=sys.stdout) |
| 80 | +logger.addHandler(handler) |
| 81 | + |
| 82 | +endpoint = "https://<my-account-name>.farmbeats.azure.net" |
| 83 | +credential = DefaultAzureCredential() |
| 84 | + |
| 85 | +# This client will log detailed information about its HTTP sessions, at DEBUG level |
| 86 | +client = FarmBeatsClient(endpoint=endpoint, credential=credential, logging_enable=True) |
| 87 | +``` |
| 88 | + |
| 89 | +Similarly, `logging_enable` can enable detailed logging for a single call, |
| 90 | +even when it isn't enabled for the client: |
| 91 | + |
| 92 | +```python |
| 93 | +client.crops.get(crop_id="crop_id", logging_enable=True) |
| 94 | +``` |
| 95 | + |
| 96 | +## Next steps |
| 97 | + |
| 98 | +## Contributing |
| 99 | + |
| 100 | +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]. |
| 101 | + |
| 102 | +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. |
| 103 | + |
| 104 | +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 [[email protected]][coc_contact] with any additional questions or comments. |
| 105 | + |
| 106 | +<!-- LINKS --> |
| 107 | + |
| 108 | +[azure_subscription]: https://azure.microsoft.com/free/ |
| 109 | +[pip]: https://pypi.org/project/pip/ |
| 110 | +[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token |
| 111 | +[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity#credentials |
| 112 | +[azure_identity_pip]: https://pypi.org/project/azure-identity/ |
| 113 | +[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity#defaultazurecredential |
| 114 | +[python_logging]: https://docs.python.org/3.5/library/logging.html |
| 115 | +[cla]: https://cla.microsoft.com |
| 116 | +[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ |
| 117 | +[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ |
| 118 | +[coc_contact]: mailto:[email protected] |
0 commit comments