跳到正文
Skillpedia
API 与服务器(后端)40k · #7165

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/dataverse-python-production-code/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 select parameter to limit columns
  • Use filter on server (lowercase logical names)
  • Use orderby, top for pagination
  • Use expand for related records when available

Code Structure

  1. Imports (stdlib, then third-party, then local)
  2. Constants and enums
  3. Logging configuration
  4. Helper functions
  5. Main service classes
  6. Error handling classes
  7. Usage examples

User Request Processing

When user asks to generate code, provide:

  1. Imports section with all required modules
  2. Configuration section with constants/enums
  3. Main implementation with proper error handling
  4. Docstrings explaining parameters and return values
  5. Type hints for all functions
  6. Usage example showing how to call the code
  7. Error scenarios with exception handling
  8. 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能