PowerPlatform-Dataverse-Client 0.1.0b1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. powerplatform_dataverse_client-0.1.0b1/LICENSE +21 -0
  2. powerplatform_dataverse_client-0.1.0b1/PKG-INFO +383 -0
  3. powerplatform_dataverse_client-0.1.0b1/README.md +346 -0
  4. powerplatform_dataverse_client-0.1.0b1/pyproject.toml +87 -0
  5. powerplatform_dataverse_client-0.1.0b1/setup.cfg +4 -0
  6. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/__init__.py +6 -0
  7. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/__version__.py +6 -0
  8. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/client.py +681 -0
  9. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/core/__init__.py +11 -0
  10. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/core/_auth.py +59 -0
  11. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/core/_error_codes.py +104 -0
  12. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/core/_http.py +79 -0
  13. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/core/config.py +54 -0
  14. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/core/errors.py +196 -0
  15. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/data/__init__.py +11 -0
  16. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/data/_odata.py +1458 -0
  17. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/data/_upload.py +178 -0
  18. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/extensions/__init__.py +9 -0
  19. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/models/__init__.py +9 -0
  20. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/py.typed +0 -0
  21. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/Dataverse/utils/__init__.py +10 -0
  22. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform/__init__.py +4 -0
  23. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform_Dataverse_Client.egg-info/PKG-INFO +383 -0
  24. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform_Dataverse_Client.egg-info/SOURCES.txt +26 -0
  25. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform_Dataverse_Client.egg-info/dependency_links.txt +1 -0
  26. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform_Dataverse_Client.egg-info/not-zip-safe +1 -0
  27. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform_Dataverse_Client.egg-info/requires.txt +11 -0
  28. powerplatform_dataverse_client-0.1.0b1/src/PowerPlatform_Dataverse_Client.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1,383 @@
1
+ Metadata-Version: 2.4
2
+ Name: PowerPlatform-Dataverse-Client
3
+ Version: 0.1.0b1
4
+ Summary: Python SDK for Microsoft Dataverse
5
+ Author: Microsoft Corporation
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/microsoft/PowerPlatform-DataverseClient-Python
8
+ Project-URL: Repository, https://github.com/microsoft/PowerPlatform-DataverseClient-Python.git
9
+ Project-URL: Issues, https://github.com/microsoft/PowerPlatform-DataverseClient-Python/issues
10
+ Project-URL: Documentation, https://github.com/microsoft/PowerPlatform-DataverseClient-Python#readme
11
+ Keywords: dataverse,powerapps,powerplatform,crm,dynamics,odata
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: azure-identity>=1.17.0
27
+ Requires-Dist: azure-core>=1.30.2
28
+ Requires-Dist: requests>=2.32.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
31
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
32
+ Requires-Dist: black>=23.0.0; extra == "dev"
33
+ Requires-Dist: isort>=5.12.0; extra == "dev"
34
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
35
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # PowerPlatform Dataverse Client for Python
39
+
40
+ [![PyPI version](https://badge.fury.io/py/PowerPlatform-Dataverse-Client.svg)](https://badge.fury.io/py/PowerPlatform-Dataverse-Client)
41
+ [![Python](https://img.shields.io/pypi/pyversions/PowerPlatform-Dataverse-Client.svg)](https://pypi.org/project/PowerPlatform-Dataverse-Client/)
42
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
43
+
44
+ A Python client library for Microsoft Dataverse that provides a unified interface for CRUD operations, SQL queries, table metadata management, and file uploads through the Dataverse Web API.
45
+
46
+ **[Source code](https://github.com/microsoft/PowerPlatform-DataverseClient-Python)** | **[Package (PyPI)](https://pypi.org/project/PowerPlatform-Dataverse-Client/)** | **[API reference documentation](https://learn.microsoft.com/python/api/dataverse-sdk-docs-python/dataverse-overview?view=dataverse-sdk-python-latest)** | **[Product documentation](https://learn.microsoft.com/power-apps/developer/data-platform/sdk-python/)** | **[Samples](https://github.com/microsoft/PowerPlatform-DataverseClient-Python/tree/main/examples)**
47
+
48
+ > [!IMPORTANT]
49
+ > This library is currently in **preview**. Preview versions are provided for early access to new features and may contain breaking changes.
50
+
51
+ ## Table of contents
52
+
53
+ - [Key features](#key-features)
54
+ - [Getting started](#getting-started)
55
+ - [Prerequisites](#prerequisites)
56
+ - [Install the package](#install-the-package)
57
+ - [Authenticate the client](#authenticate-the-client)
58
+ - [Key concepts](#key-concepts)
59
+ - [Examples](#examples)
60
+ - [Quick start](#quick-start)
61
+ - [Basic CRUD operations](#basic-crud-operations)
62
+ - [Bulk operations](#bulk-operations)
63
+ - [Query data](#query-data)
64
+ - [Table management](#table-management)
65
+ - [File operations](#file-operations)
66
+ - [Next steps](#next-steps)
67
+ - [Troubleshooting](#troubleshooting)
68
+ - [Contributing](#contributing)
69
+
70
+ ## Key features
71
+
72
+ - **🔄 CRUD Operations**: Create, read, update, and delete records with support for bulk operations and automatic retry
73
+ - **⚡ True Bulk Operations**: Automatically uses Dataverse's native `CreateMultiple`, `UpdateMultiple`, and `BulkDelete` Web API operations for maximum performance and transactional integrity
74
+ - **📊 SQL Queries**: Execute read-only SQL queries via the Dataverse Web API `?sql=` parameter
75
+ - **🏗️ Table Management**: Create, inspect, and delete custom tables and columns programmatically
76
+ - **📎 File Operations**: Upload files to Dataverse file columns with automatic chunking for large files
77
+ - **🔐 Azure Identity**: Built-in authentication using Azure Identity credential providers with comprehensive support
78
+ - **🛡️ Error Handling**: Structured exception hierarchy with detailed error context and retry guidance
79
+
80
+ ## Getting started
81
+
82
+ ### Prerequisites
83
+
84
+ - **Python 3.10+** (3.10, 3.11, 3.12, 3.13 supported)
85
+ - **Microsoft Dataverse environment** with appropriate permissions
86
+ - **OAuth authentication configured** for your application
87
+
88
+ ### Install the package
89
+
90
+ Install the PowerPlatform Dataverse Client using [pip](https://pypi.org/project/pip/):
91
+
92
+ ```bash
93
+ # Install the latest stable release
94
+ pip install PowerPlatform-Dataverse-Client
95
+ ```
96
+
97
+ For development from source:
98
+
99
+ ```bash
100
+ git clone https://github.com/microsoft/PowerPlatform-DataverseClient-Python.git
101
+ cd PowerPlatform-DataverseClient-Python
102
+ pip install -e .
103
+ ```
104
+
105
+ ### Authenticate the client
106
+
107
+ The client requires any Azure Identity `TokenCredential` implementation for OAuth authentication with Dataverse:
108
+
109
+ ```python
110
+ from azure.identity import (
111
+ InteractiveBrowserCredential,
112
+ ClientSecretCredential,
113
+ ClientCertificateCredential,
114
+ AzureCliCredential
115
+ )
116
+ from PowerPlatform.Dataverse.client import DataverseClient
117
+
118
+ # Development options
119
+ credential = InteractiveBrowserCredential() # Browser authentication
120
+ # credential = AzureCliCredential() # If logged in via 'az login'
121
+
122
+ # Production options
123
+ # credential = ClientSecretCredential(tenant_id, client_id, client_secret)
124
+ # credential = ClientCertificateCredential(tenant_id, client_id, cert_path)
125
+
126
+ client = DataverseClient("https://yourorg.crm.dynamics.com", credential)
127
+ ```
128
+
129
+ > **Complete authentication setup**: See **[Use OAuth with Dataverse](https://learn.microsoft.com/power-apps/developer/data-platform/authenticate-oauth)** for app registration, all credential types, and security configuration.
130
+
131
+ ## Key concepts
132
+
133
+ The SDK provides a simple, pythonic interface for Dataverse operations:
134
+
135
+ | Concept | Description |
136
+ |---------|-------------|
137
+ | **DataverseClient** | Main entry point for all operations with environment connection |
138
+ | **Records** | Dataverse records represented as Python dictionaries with column schema names |
139
+ | **Schema names** | Use table schema names (`"account"`, `"new_MyTestTable"`) and column schema names (`"name"`, `"new_MyTestColumn"`). See: [Table definitions in Microsoft Dataverse](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/entity-metadata) |
140
+ | **Bulk Operations** | Efficient bulk processing for multiple records with automatic optimization |
141
+ | **Paging** | Automatic handling of large result sets with iterators |
142
+ | **Structured Errors** | Detailed exception hierarchy with retry guidance and diagnostic information |
143
+ | **Customization prefix values** | Custom tables and columns require a customization prefix value to be included for all operations (e.g., `"new_MyTestTable"`, not `"MyTestTable"`). See: [Table definitions in Microsoft Dataverse](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/entity-metadata) |
144
+
145
+ ## Examples
146
+
147
+ ### Quick start
148
+
149
+ ```python
150
+ from azure.identity import InteractiveBrowserCredential
151
+ from PowerPlatform.Dataverse.client import DataverseClient
152
+
153
+ # Connect to Dataverse
154
+ credential = InteractiveBrowserCredential()
155
+ client = DataverseClient("https://yourorg.crm.dynamics.com", credential)
156
+
157
+ # Create a contact
158
+ contact_id = client.create("contact", {"firstname": "John", "lastname": "Doe"})[0]
159
+
160
+ # Read the contact back
161
+ contact = client.get("contact", contact_id, select=["firstname", "lastname"])
162
+ print(f"Created: {contact['firstname']} {contact['lastname']}")
163
+
164
+ # Clean up
165
+ client.delete("contact", contact_id)
166
+ ```
167
+
168
+ ### Basic CRUD operations
169
+
170
+ ```python
171
+ # Create a record
172
+ account_ids = client.create("account", {"name": "Contoso Ltd"})
173
+ account_id = account_ids[0]
174
+
175
+ # Read a record
176
+ account = client.get("account", account_id)
177
+ print(account["name"])
178
+
179
+ # Update a record
180
+ client.update("account", account_id, {"telephone1": "555-0199"})
181
+
182
+ # Delete a record
183
+ client.delete("account", account_id)
184
+ ```
185
+
186
+ ### Bulk operations
187
+
188
+ ```python
189
+ # Bulk create
190
+ payloads = [
191
+ {"name": "Company A"},
192
+ {"name": "Company B"},
193
+ {"name": "Company C"}
194
+ ]
195
+ ids = client.create("account", payloads)
196
+
197
+ # Bulk update (broadcast same change to all)
198
+ client.update("account", ids, {"industry": "Technology"})
199
+
200
+ # Bulk delete
201
+ client.delete("account", ids, use_bulk_delete=True)
202
+ ```
203
+
204
+ ### Query data
205
+
206
+ ```python
207
+ # SQL query (read-only)
208
+ results = client.query_sql(
209
+ "SELECT TOP 10 accountid, name FROM account WHERE statecode = 0"
210
+ )
211
+ for record in results:
212
+ print(record["name"])
213
+
214
+ # OData query with paging
215
+ # Note: filter and expand parameters are case sensitive
216
+ pages = client.get(
217
+ "account",
218
+ select=["accountid", "name"], # select is case-insensitive (automatically lowercased)
219
+ filter="statecode eq 0", # filter must use lowercase logical names (not transformed)
220
+ top=100
221
+ )
222
+ for page in pages:
223
+ for record in page:
224
+ print(record["name"])
225
+
226
+ # Query with navigation property expansion (case-sensitive!)
227
+ pages = client.get(
228
+ "account",
229
+ select=["name"],
230
+ expand=["primarycontactid"], # Navigation property names are case-sensitive
231
+ filter="statecode eq 0" # Column names must be lowercase logical names
232
+ )
233
+ for page in pages:
234
+ for account in page:
235
+ contact = account.get("primarycontactid", {})
236
+ print(f"{account['name']} - Contact: {contact.get('fullname', 'N/A')}")
237
+ ```
238
+
239
+ > **Important**: When using `filter` and `expand` parameters:
240
+ > - **`filter`**: Column names must use exact lowercase logical names (e.g., `"statecode eq 0"`, not `"StateCode eq 0"`)
241
+ > - **`expand`**: Navigation property names are case-sensitive and must match the exact server names
242
+ > - **`select`** and **`orderby`**: Case-insensitive; automatically converted to lowercase
243
+
244
+ ### Table management
245
+
246
+ ```python
247
+ # Create a custom table, including the customization prefix value in the schema names for the table and columns.
248
+ table_info = client.create_table("new_Product", {
249
+ "new_Code": "string",
250
+ "new_Price": "decimal",
251
+ "new_Active": "bool"
252
+ })
253
+
254
+ # Create with custom primary column name and solution assignment
255
+ table_info = client.create_table(
256
+ table_schema_name="new_Product",
257
+ columns={
258
+ "new_Code": "string",
259
+ "new_Price": "decimal"
260
+ },
261
+ solution_unique_name="MyPublisher", # Optional: add to specific solution
262
+ primary_column_schema_name="new_ProductName" # Optional: custom primary column (default is "{customization prefix value}_Name")
263
+ )
264
+
265
+ # Add columns to existing table (columns must include customization prefix value)
266
+ client.create_columns("new_Product", {"new_Category": "string"})
267
+
268
+ # Remove columns
269
+ client.delete_columns("new_Product", ["new_Category"])
270
+
271
+ # Clean up
272
+ client.delete_table("new_Product")
273
+ ```
274
+
275
+ > **Important**: All custom column names must include the customization prefix value (e.g., `"new_"`).
276
+ > This ensures explicit, predictable naming and aligns with Dataverse metadata requirements.
277
+
278
+ ### File operations
279
+
280
+ ```python
281
+ # Upload a file to a record
282
+ client.upload_file(
283
+ table_schema_name="account",
284
+ record_id=account_id,
285
+ file_name_attribute="new_document",
286
+ path="/path/to/document.pdf"
287
+ )
288
+ ```
289
+
290
+ ## Next steps
291
+
292
+ ### More sample code
293
+
294
+ Explore our comprehensive examples in the [`examples/`](examples/) directory:
295
+
296
+ **🌱 Getting Started:**
297
+ - **[Installation & Setup](examples/basic/installation_example.py)** - Validate installation and basic usage patterns
298
+ - **[Functional Testing](examples/basic/functional_testing.py)** - Test core functionality in your environment
299
+
300
+ **🚀 Advanced Usage:**
301
+ - **[Complete Walkthrough](examples/advanced/walkthrough.py)** - Full feature demonstration with production patterns
302
+ - **[File Upload](examples/advanced/file_upload.py)** - Upload files to Dataverse file columns
303
+
304
+ 📖 See the [examples README](examples/README.md) for detailed guidance and learning progression.
305
+
306
+ ### Additional documentation
307
+
308
+ For comprehensive information on Microsoft Dataverse and related technologies:
309
+
310
+ | Resource | Description |
311
+ |----------|-------------|
312
+ | **[Dataverse Developer Guide](https://learn.microsoft.com/power-apps/developer/data-platform/)** | Complete developer documentation for Microsoft Dataverse |
313
+ | **[Dataverse Web API Reference](https://learn.microsoft.com/power-apps/developer/data-platform/webapi/)** | Detailed Web API reference and examples |
314
+ | **[Azure Identity for Python](https://learn.microsoft.com/python/api/overview/azure/identity-readme)** | Authentication library documentation and credential types |
315
+ | **[Power Platform Developer Center](https://learn.microsoft.com/power-platform/developer/)** | Broader Power Platform development resources |
316
+ | **[Dataverse SDK for .NET](https://learn.microsoft.com/power-apps/developer/data-platform/org-service/overview)** | Official .NET SDK for Microsoft Dataverse |
317
+
318
+ ## Troubleshooting
319
+
320
+ ### General
321
+
322
+ The client raises structured exceptions for different error scenarios:
323
+
324
+ ```python
325
+ from PowerPlatform.Dataverse.client import DataverseClient
326
+ from PowerPlatform.Dataverse.core.errors import HttpError, ValidationError
327
+
328
+ try:
329
+ client.get("account", "invalid-id")
330
+ except HttpError as e:
331
+ print(f"HTTP {e.status_code}: {e.message}")
332
+ print(f"Error code: {e.code}")
333
+ print(f"Subcode: {e.subcode}")
334
+ if e.is_transient:
335
+ print("This error may be retryable")
336
+ except ValidationError as e:
337
+ print(f"Validation error: {e.message}")
338
+ ```
339
+
340
+ ### Authentication issues
341
+
342
+ **Common fixes:**
343
+ - Verify environment URL format: `https://yourorg.crm.dynamics.com` (no trailing slash)
344
+ - Ensure Azure Identity credentials have proper Dataverse permissions
345
+ - Check app registration permissions are granted and admin-consented
346
+
347
+ ### Performance considerations
348
+
349
+ For optimal performance in production environments:
350
+
351
+ | Best Practice | Description |
352
+ |---------------|-------------|
353
+ | **Bulk Operations** | Pass lists to `create()`, `update()`, and `delete()` for automatic bulk processing |
354
+ | **Select Fields** | Specify `select` parameter to limit returned columns and reduce payload size |
355
+ | **Page Size Control** | Use `top` and `page_size` parameters to control memory usage |
356
+ | **Connection Reuse** | Reuse `DataverseClient` instances across operations |
357
+ | **Production Credentials** | Use `ClientSecretCredential` or `ClientCertificateCredential` for unattended operations |
358
+ | **Error Handling** | Implement retry logic for transient errors (`e.is_transient`) |
359
+
360
+ ### Limitations
361
+
362
+ - SQL queries are **read-only** and support a limited subset of SQL syntax
363
+ - Create Table supports a limited number of column types. Lookup columns are not yet supported.
364
+ - Creating relationships between tables is not yet supported.
365
+ - File uploads are limited by Dataverse file size restrictions (default 128MB per file)
366
+
367
+ ## Contributing
368
+
369
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
370
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
371
+ the rights to use your contribution. For details, visit [Contributor License Agreements](https://cla.opensource.microsoft.com).
372
+
373
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
374
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
375
+ provided by the bot. You will only need to do this once across all repos using our CLA.
376
+
377
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
378
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
379
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
380
+
381
+ ## Trademarks
382
+
383
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.