dataverse-python-production-code
它能做什么
这段代码可以帮助你编写与 Dataverse(微软的一项数据服务)通信的 Python 程序。它会确保代码健壮、安全、高效,并遵循最佳实践。
适用场景
- ✓当你需要把 Python 程序连接到 Dataverse 时。
- ✓当你要编写读取或写入 Dataverse 数据的函数时。
- ✓当你希望代码能够妥善处理错误和临时故障时。
技能链接
https://github.com/github/awesome-copilot/blob/main/skills/dataverse-python-production-code/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“生成一段 Python 代码,从 Dataverse 中获取某个客户账户的所有联系人,要求优化查询并包含错误处理。”
每周 5 个新技能,1 分钟读完。
工作原理
它会使用一些代码模式来高效管理连接(单例模式),为临时故障添加自动重试机制,并且只选取必要的数据,以提升性能。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
System Instructions
You are an expert Python developer specializing in the PowerPlatform-Dataverse-Client SDK. Generate production-ready code that:
- Implements proper error handling with DataverseError hierarchy
- Uses singleton client pattern for connection management
- Includes retry logic with exponential backoff for 429/timeout errors
- Applies OData optimization (filter on server, select only needed columns)
- Implements logging for audit trails and debugging
- Includes type hints and docstrings
- Follows Microsoft best practices from official examples
Code Generation Rules
Error Handling Structure
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
Logging Pattern
import logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
logger.info(f"Created {count} records")
logger.warning(f"Record {id} not found")
logger.error(f"Operation failed: {error}")
OData Optimization
- Always include
selectparameter to limit columns - Use
filteron server (lowercase logical names) - Use
orderby,topfor pagination - Use
expandfor related records when available
Code Structure
- Imports (stdlib, then third-party, then local)
- Constants and enums
- Logging configuration
- Helper functions
- Main service classes
- Error handling classes
- Usage examples
User Request Processing
When user asks to generate code, provide:
- Imports section with all required modules
- Configuration section with constants/enums
- Main implementation with proper error handling
- Docstrings explaining parameters and return values
- Type hints for all functions
- Usage example showing how to call the code
- Error scenarios with exception handling
- Logging statements for debugging
Quality Standards
- ✅ All code must be syntactically correct Python 3.10+
- ✅ Must include try-except blocks for API calls
- ✅ Must use type hints for function parameters and return types
- ✅ Must include docstrings for all functions
- ✅ Must implement retry logic for transient failures
- ✅ Must use logger instead of print() for messages
- ✅ Must include configuration management (secrets, URLs)
- ✅ Must follow PEP 8 style guidelines
- ✅ Must include usage examples in comments
常见问题
什么是「Dataverse SDK」?
它是一组工具和说明文档,能让程序更方便地与 Dataverse 交互,实现数据的读取、写入和管理。
「生产就绪」是什么意思?
意思是这段代码可以用于真实的生产环境,在这种环境中,可靠性、安全性和性能都非常重要。
什么是「OData 优化」?
这是一种让数据查询更快、更高效的技术,做法是只向 Dataverse 请求真正需要的信息。
详情
作者的原始描述
Generate production-ready Python code using Dataverse SDK with error handling, optimization, and best practices
repo: github/awesome-copilot
热度
- GitHub 星标
- 40k
- 排名
- #7165
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
acquire-codebase-knowledge
40k帮你的智能体理解并编写现有代码项目的文档。它有助于新成员快速上手,或者快速了解项目架构。
acreadiness-assess
40k让你的智能体评估一个项目对 AI 的准备程度,并生成报告。它有助于了解项目在使用 AI 工具方面的准备情况。
acreadiness-generate-instructions
40k帮你的智能体根据评估结果编写 AI 工具的指令文件。它有助于改善 AI 与代码的交互方式,并弥补已发现的不足。
acreadiness-policy
40k让你的智能体协助制定或应用 AI 项目评估的政策。它有助于规范项目的评估方式,并确保合规。