Tool to manage MinIO connections and transfers.
Project description
SDP Tools
A Python toolkit for Scientific Data Platform operations, providing utilities for MinIO object storage and SURFdrive file transfers.
Features
MinIO File Management
- ๐ Multi-account configuration support (WO, HO, ML, VIZ)
- ๐ Upload and download files
- ๐ชฃ Bucket management and listing
- ๐ List and verify uploaded objects
- โก Environment-based credential management
SURFdrive Integration
- ๐ฅ Download CSV files from SURFdrive public shares
- ๐ HTTP Basic Authentication support
- ๐ Direct pandas DataFrame integration
- ๐ WebDAV protocol support
Installation
From PyPI (coming soon)
pip install sdp-tools
From source
# Clone the repository
git clone https://github.com/cedanl/sdp-tools
cd sdp-tools
# Install with uv (recommended)
uv pip install -e ".[dev,test]"
# Or with pip
pip install -e ".[dev,test]"
Quick Start
MinIO File Operations
The MinIO module supports multiple accounts through environment variable naming patterns.
Configuration
Set environment variables for your account (replace {ACCOUNT} with WO, HO, ML, or VIZ):
export MINIO_HO_ACCESS_KEY="your-access-key"
export MINIO_HO_SECRET_KEY="your-secret-key"
export MINIO_HO_ENDPOINT="https://minio.example.com"
export MINIO_HO_BUCKET="your-bucket-name"
Usage
from minio_file import minio_file
# Initialize client for specific account
ho = minio_file("HO")
# Upload a file
ho.upload_file("local_file.txt", "remote/path/file.txt")
# Download a file
ho.download_file("local_download.txt", "remote/path/file.txt")
# List all files in bucket
ho.get_file_list()
# Get all available buckets
buckets = ho.get_buckets()
for bucket in buckets:
print(bucket.name)
SURFdrive File Downloads
Download CSV files from SURFdrive public shares directly into pandas DataFrames.
Configuration
export SURFDRIVE_SHARE_TOKEN="your-share-token"
export SURFDRIVE_PASSWORD="your-password"
Usage
from surfdrive import download_surfdrive_csv
# Download CSV and get DataFrame
df = download_surfdrive_csv("data.csv")
if df is not None:
print(f"Downloaded {len(df)} rows")
print(df.head())
# Save locally if needed
df.to_csv("local_copy.csv", index=False)
Or use the CLI:
# Set environment variables first
export SURFDRIVE_SHARE_TOKEN="your-token"
export SURFDRIVE_PASSWORD="your-password"
# Download and save CSV
python -m surfdrive.surfdrive_download output.csv
Environment Variables
MinIO Configuration
Each account uses a prefix pattern: MINIO_{ACCOUNT}_*
| Variable Pattern | Required | Description | Accounts |
|---|---|---|---|
MINIO_{ACCOUNT}_ACCESS_KEY |
โ | MinIO access key | WO, HO, ML, VIZ |
MINIO_{ACCOUNT}_SECRET_KEY |
โ | MinIO secret key | WO, HO, ML, VIZ |
MINIO_{ACCOUNT}_ENDPOINT |
โ | MinIO endpoint URL | WO, HO, ML, VIZ |
MINIO_{ACCOUNT}_BUCKET |
โ | Target bucket name | WO, HO, ML, VIZ |
Example for HO account:
MINIO_HO_ACCESS_KEYMINIO_HO_SECRET_KEYMINIO_HO_ENDPOINTMINIO_HO_BUCKET
SURFdrive Configuration
| Variable | Required | Description |
|---|---|---|
SURFDRIVE_SHARE_TOKEN |
โ | Public share token from SURFdrive |
SURFDRIVE_PASSWORD |
โ | Password for the public share |
Development
Setup Development Environment
# Install development dependencies
make install-dev
# Or manually
uv pip install -e ".[dev,test]"
Running Tests
# Run all fast tests
make test-fast
# Run all tests including slow ones
make test
# Run with coverage
make test-coverage
# Run specific test file
pytest tests/test_surfdrive.py -v
Code Quality
# Format code
make format
# Run linters
make lint
# Run all checks (lint + tests)
make check
Building
# Build package
make build
# Build and verify
make build-check
Project Structure
sdp-tools/
โโโ src/
โ โโโ minio_file/ # MinIO operations module
โ โ โโโ __init__.py
โ โ โโโ minio_file.py
โ โโโ surfdrive/ # SURFdrive operations module
โ โโโ __init__.py
โ โโโ surfdrive_download.py
โโโ tests/ # Test suite
โ โโโ test_imports.py
โ โโโ test_functionality.py
โ โโโ test_surfdrive.py
โ โโโ test_and_build_distribution.py
โโโ docs/ # Documentation
โโโ pyproject.toml # Project configuration
โโโ Makefile # Development commands
โโโ README.md # This file
API Reference
MinIO Module (minio_file)
Class: minio_file(account)
Initialize a MinIO client for a specific account.
Parameters:
account(str): Account identifier. Must be one of: "WO", "HO", "ML", "VIZ"
Methods:
get_buckets()โ list: Retrieve all available bucketsupload_file(file_name, full_name): Upload a file to MinIOfile_name: Local file pathfull_name: Remote object path
download_file(file_name, full_name): Download a file from MinIOfile_name: Local destination pathfull_name: Remote object path
get_file_list(): Print all objects in the bucket
Example:
from minio_file import minio_file
# Initialize for ML account
ml = minio_file("ML")
# Upload
ml.upload_file("data.csv", "datasets/data.csv")
# Download
ml.download_file("local_data.csv", "datasets/data.csv")
SURFdrive Module (surfdrive)
Function: download_surfdrive_csv(filename)
Download a CSV file from SURFdrive public share.
Parameters:
filename(str): Name of the file to download (currently unused, downloads from configured share)
Returns:
pandas.DataFrameorNone: DataFrame with CSV data, or None if download fails
Environment Variables Required:
SURFDRIVE_SHARE_TOKENSURFDRIVE_PASSWORD
Example:
from surfdrive import download_surfdrive_csv
df = download_surfdrive_csv("data.csv")
if df is not None:
print(f"Shape: {df.shape}")
print(df.describe())
Troubleshooting
MinIO Issues
Invalid Account Error
Incorrect account {account}
Solution: Use only valid account names: "WO", "HO", "ML", or "VIZ"
Missing Environment Variables
Missing required environment variables
Solution: Set all required environment variables for your account (ACCESS_KEY, SECRET_KEY, ENDPOINT, BUCKET)
Connection Errors
Failed to connect to MinIO
Solution:
- Verify the
MINIO_{ACCOUNT}_ENDPOINTis correct and accessible - Check network connectivity
- Ensure MinIO server is running
SURFdrive Issues
Authentication Errors (401)
Error: 401
Solution:
- Verify
SURFDRIVE_SHARE_TOKENandSURFDRIVE_PASSWORDare correct - Check that the share is still active and accessible
File Not Found (404)
Error: 404
Solution:
- Verify the share URL is correct
- Check that the file exists in the shared folder
Network Timeout
Connection timeout
Solution:
- Check internet connectivity
- Verify SURFdrive service is accessible
- Try again later if service is experiencing issues
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Development Workflow
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Run tests:
make test - Run linters:
make lint - Commit your changes:
git commit -m "Description" - Push to your fork:
git push origin feature-name - Create a Pull Request
License
MIT License - see LICENSE file for details.
Deployment
Quick Start: 5-Minute Trusted Publisher Setup โก
For complete information on publishing to PyPI:
- Trusted Publisher Quick Start - Already uploaded? Start here!
- Complete Test PyPI Setup Guide - First time? Read this.
- Deployment Documentation - Overview and troubleshooting
Support
- Issues: https://github.com/cedanl/sdp-tools/issues
- Documentation: https://github.com/cedanl/sdp-tools/tree/main/docs
- Deployment: https://github.com/cedanl/sdp-tools/tree/main/docs/deployment
Version
Current version: 2025.1.6
See CHANGELOG.md for version history.
Project details
Release history Release notifications | RSS feed
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 sdp_tools-2025.1.7.tar.gz.
File metadata
- Download URL: sdp_tools-2025.1.7.tar.gz
- Upload date:
- Size: 152.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8fa5c3b5ced4922fb1bb718ea11ded782c98b898fc4dcab0d5f597f76ad22dc
|
|
| MD5 |
0ff0ae537db6aa6990686c0c9db6b726
|
|
| BLAKE2b-256 |
1deb44ee8a502d1940bfb71077d450601dbe087aadcfab3870a61744f4303617
|
File details
Details for the file sdp_tools-2025.1.7-py3-none-any.whl.
File metadata
- Download URL: sdp_tools-2025.1.7-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d2a45240a3617e87b87a1ca3890fe7beb427d5f731ddb321ab4b57c796c9630
|
|
| MD5 |
d1206189cca74174903bd1914ac6a771
|
|
| BLAKE2b-256 |
831f3e1f566c5b93c1484863f65e9c399bf46815f177b4f2c148e499c8a64739
|