/vibe:ghcopilot-instr-dataverse-python-best-practicesfrom vibe
Provides production-ready patterns for the Dataverse SDK for Python, covering authentication, CRUD operations, querying, error handling, and performance optimization.
Ships in vibe. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Production-ready patterns and best practices extracted from Microsoft's official PowerPlatform-DataverseClient-Python repository, examples, and recommended workflows.
# Install the published SDK from PyPI
pip install PowerPlatform-Dataverse-Client
# Install Azure Identity for authentication
pip install azure-identity
# Optional: pandas integration for data manipulation
pip install pandas
# Clone the repository
git clone https://github.com/microsoft/PowerPlatform-DataverseClient-Python.git
cd PowerPlatform-DataverseClient-Python
# Install in editable mode for live development
pip install -e .
# Install development dependencies
pip install pytest pytest-cov black isort mypy ruff
from PowerPlatform.Dataverse import __version__
from PowerPlatform.Dataverse.client import DataverseClient
from azure.identity import InteractiveBrowserCredential
print(f"SDK Version: {__version__}")
print("Installation successful!")
from azure.identity import InteractiveBrowserCredential
from PowerPlatform.Dataverse.client import DataverseClient
credential = InteractiveBrowserCredential()
client = DataverseClient("https://yourorg.crm.dynamics.com", credential)
When to use: Local development, interactive testing, single-user scenarios.
from azure.identity import ClientSecretCredential
from PowerPlatform.Dataverse.client import DataverseClient
credential = ClientSecretCredential(
tenant_id="your-tenant-id",
client_id="your-client-id",
client_secret="your-client-secret"
)
client = DataverseClient("https://yourorg.crm.dynamics.com", credential)
When to use: Server-side applications, Azure automation, scheduled jobs.
from azure.identity import ClientCertificateCredential
from PowerPlatform.Dataverse.client import DataverseClient
credential = ClientCertificateCredential(
tenant_id="your-tenant-id",
client_id="your-client-id",
certificate_path="path/to/certificate.pem"
)
client = DataverseClient("https://yourorg.crm.dynamics.com", credential)
When to use: Highly secure environments, certificate-pinning requirements.
from azure.identity import AzureCliCredential
from PowerPlatform.Dataverse.client import DataverseClient
credential = AzureCliCredential()
client = DataverseClient("https://yourorg.crm.dynamics.com", credential)
When to use: Local testing with Azure CLI installed, Azure DevOps pipelines.
Best Practice: Create one DataverseClient instance and reuse it throughout your application.
# ❌ ANTI-PATTERN: Creating new clients repeatedly
def fetch_account(account_id):
credential = InteractiveBrowserCredential()
client = DataverseClient("https://yourorg.crm.dynamics.com", credential)
return client.get("account", account_id)
# ✅ PATTERN: Singleton client
class DataverseService:
_instance = None
def __new__(cls):
if cls._instance is None:
credential = InteractiveBrowserCredential()
cls._instance = DataverseClient(
"https://yourorg.crm.dynamics.com",
credential
)
return cls._instance
# Usage
service = DataverseService()
account = service.get("account", account_id)
from PowerPlatform.Dataverse.core.config import DataverseConfig
from PowerPlatform.Dataverse.client import DataverseClient
from azure.identity import ClientSecretCredential
config = DataverseConfig(
language_code=1033, # English (US)
# Note: http_retries, http_backoff, http_timeout are reserved for internal use
)
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
client = DataverseClient("https://yourorg.crm.dynamics.com", credential, config)
Key configuration options:
language_code: Language for API responses (default: 1033 for English)record_data = {
"name": "Contoso Ltd",
"telephone1": "555-0100",
"creditlimit": 100000.00,
}
created_ids = client.create("account", record_data)
record_id = created_ids[0]
print(f"Created: {record_id}")
# SDK automatically uses CreateMultiple for arrays > 1 record
records = [
{"name": f"Company {i}", "creditlimit": 50000 + (i * 1000)}
for i in range(100)
]
created_ids = client.create("account", records)
print(f"Created {len(created_ids)} records")
Performance: Bulk create is optimized internally; no manual batching required.
account = client.get("account", "account-guid-here")
print(account.get("name"))
# Returns paginated results (generator)
for page in client.get(
"account",
filter="creditlimit gt 50000",
select=["name", "creditlimit", "telephone1"],
orderby="name",
top=100
):
for account in page:
print(f"{account['name']}: ${account['creditlimit']}")
Key parameters:
filter: OData filter (must use lowercase logical names)select: Fields to retrieve (improves performance)orderby: Sort resultstop: Max records per page (default: 5000)page_size: Override page size for pagination# SQL queries are read-only; use for complex analytics
results = client.query_sql("""
SELECT TOP 10 name, creditlimit
FROM account
WHERE creditlimit > 50000
ORDER BY name
""")
for row in results:
print(f"{row['name']}: ${row['creditlimit']}")
Limitations:
client.update("account", "account-guid", {
"creditlimit": 150000.00,
"name": "Updated Company Name"
})
# Update all selected records with same data
account_ids = ["id1", "id2", "id3"]
client.update("account", account_ids, {
"industrycode": 1, # Retail
"accountmanagerid": "manager-guid"
})
# For different updates per record, send multiple calls
updates = {
"id1": {"creditlimit": 100000},
"id2": {"creditlimit": 200000},
"id3": {"creditlimit": 300000},
}
for record_id, data in updates.items():
client.update("account", record_id, data)
client.delete("account", "account-guid")
# SDK automatically uses BulkDelete for large lists
record_ids = ["id1", "id2", "id3", ...]
client.delete("account", record_ids, use_bulk_delete=True)
from PowerPlatform.Dataverse.core.errors import (
DataverseError, # Base class
ValidationError, # Validation failures
MetadataError, # Table/column operations
HttpError, # HTTP-level errors
SQLParseError # SQL query syntax errors
)
try:
client.create("account", {"name": None}) # Invalid
except ValidationError as e:
print(f"Validation failed: {e}")
# Handle validation-specific logic
except DataverseError as e:
print(f"General SDK error: {e}")
# Handle other SDK errors
import time
from PowerPlatform.Dataverse.core.errors import HttpError
def create_with_retry(table_name, record_data, max_retries=3):
"""Create record with exponential backoff retry logic."""
for attempt in range(max_retries):
try:
return client.create(table_name, record_data)
except HttpError as e:
if attempt == max_retries - 1:
raise
# Exponential backoff: 1s, 2s, 4s
backoff_seconds = 2 ** attempt
print(f"Attempt {attempt + 1} failed. Retrying in {backoff_seconds}s...")
time.sleep(backoff_seconds)
# Usage
created_ids = create_with_retry("account", {"name": "Contoso"})
import time
from PowerPlatform.Dataverse.core.errors import HttpError
try:
accounts = client.get("account", top=5000)
except HttpError as e:
if "429" in str(e):
# Rate limited; wait and retry
print("Rate limited. Waiting 60 seconds...")
time.sleep(60)
accounts = client.get("account", top=5000)
else:
raise
from enum import IntEnum
class Priority(IntEnum):
LOW = 1
MEDIUM = 2
HIGH = 3
# Define columns with types
columns = {
"new_Title": "string",
"new_Quantity": "int",
"new_Amount": "decimal",
"new_Completed": "bool",
"new_Priority": Priority, # Creates option set/picklist
"new_CreatedDate": "datetime"
}
table_info = client.create_table(
"new_CustomTable",
primary_column_schema_name="new_Name",
columns=columns
)
print(f"Created table: {table_info['table_schema_name']}")
table_info = client.get_table_info("account")
print(f"Schema Name: {table_info['table_schema_name']}")
print(f"Logical Name: {table_info['table_logical_name']}")
print(f"Entity Set: {table_info['entity_set_name']}")
print(f"Primary ID: {table_info['primary_id_attribute']}")
tables = client.list_tables()
for table in tables:
print(f"{table['table_schema_name']} ({table['table_logical_name']})")
# Add columns to existing table
client.create_columns("new_CustomTable", {
"new_Status": "string",
"new_Priority": "int"
})
# Delete columns
client.delete_columns("new_CustomTable", ["new_Status", "new_Priority"])
# Delete table
client.delete_table("new_CustomTable")
# Retrieve all accounts in pages
all_accounts = []
for page in client.get(
"account",
top=500, # Records per page
page_size=500
):
all_accounts.extend(page)
print(f"Retrieved page with {len(page)} records")
print(f"Total: {len(all_accounts)} records")
# For complex paging scenarios
skip_count = 0
page_size = 1000
while True:
page = client.get("account", top=page_size, skip=skip_count)
if not page:
break
print(f"Page {skip_count // page_size + 1}: {len(page)} records")
skip_count += page_size
from pathlib import Path
file_path = Path("document.pdf")
record_id = "account-guid"
# Single PATCH upload
response = client.upload_file(
table_name="account",
record_id=record_id,
file_column_name="new_documentfile",
file_path=file_path
)
print(f"Upload successful: {response}")
from pathlib import Path
file_path = Path("large_video.mp4")
record_id = "account-guid"
# SDK automatically chunks large files
response = client.upload_file(
table_name="account",
record_id=record_id,
file_column_name="new_videofile",
file_path=file_path,
chunk_size=4 * 1024 * 1024 # 4 MB chunks
)
print(f"Chunked upload complete")
# ❌ WRONG: Uppercase logical names
results = client.get("account", filter="Name eq 'Contoso'")
# ✅ CORRECT: Lowercase logical names
results = client.get("account", filter="name eq 'Contoso'")
# ✅ Values ARE case-sensitive when needed
results = client.get("account", filter="name eq 'Contoso Ltd'")
# Equality
client.get("account", filter="name eq 'Contoso'")
# Greater than / Less than
client.get("account", filter="creditlimit gt 50000")
client.get("account", filter="createdon lt 2024-01-01")
# String contains
client.get("account", filter="contains(name, 'Ltd')")
# AND/OR operations
client.get("account", filter="(name eq 'Contoso') and (creditlimit gt 50000)")
client.get("account", filter="(industrycode eq 1) or (industrycode eq 2)")
# NOT operation
client.get("account", filter="not(statecode eq 1)")
# Select specific columns (improves performance)
client.get("account", select=["name", "creditlimit", "telephone1"])
# Expand related records
client.get(
"account",
expand=["parentaccountid($select=name)"],
select=["name", "parentaccountid"]
)
# Clear SDK internal cache after bulk operations
client.flush_cache()
# Useful after:
# - Metadata changes (table/column creation)
# - Bulk deletes
# - Metadata synchronization
Use select parameter: Only fetch needed columns
client.get("account", select=["name", "creditlimit"])
Batch operations: Create/update multiple records at once
ids = client.create("account", [record1, record2, record3])
Use paging: Don't load all records at once
for page in client.get("account", top=1000):
process_page(page)
Reuse client instance: Create once, use many times
client = DataverseClient(url, credential) # Once
# Reuse throughout app
Apply filters on server: Let Dataverse filter before returning
client.get("account", filter="creditlimit gt 50000")
Don't fetch all columns: Specify what you need
# Slow
client.get("account")
Don't create records in loops: Batch them
# Slow
for record in records:
client.create("account", record)
Don't load all results at once: Use pagination
# Slow
all_accounts = list(client.get("account"))
Don't create new clients repeatedly: Reuse singleton
# Inefficient
for i in range(100):
client = DataverseClient(url, credential)
def upsert_account(name, data):
"""Create account or update if exists."""
try:
# Try to find existing
results = list(client.get("account", filter=f"name eq '{name}'"))
if results:
account_id = results[0]['accountid']
client.update("account", account_id, data)
return account_id, "updated"
else:
ids = client.create("account", {"name": name, **data})
return ids[0], "created"
except Exception as e:
print(f"Upsert failed: {e}")
raise
def create_with_recovery(records):
"""Create records with per-record error tracking."""
results = {"success": [], "failed": []}
try:
ids = client.create("account", records)
results["success"] = ids
except Exception as e:
# If bulk fails, try individual records
for i, record in enumerate(records):
try:
ids = client.create("account", record)
results["success"].append(ids[0])
except Exception as e:
results["failed"].append({"index": i, "record": record, "error": str(e)})
return results
# Verify installation
pip show PowerPlatform-Dataverse-Client
# Reinstall
pip install --upgrade PowerPlatform-Dataverse-Client
# Check virtual environment is activated
which python # Should show venv path
# Verify credentials have Dataverse access
# Try interactive auth first for testing
from azure.identity import InteractiveBrowserCredential
credential = InteractiveBrowserCredential(
tenant_id="your-tenant-id" # Specify if multiple tenants
)
# Check org URL format
# ✓ https://yourorg.crm.dynamics.com
# ❌ https://yourorg.crm.dynamics.com/
# ❌ https://yourorg.crm4.dynamics.com (regional)
# Reduce request frequency
# Implement exponential backoff (see Error Handling section)
# Reduce page size
client.get("account", top=500) # Instead of 5000
# Verify table exists (schema name is case-insensitive for existence, but case-sensitive for API)
tables = client.list_tables()
print([t['table_schema_name'] for t in tables])
# Use exact schema name
table_info = client.get_table_info("new_customprefixed_table")
# query_sql() requires org config
# If disabled, fallback to OData
try:
results = client.query_sql("SELECT * FROM account")
except Exception:
# Fallback to OData
results = client.get("account")
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub anubhavg-icpl/vibe --plugin vibe5,304 skills in this plugin
/3d-pipelineChoose a 3D generation or reconstruction pipeline given input type, output format, and use case. Use when you need help with 3d pipeline./8-bit-orbit-video-templateHyperframes Video TemplateShip a premium template-mode Hyperframes composition with a ready default showcase and deterministic timeline behavior./a2a-agent-specProduce the Agent Card and skills schema for an agent that should be callable over A2A. Use when you need help with a2a agent spec.Other plugins' skills for the same job