Generate production-ready Python 3.10+ code for the PowerPlatform-Dataverse-Client SDK with DataverseError handling, singleton client management, retry with exponential backoff for 429/timeout failures, OData optimization, audit logging, type hints, docstrings, configuration handling, and usage examples. Use when asked for Dataverse Python code, SDK examples, or system instructions.
Generate production-ready Python for the PowerPlatform-Dataverse-Client SDK by using typed service classes, singleton client management, Dataverse exception handling, retryable transient errors, server-side OData filtering, and structured logging instead of throwaway snippets.
When to invoke
"Generate production Python for Dataverse."
"Write PowerPlatform-Dataverse-Client SDK code with retries."
"Show Dataverse error handling and logging patterns."
"Create a singleton Dataverse client service."
"Optimize this Dataverse query with OData select and filter."
Code generation criteria
Area
Required rule
Python version
Code must be syntactically correct Python 3.10+.
Imports
Order stdlib, third-party, then local imports.
Error handling
Catch DataverseError, ValidationError, MetadataError, and HttpError with try-except blocks where appropriate.
Retry
Retry transient 429 or timeout errors with exponential backoff; default max_retries=3.
Client management
Use a singleton service class so connection management is centralized.
OData
Filter on the server, select only needed columns, use lowercase logical names, and apply orderby, top, and expand when appropriate.
Logging
Use logger, not print(), with enough context for audit trails and debugging.
Types and docs
Include type hints and docstrings for all public functions.
Configuration
Keep secrets, URLs, and credentials in configuration; do not hardcode them.
Style
Follow PEP 8 and Microsoft best practices from official examples.
Error handling pattern
from PowerPlatform.Dataverse.core.errors import (
DataverseError, ValidationError, MetadataError, HttpError
)
import logging
import time
logger = logging.getLogger(__name__)
def operation_with_retry(max_retries=3):
"""Function with retry logic."""
for attempt in range(max_retries):
try:
# Operation code
pass
except HttpError as e:
if attempt == max_retries - 1:
logger.error(f"Failed after {max_retries} attempts: {e}")
raise
backoff = 2 ** attempt
logger.warning(f"Attempt {attempt + 1} failed. Retrying in {backoff}s")
time.sleep(backoff)
Client management pattern
class DataverseService:
_instance = None
_client = None
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance
def __init__(self, org_url, credential):
if self._client is None:
self._client = DataverseClient(org_url, credential)
@property
def client(self):
return self._client
API calls are inside try/except blocks using DataverseError, ValidationError, MetadataError, and HttpError where applicable.
Retry logic with exponential backoff covers transient 429 and timeout errors.
Client creation follows the singleton DataverseService pattern.
OData queries use select, server-side filter, lowercase logical names, and orderby/top/expand when appropriate.
All public functions include type hints and docstrings.
Logging uses logger and never print() for operational messages.
Secrets, URLs, and credentials are configuration-driven, not hardcoded.
The answer includes imports, configuration, main implementation, usage example, error scenarios, and logging statements.
1---2name: dataverse-python-production-code3description: Generate production-ready Python 3.10+ code for the PowerPlatform-Dataverse-Client SDK with DataverseError handling, singleton client management, retry with exponential backoff for 429/timeout failures, OData optimization, audit logging, type hints, docstrings, configuration handling, and usage examples. Use when asked for Dataverse Python code, SDK examples, or system instructions.4---56<!-- Generated from harness/github-copilot/skills/dataverse-python-production-code/SKILL.md by harness/claude-code/scripts/convert_from_copilot.py. Edit the source, not this file. -->78# Dataverse Python production code910Generate production-ready Python for the PowerPlatform-Dataverse-Client SDK by using typed service classes, singleton client management, Dataverse exception handling, retryable transient errors, server-side OData filtering, and structured logging instead of throwaway snippets.1112## When to invoke1314- "Generate production Python for Dataverse."15- "Write PowerPlatform-Dataverse-Client SDK code with retries."16- "Show Dataverse error handling and logging patterns."17- "Create a singleton Dataverse client service."18- "Optimize this Dataverse query with OData select and filter."1920## Code generation criteria2122| Area | Required rule |23| --- | --- |24| Python version | Code must be syntactically correct Python 3.10+. |25| Imports | Order stdlib, third-party, then local imports. |26| Error handling | Catch `DataverseError`, `ValidationError`, `MetadataError`, and `HttpError` with try-except blocks where appropriate. |27| Retry | Retry transient `429` or timeout errors with exponential backoff; default `max_retries=3`. |28| Client management | Use a singleton service class so connection management is centralized. |29| OData | Filter on the server, select only needed columns, use lowercase logical names, and apply `orderby`, `top`, and `expand` when appropriate. |30| Logging | Use `logger`, not `print()`, with enough context for audit trails and debugging. |31| Types and docs | Include type hints and docstrings for all public functions. |32| Configuration | Keep secrets, URLs, and credentials in configuration; do not hardcode them. |33| Style | Follow PEP 8 and Microsoft best practices from official examples. |3435## Error handling pattern3637```python38from PowerPlatform.Dataverse.core.errors import (39 DataverseError, ValidationError, MetadataError, HttpError40)41import logging42import time4344logger = logging.getLogger(__name__)4546def operation_with_retry(max_retries=3):47 """Function with retry logic."""48 for attempt in range(max_retries):49 try:50 # Operation code51 pass52 except HttpError as e:53 if attempt == max_retries - 1:54 logger.error(f"Failed after {max_retries} attempts: {e}")55 raise56 backoff = 2 ** attempt57 logger.warning(f"Attempt {attempt + 1} failed. Retrying in {backoff}s")58 time.sleep(backoff)59```6061## Client management pattern6263```python64class DataverseService:65 _instance = None66 _client = None6768 def __new__(cls, *args, **kwargs):69 if cls._instance is None:70 cls._instance = super().__new__(cls)71 return cls._instance7273 def __init__(self, org_url, credential):74 if self._client is None:75 self._client = DataverseClient(org_url, credential)7677 @property78 def client(self):79 return self._client80```8182## Logging pattern8384```python85import logging8687logging.basicConfig(88 level=logging.INFO,89 format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'90)91logger = logging.getLogger(__name__)9293logger.info(f"Created {count} records")94logger.warning(f"Record {id} not found")95logger.error(f"Operation failed: {error}")96```9798## OData optimization rules99100| Rule | Reason |101| --- | --- |102| Always include `select` | Avoid transferring unused columns. |103| Use `filter` on server | Do not fetch broad records and filter in Python. |104| Use lowercase logical names | Dataverse logical names are lowercase and differ from display names. |105| Use `orderby` and `top` | Make pagination and result order deterministic. |106| Use `expand` for related records when available | Avoid manual follow-up calls when supported. |107| Log query intent, not secrets | Audit behavior without leaking tokens or PII. |108109## User request processing110111When generating code, include these sections:1121131. Imports with all required modules.1142. Configuration section with `constants/enums`.1153. Main implementation with proper error handling.1164. Docstrings explaining parameters and return values.1175. Type hints for all functions.1186. Usage example showing how to call the code.1197. Error scenarios with exception handling.1208. Logging statements for debugging.121122## Output template123124````markdown125## Dataverse Python implementation126127**Status:** generated | needs details | blocked128**SDK:** `PowerPlatform-Dataverse-Client`129**Python:** `3.10+`130131### Code132```python133from PowerPlatform.Dataverse.core.errors import DataverseError, ValidationError, MetadataError, HttpError134135# stdlib imports, configuration, logging, singleton DataverseService,136# OData-optimized operation, retry handling, usage example137```138139### Error scenarios140| Scenario | Exception | Handling |141| --- | --- | --- |142| Validation failure | `ValidationError` | fail fast with clear message |143| Metadata issue | `MetadataError` | log and raise |144| HTTP 429/timeout | `HttpError` | retry with exponential backoff |145| Other Dataverse failure | `DataverseError` | log with context and raise |146147### OData query choices148- `select`: <columns>149- `filter`: <server-side filter>150- `orderby`: <ordering>151- `top`: <limit>152- `expand`: <related records if used>153````154155## Quality gate156157- [ ] Code is valid Python 3.10+ and follows PEP 8.158- [ ] API calls are inside try/except blocks using `DataverseError`, `ValidationError`, `MetadataError`, and `HttpError` where applicable.159- [ ] Retry logic with exponential backoff covers transient `429` and timeout errors.160- [ ] Client creation follows the singleton `DataverseService` pattern.161- [ ] OData queries use `select`, server-side `filter`, lowercase logical names, and `orderby`/`top`/`expand` when appropriate.162- [ ] All public functions include type hints and docstrings.163- [ ] Logging uses `logger` and never `print()` for operational messages.164- [ ] Secrets, URLs, and credentials are configuration-driven, not hardcoded.165- [ ] The answer includes imports, configuration, main implementation, usage example, error scenarios, and logging statements.
Run npx skillmds@latest add paulasilvatech/dataverse-python-production-code in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Generate production-ready Python 3.10+ code for the PowerPlatform-Dataverse-Client SDK with DataverseError handling, singleton client management, retry with exponential backoff for 429/timeout failures, OData optimization, audit logging, type hints, docstrings, configuration handling, and usage examples. Use when asked for Dataverse Python code, SDK examples, or system instructions. It is listed under Security on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
paulasilvatech (@paulasilvatech) published this skill. Their other Agent Skills are listed on their SkillMD profile.