Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Direct TDS via ODBC is not used; SQL reads are executed via the Web API using th

```python
from azure.identity import InteractiveBrowserCredential
from dataverse_sdk import DataverseClient
from PowerPlatform.Dataverse import DataverseClient

base_url = "https://yourorg.crm.dynamics.com"
credential = InteractiveBrowserCredential() # or DeviceCodeCredential(), ClientSecretCredential(...), etc.
Expand All @@ -89,29 +89,29 @@ client = DataverseClient(base_url=base_url, credential=credential)

## Quickstart

Edit `examples/quickstart.py` and run:
For a comprehensive walkthrough, edit `examples/advanced/complete_walkthrough.py` and run:

```powershell
python examples/quickstart.py
python examples/advanced/complete_walkthrough.py
```

The quickstart demonstrates:
The walkthrough demonstrates:
- Creating a simple custom table (metadata APIs)
- Creating, reading, updating, and deleting records (OData)
- Bulk create (CreateMultiple) to insert many records in one call
- Bulk update via unified `update` (multi-ID broadcast & per‑record patches)
- Retrieve multiple with paging (`$top` vs `page_size`)
- Executing a read-only SQL query (Web API `?sql=`)

For upload files functionalities, run quickstart_file_upload.py instead
For upload files functionalities, run `examples/advanced/file_upload.py` instead

## Examples

### DataverseClient (recommended)

```python
from azure.identity import InteractiveBrowserCredential
from dataverse_sdk import DataverseClient
from PowerPlatform.Dataverse import DataverseClient

base_url = "https://yourorg.crm.dynamics.com"
credential = InteractiveBrowserCredential() # or DeviceCodeCredential(), ClientSecretCredential(...), etc.
Expand Down Expand Up @@ -343,7 +343,7 @@ Notes:

### Pandas helpers

`PandasODataClient` is a thin wrapper around the low-level client. All methods accept logical (singular) names (e.g. `account`, `new_sampleitem`), not entity set (plural) names. See `examples/quickstart_pandas.py` for a DataFrame workflow.
`PandasODataClient` is a thin wrapper around the low-level client. All methods accept logical (singular) names (e.g. `account`, `new_sampleitem`), not entity set (plural) names. See `examples/advanced/pandas_integration.py` for a DataFrame workflow.

VS Code Tasks
- Install deps: `Install deps (pip)`
Expand Down
103 changes: 76 additions & 27 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,98 @@
# Dataverse SDK Examples
# PowerPlatform Dataverse Client Examples

This directory contains comprehensive examples demonstrating how to use the Microsoft Dataverse SDK for Python.
This directory contains comprehensive examples demonstrating how to use the **PowerPlatform-Dataverse-Client** SDK for Python. The examples are organized in a progressive learning path: **Install → Learn → Test**.

## 📦 Installation

Install the PowerPlatform Dataverse Client SDK:

```bash
pip install PowerPlatform-Dataverse-Client
```

## 📁 Directory Structure

### 🌱 Basic Examples (`basic/`)
Get started quickly with fundamental Dataverse operations:
- **`quickstart.py`** - Basic client setup, authentication, and simple CRUD operations
- Authentication setup with Azure Identity
- Creating, reading, updating, and deleting records
- Basic error handling

### 🚀 Advanced Examples (`advanced/`)
Explore powerful features for complex scenarios:
- **`file_upload.py`** - File upload to Dataverse file columns with chunking
- **`pandas_integration.py`** - DataFrame-based operations for data analysis
Start here for getting up and running with the SDK:

- **`installation_example.py`** - **START HERE** 🎯
- Package installation validation and import verification
- Method availability checking and troubleshooting
- Basic usage examples and code patterns
- Optional interactive testing with real environment
- Perfect for first-run validation after installation

- **`functional_testing.py`** - **TEST BASIC FUNCTIONALITY** 🧪
- Simple functional testing in real Dataverse environments
- Basic CRUD operations validation with clean patterns
- Table creation and basic querying tests
- Interactive cleanup and straightforward validation
- Perfect for verifying SDK works in your environment

### 🔬 Advanced Examples (`advanced/`)
Deep-dive into production-ready patterns and specialized functionality:

- **`complete_walkthrough.py`** - **COMPREHENSIVE DEMO** 🚀
- Full SDK feature demonstration with production-ready patterns
- Table creation with custom schemas and enums
- Single and bulk CRUD operations with error handling
- Advanced querying (SQL and OData) with paging
- Column metadata management and multi-language support
- Interactive cleanup and best practices

- **`file_upload.py`** - **FILE OPERATIONS** 📎
- File upload to Dataverse file columns with chunking
- Advanced file handling patterns

- **`pandas_integration.py`** - **DATA ANALYSIS** 📊
- DataFrame-based operations for data analysis
- Pandas integration patterns

## 🚀 Getting Started

1. **Install Dependencies**:
```bash
pip install -r requirements.txt
```
Follow this recommended progression for the best learning experience:

### 📋 Step 1: Validate Installation
```bash
# Install the SDK and dependencies
pip install PowerPlatform-Dataverse-Client azure-identity

# Validate installation and imports
python examples/basic/installation_example.py
```

### 🧪 Step 2: Test Basic Functionality (Optional)
```bash
# Basic functional testing in your environment
python examples/basic/functional_testing.py
```

### 🚀 Step 3: Master Advanced Features
```bash
# Comprehensive walkthrough with production patterns
python examples/advanced/complete_walkthrough.py
```

2. **Set Up Authentication**:
Configure Azure Identity credentials (see individual examples for details)
## 🎯 Quick Start Recommendations

3. **Run Basic Example**:
```bash
python examples/basic/quickstart.py
```
- **New to the SDK?** → Start with `examples/basic/installation_example.py`
- **Need to test/validate?** → Use `examples/basic/functional_testing.py`
- **Want to see all features?** → Run `examples/advanced/complete_walkthrough.py`
- **Building production apps?** → Study patterns in `examples/advanced/complete_walkthrough.py`

## 📋 Prerequisites

- Python 3.8+
- Python 3.10+
- PowerPlatform-Dataverse-Client SDK installed (`pip install PowerPlatform-Dataverse-Client`)
- Azure Identity credentials configured
- Access to a Dataverse environment
- Required packages installed from `requirements.txt`

## 🔒 Authentication

All examples use Azure Identity for authentication. Common patterns:
- `DefaultAzureCredential` for development
- `ClientSecretCredential` for production services
- `InteractiveBrowserCredential` for interactive scenarios
- `InteractiveBrowserCredential` for development and interactive scenarios
- `DeviceCodeCredential` for development on headless systems
- `ClientSecretCredential` for production services with service principals

## 📖 Documentation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

"""
PowerPlatform Dataverse Client - Complete SDK Walkthrough

This comprehensive example demonstrates advanced usage of the PowerPlatform-Dataverse-Client SDK
including all major features and production-ready patterns.

Features Demonstrated:
- Authentication setup and connection management
- Table creation with custom schemas and enums
- Single and bulk record operations (CRUD)
- Advanced querying with SQL and OData
- Paging and batch processing
- Column metadata management
- Multi-language label support
- Error handling and retry patterns
- Interactive cleanup options

Prerequisites:
pip install PowerPlatform-Dataverse-Client
pip install azure-identity

For local development, you can also run from source by uncommenting the sys.path line below.

Note: This is a comprehensive demonstration. For basic installation validation,
use examples/basic/installation_example.py first.
"""

import sys
from pathlib import Path
import os
from typing import Optional

# Add src to PYTHONPATH for local runs
sys.path.append(str(Path(__file__).resolve().parents[1] / "src"))
# Uncomment for local development from source
# sys.path.append(str(Path(__file__).resolve().parents[2] / "src"))

from dataverse_sdk import DataverseClient
from dataverse_sdk.core.errors import MetadataError
from PowerPlatform.Dataverse import DataverseClient
from PowerPlatform.Dataverse.core.errors import MetadataError
from enum import IntEnum
from azure.identity import InteractiveBrowserCredential
import traceback
Expand Down
19 changes: 16 additions & 3 deletions examples/advanced/file_upload.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

"""
PowerPlatform Dataverse Client - File Upload Example

This example demonstrates file upload capabilities using the
PowerPlatform-Dataverse-Client SDK with automatic chunking for large files.

Prerequisites:
pip install PowerPlatform-Dataverse-Client
pip install azure-identity

For local development, you can also run from source by uncommenting the sys.path line below.
"""

import sys
from pathlib import Path
import os
import time
import traceback
from typing import Optional

# Add src to PYTHONPATH for local runs
sys.path.append(str(Path(__file__).resolve().parents[1] / "src"))
# Uncomment for local development from source
# sys.path.append(str(Path(__file__).resolve().parents[2] / "src"))

from dataverse_sdk import DataverseClient # type: ignore
from PowerPlatform.Dataverse import DataverseClient
from azure.identity import InteractiveBrowserCredential # type: ignore
import requests

Expand Down
22 changes: 18 additions & 4 deletions examples/advanced/pandas_integration.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

"""
PowerPlatform Dataverse Client - Pandas Integration Example

This example demonstrates advanced DataFrame-based operations using the
PowerPlatform-Dataverse-Client SDK with pandas integration.

Prerequisites:
pip install PowerPlatform-Dataverse-Client
pip install azure-identity
pip install pandas

For local development, you can also run from source by uncommenting the sys.path line below.
"""

import sys
from pathlib import Path
import os

# Add src to PYTHONPATH for local runs
sys.path.append(str(Path(__file__).resolve().parents[1] / "src"))
# Uncomment for local development from source
# sys.path.append(str(Path(__file__).resolve().parents[2] / "src"))

from dataverse_sdk import DataverseClient
from dataverse_sdk.utils.pandas_adapter import PandasODataClient
from PowerPlatform.Dataverse import DataverseClient
from PowerPlatform.Dataverse.utils.pandas_adapter import PandasODataClient
from azure.identity import InteractiveBrowserCredential
import traceback
import requests
Expand Down
Loading
Loading