A modern SharePoint client library for Python with federated authentication support
Project description
FetchPoint
A Python library for SharePoint Online integration with federated authentication support.
Overview
FetchPoint is a clean, enterprise-ready library for SharePoint Online integration with federated authentication support. Provides secure, read-only access to files stored in SharePoint document libraries with comprehensive error handling, metadata extraction, and Excel file focus. Designed for enterprise environments with Azure AD and federated authentication.
Key Features
- Federated Authentication: Azure AD and enterprise identity provider support
- Read-Only Operations: Secure file listing and downloading
- Excel Focus: Optimized for .xlsx, .xls, .xlsm, .xlsb files
- Path Validation: Hierarchical folder navigation with detailed error reporting
- Context Manager: Clean resource management
- Comprehensive Error Handling: Detailed diagnostics for troubleshooting
- No Environment Dependencies: Explicit configuration required (environment variables optional)
Installation
uv add fetchpoint
Quick Start
from fetchpoint import SharePointClient, create_sharepoint_config
# Create configuration
config = create_sharepoint_config(
username="user@company.com",
password="your_password",
sharepoint_url="https://company.sharepoint.com/sites/project"
)
# Use context manager (recommended)
with SharePointClient(config) as client:
# List Excel files
files = client.list_excel_files(
library_name="Documents",
folder_path="General/Reports"
)
# Download files
results = client.download_files(
library_name="Documents",
folder_path="General/Reports",
filenames=files,
download_dir="./downloads"
)
Configuration
Method 1: Explicit Configuration
from fetchpoint import create_sharepoint_config
config = create_sharepoint_config(
username="user@company.com", # Required: SharePoint username (email)
password="your_password", # Required: User password
sharepoint_url="https://company.sharepoint.com/sites/yoursite", # Required: SharePoint site URL
timeout_seconds=30, # Optional: Connection timeout (default: 30)
max_file_size_mb=100 # Optional: File size limit (default: 100)
)
Method 2: Dictionary Configuration
from fetchpoint import SharePointClient
client = SharePointClient.from_dict({
"username": "user@company.com",
"password": "your_password",
"sharepoint_url": "https://company.sharepoint.com/sites/yoursite"
})
Method 3: Environment Variables (Legacy)
# Required
SHAREPOINT_URL=https://company.sharepoint.com/sites/yoursite
SHAREPOINT_USERNAME=user@company.com
SHAREPOINT_PASSWORD=your_password
# Optional
SHAREPOINT_TIMEOUT_SECONDS=30
SHAREPOINT_MAX_FILE_SIZE_MB=100
SHAREPOINT_AUTH_TYPE=federated
SHAREPOINT_SESSION_TIMEOUT=3600
SHAREPOINT_LOG_LEVEL=INFO
Important: SHAREPOINT_URL is optional when using explicit configuration methods. When using environment variables, it's required and specifies the complete SharePoint site URL.
API Reference
SharePointClient
Main client class for SharePoint operations.
Methods
connect() -> bool
- Establish connection to SharePoint
- Returns:
Trueif successful
test_connection() -> bool
- Validate current connection
- Returns:
Trueif connection is valid
disconnect() -> None
- Clean up connection and resources
list_excel_files(library_name: str, folder_path: str) -> list[str]
- List Excel file names in specified location
- Args:
library_name(default: "Documents"),folder_path(e.g., "General/Reports") - Returns: List of Excel filenames
list_files(library: str, path: list[str]) -> list[FileInfo]
- List files with complete metadata
- Args:
libraryname,pathsegments - Returns: List of FileInfo objects with metadata
list_folders(library_name: str, folder_path: str) -> list[str]
- List folder names in specified location
- Returns: List of folder names
download_file(library: str, path: list[str], local_path: str) -> None
- Download single file
- Args:
libraryname,pathsegments including filename,local_path
download_files(library_name: str, folder_path: str, filenames: list[str], download_dir: str) -> dict
- Download multiple files with per-file error handling
- Returns: Dictionary with success/failure status for each file
get_file_details(library_name: str, folder_path: str, filename: str) -> FileInfo
- Get comprehensive file metadata
- Returns: FileInfo object with complete metadata
validate_paths(library_name: str) -> dict
- Validate configured SharePoint paths
- Returns: Validation results with error details and available folders
discover_structure(library_name: str, max_depth: int) -> dict
- Explore SharePoint library structure
- Returns: Hierarchical representation of folders and files
Configuration Functions
create_sharepoint_config(...) -> SharePointAuthConfig
- Create configuration with explicit parameters
create_config_from_dict(config_dict: dict) -> SharePointAuthConfig
- Create configuration from dictionary
create_authenticated_context(config: SharePointAuthConfig) -> ClientContext
- Create authenticated SharePoint context
Models
SharePointAuthConfig
- Configuration model with validation
- Fields:
username,password,sharepoint_url,timeout_seconds,max_file_size_mb
FileInfo
- File metadata model
- Fields:
name,size_bytes,size_mb,created_date,modified_date,file_type,library_name,folder_path,created_by,modified_by
FileType
- Enum for supported Excel extensions
- Values:
XLSX,XLS,XLSM,XLSB
Exceptions
All exceptions inherit from SharePointError:
AuthenticationError: Authentication failuresFederatedAuthError: Federated authentication issues (Azure AD specific)ConnectionError: Connection problemsFileNotFoundError: File not found in SharePointFileDownloadError: Download failuresFileSizeLimitError: File exceeds size limitConfigurationError: Invalid configurationPermissionError: Access deniedLibraryNotFoundError: Document library not foundInvalidFileTypeError: Unsupported file type
Security
- Passwords stored as
SecretStr(Pydantic) - Usernames masked in logs (first 3 characters only)
- Read-only operations only
- Configurable file size limits (default: 100MB)
- No environment dependencies by default
Error Handling
FetchPoint provides detailed error messages with context:
try:
with SharePointClient(config) as client:
files = client.list_excel_files("Documents", "NonExistent/Path")
except LibraryNotFoundError as e:
print(f"Library error: {e}")
print(f"Available folders: {e.available_folders}")
Development
For project developers working on the fetchpoint library:
Setup
# Install dependencies
uv sync --all-groups
# Build wheel package
uv build --wheel
Development Commands
Code Quality (run after every change):
# Format code
uv run ruff format src
# Lint with auto-fix
uv run ruff check --fix src
# Type checking
uv run pyright src
# Run tests
uv run pytest src -vv
# Run tests with coverage
uv run pytest src --cov=src --cov-report=term-missing
Complete validation workflow:
uv run ruff format src && uv run ruff check --fix src && uv run pyright src && uv run pytest src -vv
Testing
- Tests located in
__tests__/directories co-located with source code - Use pytest with extensions (pytest-asyncio, pytest-mock, pytest-cov)
- Minimum 90% coverage for critical components
Version Management
FetchPoint uses a single source of truth for version management:
- Version Source:
src/fetchpoint/__init__.pycontains__version__ = "x.y.z" - Dynamic Configuration:
pyproject.tomlreads version automatically from__init__.py - Publishing Workflow:
- Update version in
src/fetchpoint/__init__.py - Build:
uv build --wheel - Publish:
uv publish --token $PYPI_TOKEN
- Update version in
Update uv.lock via:
uv lock --refresh
Version Access:
import fetchpoint
print(fetchpoint.__version__) # e.g., "0.2.0"
Roadmap
- Download a single file by path
- Handle filetypes
License
Open source library for SharePoint Online integration.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fetchpoint-0.0.1.tar.gz.
File metadata
- Download URL: fetchpoint-0.0.1.tar.gz
- Upload date:
- Size: 105.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a137d5c35ce40a7f06bc70deaf4bd1147679f91efdab2668718134f6481643cf
|
|
| MD5 |
69aaffc11a96fe584767ce00c7fefb9d
|
|
| BLAKE2b-256 |
d43b66a8f1aca47653004124cc56417f38a12064d6d906ae524cf8082ff2ed93
|
File details
Details for the file fetchpoint-0.0.1-py3-none-any.whl.
File metadata
- Download URL: fetchpoint-0.0.1-py3-none-any.whl
- Upload date:
- Size: 34.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2a55f26975d5ab43b6307c74a46c18344a698b73aaa62a7d3a7fd227d254b2d
|
|
| MD5 |
68358cb12a26b1de3b37a6c4d08220fe
|
|
| BLAKE2b-256 |
713b4e2c48ccf089d7c7e06b02051ba7b6faddf0733b8efaf15798f004f210fa
|