Dataverse Python use case builder
Transform a Dataverse business need into a production-ready Python architecture with table design, pattern selection, SDK code, performance guidance, error handling, monitoring, and tests.
When to invoke
- "Build a Python Dataverse solution for this use case."
- "Design tables and code for a Dataverse document workflow."
- "Generate PowerPlatform-Dataverse-Client SDK code for bulk sync."
- "Create a Dataverse scheduled job in Python."
- "Recommend Dataverse architecture for this business process."
Prerequisites and context
- Target Python 3.10+ and PEP 8 style.
- Use
PowerPlatform.Dataverse.client.DataverseClient, PowerPlatform.Dataverse.core.config.DataverseConfig, and azure.identity.ClientSecretCredential when authentication is needed.
- Use Dataverse table logical names, relationship names, choice values, and file columns supplied by the user or discovered from metadata. Do not invent production schema names without labeling them as proposed.
Procedure
- Analyze requirements: operations, data volume, frequency, performance, error tolerance, and audit needs.
- Design the data model: tables, columns, relationships, lookups, files, and option sets.
- Select the implementation pattern from the pattern table.
- Generate complete Python code with configuration, service class, operations, error handling, logging, and usage examples.
- Add optimization recommendations for the expected volume and latency.
- Document monitoring, metrics, test strategy, and recovery behavior.
Requirement analysis questions
| Area |
Ask or infer |
| Operations |
Create, Read, Update, Delete, Bulk, Query, file upload, or delete. |
| Volume |
Record count, file sizes, page sizes, and batch sizes. |
| Frequency |
One-time, batch, real-time, scheduled, daily, weekly, monthly. |
| Performance |
Response time, throughput, timeout tolerance. |
| Error tolerance |
Retry strategy, idempotency, partial success handling, resume behavior. |
| Audit |
Logging, history, compliance, privacy, user activity tracking. |
Data model design
Use proposed schema blocks like this when the real schema is not provided:
tables = {
"account": {
"custom_fields": ["new_documentcount", "new_lastdocumentdate"]
},
"new_document": {
"primary_key": "new_documentid",
"columns": {
"new_name": "string",
"new_documenttype": "enum",
"new_parentaccount": "lookup(account)",
"new_uploadedby": "lookup(user)",
"new_uploadeddate": "datetime",
"new_documentfile": "file"
}
}
}
Pattern selection
| Pattern |
Use when |
Examples |
| Transactional CRUD Operations |
Single record creation/update, immediate consistency, relationships, lookups. |
Order management, invoice creation. |
| Batch Processing |
Bulk create/update/delete, performance priority, partial failure acceptable. |
Data migration, daily sync. |
| Query & Analytics |
Complex filtering, aggregation, pagination, optimized reads. |
Reporting, dashboards. |
| File Management |
Document upload/storage, chunked transfers, audit trail. |
Contract management, media library. |
| Scheduled Jobs |
Recurring operations, external synchronization, resumable cleanup. |
Nightly syncs, cleanup tasks. |
| Real-time Integration |
Event-driven low-latency processing with status tracking. |
Order processing, approval workflows. |
Implementation skeleton
import logging
from enum import IntEnum
from typing import Optional, List, Dict, Any
from datetime import datetime
from pathlib import Path
from PowerPlatform.Dataverse.client import DataverseClient
from PowerPlatform.Dataverse.core.config import DataverseConfig
from PowerPlatform.Dataverse.core.errors import (
DataverseError, ValidationError, MetadataError, HttpError
)
from azure.identity import ClientSecretCredential
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class Status(IntEnum):
DRAFT = 1
ACTIVE = 2
ARCHIVED = 3
class DataverseService:
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)
cls._instance._initialize()
return cls._instance
def _initialize(self):
config = DataverseConfig()
credential = ClientSecretCredential(
tenant_id=config.tenant_id,
client_id=config.client_id,
client_secret=config.client_secret,
)
self.client = DataverseClient(config=config, credential=credential)
Include CRUD, bulk, query, file, or scheduled methods after this skeleton based on the selected pattern.
Optimization rules
| Scenario |
Pattern |
| High-volume create/update |
Use batch operations: client.create("table", [record1, record2, record3]); avoid one network call per row. |
| Bulk load |
Chunk input and track successful IDs: client.create("table", [record] * 1000). |
| Complex query |
Use filter, select, orderby, and top=500; process pages instead of materializing all results. |
| Large file transfer |
Use chunked upload with chunk_size=4 * 1024 * 1024 for 4 MB chunks. |
| Recovery |
Store checkpoints, retry transient HttpError, and treat validation failures as data-quality records. |
for page in client.get(
"table",
filter="status eq 1",
select=["id", "name", "amount"],
orderby="name",
top=500
):
pass
client.upload_file(
table_name="table",
record_id=id,
file_column_name="new_file",
file_path=path,
chunk_size=4 * 1024 * 1024
)
Use case categories
| Category |
Typical cases |
| Customer Relationship Management |
Lead management, account hierarchy, contact tracking, opportunity pipeline, activity history. |
| Document Management |
Storage and retrieval, version control, access control, audit trails, compliance tracking. |
| Data Integration |
ETL, data synchronization, external system integration, migration, backup/restore. |
| Business Process |
Order management, approval workflows, project tracking, inventory, resource allocation. |
| Reporting & Analytics |
Aggregation, historical analysis, KPI tracking, dashboard data, export functionality. |
| Compliance & Audit |
Change tracking, user activity logging, governance, retention policies, privacy management. |
Dataverse implementation labels
Use these labels when structuring generated code and architecture notes: Backup/restore, CLASS, CONFIGURATION, CONSTANTS, ENUMS, ERROR, EXAMPLE, HANDLING, OPERATIONS, PATTERN, RECOVERY, SERVICE, SETUP, SINGLETON, SPECIFIC, USAGE, Upload/store, and relationships/lookups.
Output template
## Dataverse Python solution - <use case>
**Status:** complete | needs details | blocked
**Pattern:** Transactional CRUD Operations | Batch Processing | Query & Analytics | File Management | Scheduled Jobs | Real-time Integration
### Architecture overview
<2-3 sentence design summary>
### Data model
| Table | Relationship | Key columns | Notes |
| --- | --- | --- | --- |
| `<logical name>` | `<relationship>` | `<columns>` | `<constraints>` |
### Implementation code
```python
<complete Python 3.10+ code>
Usage instructions
Performance notes
- <throughput, batch, paging, or chunking guidance>
Error handling
| Failure |
Recovery |
<failure> |
<retry, skip, compensate, or alert> |
Monitoring
Testing
## Quality gate
- [ ] The solution states operations, volume, frequency, performance, error tolerance, and audit assumptions.
- [ ] Proposed table and column names are labeled when not user-provided.
- [ ] Code includes all imports, type hints, logging, and Dataverse error handling.
- [ ] The selected pattern matches the use case category and volume.
- [ ] Bulk, paging, or chunking is used for high-volume records or files.
- [ ] Usage, monitoring, and testing guidance are included.
1---2name: dataverse-python-usecase-builder-23description: Generate complete Python solutions for Microsoft Dataverse SDK business use cases, including architecture, table design, CRUD, batch, query, file, scheduled, or real-time patterns. Use this skill when the user describes a Dataverse business need and asks for production-ready Python code, PowerPlatform-Dataverse-Client guidance, or Dataverse solution architecture.4---56# Dataverse Python use case builder78Transform a Dataverse business need into a production-ready Python architecture with table design, pattern selection, SDK code, performance guidance, error handling, monitoring, and tests.910## When to invoke1112- "Build a Python Dataverse solution for this use case."13- "Design tables and code for a Dataverse document workflow."14- "Generate PowerPlatform-Dataverse-Client SDK code for bulk sync."15- "Create a Dataverse scheduled job in Python."16- "Recommend Dataverse architecture for this business process."1718## Prerequisites and context1920- Target Python 3.10+ and PEP 8 style.21- Use `PowerPlatform.Dataverse.client.DataverseClient`, `PowerPlatform.Dataverse.core.config.DataverseConfig`, and `azure.identity.ClientSecretCredential` when authentication is needed.22- Use Dataverse table logical names, relationship names, choice values, and file columns supplied by the user or discovered from metadata. Do not invent production schema names without labeling them as proposed.2324## Procedure25261. Analyze requirements: operations, data volume, frequency, performance, error tolerance, and audit needs.272. Design the data model: tables, columns, relationships, lookups, files, and option sets.283. Select the implementation pattern from the pattern table.294. Generate complete Python code with configuration, service class, operations, error handling, logging, and usage examples.305. Add optimization recommendations for the expected volume and latency.316. Document monitoring, metrics, test strategy, and recovery behavior.3233## Requirement analysis questions3435| Area | Ask or infer |36| --- | --- |37| Operations | Create, Read, Update, Delete, Bulk, Query, file upload, or delete. |38| Volume | Record count, file sizes, page sizes, and batch sizes. |39| Frequency | One-time, batch, real-time, scheduled, daily, weekly, monthly. |40| Performance | Response time, throughput, timeout tolerance. |41| Error tolerance | Retry strategy, idempotency, partial success handling, resume behavior. |42| Audit | Logging, history, compliance, privacy, user activity tracking. |4344## Data model design4546Use proposed schema blocks like this when the real schema is not provided:4748```python49tables = {50 "account": {51 "custom_fields": ["new_documentcount", "new_lastdocumentdate"]52 },53 "new_document": {54 "primary_key": "new_documentid",55 "columns": {56 "new_name": "string",57 "new_documenttype": "enum",58 "new_parentaccount": "lookup(account)",59 "new_uploadedby": "lookup(user)",60 "new_uploadeddate": "datetime",61 "new_documentfile": "file"62 }63 }64}65```6667## Pattern selection6869| Pattern | Use when | Examples |70| --- | --- | --- |71| Transactional CRUD Operations | Single record creation/update, immediate consistency, relationships, lookups. | Order management, invoice creation. |72| Batch Processing | Bulk create/update/delete, performance priority, partial failure acceptable. | Data migration, daily sync. |73| Query & Analytics | Complex filtering, aggregation, pagination, optimized reads. | Reporting, dashboards. |74| File Management | Document upload/storage, chunked transfers, audit trail. | Contract management, media library. |75| Scheduled Jobs | Recurring operations, external synchronization, resumable cleanup. | Nightly syncs, cleanup tasks. |76| Real-time Integration | Event-driven low-latency processing with status tracking. | Order processing, approval workflows. |7778## Implementation skeleton7980```python81import logging82from enum import IntEnum83from typing import Optional, List, Dict, Any84from datetime import datetime85from pathlib import Path86from PowerPlatform.Dataverse.client import DataverseClient87from PowerPlatform.Dataverse.core.config import DataverseConfig88from PowerPlatform.Dataverse.core.errors import (89 DataverseError, ValidationError, MetadataError, HttpError90)91from azure.identity import ClientSecretCredential9293logging.basicConfig(level=logging.INFO)94logger = logging.getLogger(__name__)9596class Status(IntEnum):97 DRAFT = 198 ACTIVE = 299 ARCHIVED = 3100101class DataverseService:102 _instance = None103104 def __new__(cls):105 if cls._instance is None:106 cls._instance = super().__new__(cls)107 cls._instance._initialize()108 return cls._instance109110 def _initialize(self):111 config = DataverseConfig()112 credential = ClientSecretCredential(113 tenant_id=config.tenant_id,114 client_id=config.client_id,115 client_secret=config.client_secret,116 )117 self.client = DataverseClient(config=config, credential=credential)118```119120Include CRUD, bulk, query, file, or scheduled methods after this skeleton based on the selected pattern.121122## Optimization rules123124| Scenario | Pattern |125| --- | --- |126| High-volume create/update | Use batch operations: `client.create("table", [record1, record2, record3])`; avoid one network call per row. |127| Bulk load | Chunk input and track successful IDs: `client.create("table", [record] * 1000)`. |128| Complex query | Use `filter`, `select`, `orderby`, and `top=500`; process pages instead of materializing all results. |129| Large file transfer | Use chunked upload with `chunk_size=4 * 1024 * 1024` for 4 MB chunks. |130| Recovery | Store checkpoints, retry transient `HttpError`, and treat validation failures as data-quality records. |131132```python133for page in client.get(134 "table",135 filter="status eq 1",136 select=["id", "name", "amount"],137 orderby="name",138 top=500139):140 pass141142client.upload_file(143 table_name="table",144 record_id=id,145 file_column_name="new_file",146 file_path=path,147 chunk_size=4 * 1024 * 1024148)149```150151## Use case categories152153| Category | Typical cases |154| --- | --- |155| Customer Relationship Management | Lead management, account hierarchy, contact tracking, opportunity pipeline, activity history. |156| Document Management | Storage and retrieval, version control, access control, audit trails, compliance tracking. |157| Data Integration | ETL, data synchronization, external system integration, migration, backup/restore. |158| Business Process | Order management, approval workflows, project tracking, inventory, resource allocation. |159| Reporting & Analytics | Aggregation, historical analysis, KPI tracking, dashboard data, export functionality. |160| Compliance & Audit | Change tracking, user activity logging, governance, retention policies, privacy management. |161162## Dataverse implementation labels163164Use these labels when structuring generated code and architecture notes: `Backup/restore`, `CLASS`, `CONFIGURATION`, `CONSTANTS`, `ENUMS`, `ERROR`, `EXAMPLE`, `HANDLING`, `OPERATIONS`, `PATTERN`, `RECOVERY`, `SERVICE`, `SETUP`, `SINGLETON`, `SPECIFIC`, `USAGE`, `Upload/store`, and `relationships/lookups`.165166## Output template167168```markdown169## Dataverse Python solution - <use case>170171**Status:** complete | needs details | blocked172**Pattern:** Transactional CRUD Operations | Batch Processing | Query & Analytics | File Management | Scheduled Jobs | Real-time Integration173174### Architecture overview175<2-3 sentence design summary>176177### Data model178| Table | Relationship | Key columns | Notes |179| --- | --- | --- | --- |180| `<logical name>` | `<relationship>` | `<columns>` | `<constraints>` |181182### Implementation code183```python184<complete Python 3.10+ code>185```186187### Usage instructions1881. <configuration step>1892. <run command or entry point>190191### Performance notes192- <throughput, batch, paging, or chunking guidance>193194### Error handling195| Failure | Recovery |196| --- | --- |197| `<failure>` | `<retry, skip, compensate, or alert>` |198199### Monitoring200- <metric to track>201202### Testing203- <unit or integration test pattern>204```205206## Quality gate207208- [ ] The solution states operations, volume, frequency, performance, error tolerance, and audit assumptions.209- [ ] Proposed table and column names are labeled when not user-provided.210- [ ] Code includes all imports, type hints, logging, and Dataverse error handling.211- [ ] The selected pattern matches the use case category and volume.212- [ ] Bulk, paging, or chunking is used for high-volume records or files.213- [ ] Usage, monitoring, and testing guidance are included.