Python SDK
The LabTrace Python SDK provides a comprehensive interface for integrating blockchain-powered file management into Python applications, data science workflows, and backend services.Installation
Install the SDK using pip:Quick Start
Authentication
Basic File Operations
Client Configuration
File Management
Upload Files
Download Files
List Files
Delete Files
Project Management
Get Projects
File Verification
Verify File Content
Error Handling
Exception Handling
Automatic Token Refresh
The SDK automatically handles JWT token expiration and refreshes tokens when needed:Advanced Features
Custom Request Headers
Bulk Operations
API Reference
Client Methods
Authentication
Client(username, password)- Initialize client with credentialsget_user_id()- Get current user ID from JWT token
Project Operations
get_projects(**filters)- Get all projects with optional filtersget_project(project_id)- Get specific project details
Public File Operations
upload_public_file(project_id, content, file_type, name, label, **kwargs)- Upload public fileget_public_project_files(project_id)- Get all public files in projectget_public_file(project_id, file_id, save_path)- Download public fileget_public_file_certificate(project_id, file_id, save_path, raw=False)- Download certificatedelete_public_file(project_id, file_id, user_id, reason)- Delete public file
Private File Operations
upload_private_file(project_id, content, file_type, name, label, **kwargs)- Upload private fileget_private_project_files(project_id)- Get all private files in projectget_private_file_certificate(project_id, file_id, save_path, raw=False)- Download certificatedelete_private_file(project_id, file_id, user_id, reason)- Delete private file
File Verification
verify_file_content(content, name)- Check if file already exists
Response Formats
All methods return Python dictionaries with the response data. The SDK automatically handles JSON parsing and error responses.Environment Variables
The SDK supports the following environment variables:LABTRACE_URL- API base URL (default: https://api.labtrace.io)LABTRACE_USERNAME- Default username for authenticationLABTRACE_PASSWORD- Default password for authentication
Best Practices
Security
- Store credentials securely (use environment variables or secure vaults)
- Use different accounts for different environments (dev/staging/prod)
- Regularly rotate passwords and update credentials
Performance
- Reuse client instances when possible
- Handle large files in chunks for better memory usage
- Use appropriate file types (primary vs secondary) for organization
Error Handling
- Always wrap SDK calls in try-catch blocks
- Check response status codes for specific error handling
- Implement retry logic for transient network errors
