Skip to main content

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_KEY
  • MINIO_HO_SECRET_KEY
  • MINIO_HO_ENDPOINT
  • MINIO_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 buckets
  • upload_file(file_name, full_name): Upload a file to MinIO
    • file_name: Local file path
    • full_name: Remote object path
  • download_file(file_name, full_name): Download a file from MinIO
    • file_name: Local destination path
    • full_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.DataFrame or None: DataFrame with CSV data, or None if download fails

Environment Variables Required:

  • SURFDRIVE_SHARE_TOKEN
  • SURFDRIVE_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}_ENDPOINT is correct and accessible
  • Check network connectivity
  • Ensure MinIO server is running

SURFdrive Issues

Authentication Errors (401)

Error: 401

Solution:

  • Verify SURFDRIVE_SHARE_TOKEN and SURFDRIVE_PASSWORD are 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

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes
  4. Run tests: make test
  5. Run linters: make lint
  6. Commit your changes: git commit -m "Description"
  7. Push to your fork: git push origin feature-name
  8. 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:

Support

Version

Current version: 2025.1.6

See CHANGELOG.md for version history.

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

sdp_tools-2025.1.7.tar.gz (152.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sdp_tools-2025.1.7-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

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

Hashes for sdp_tools-2025.1.7.tar.gz
Algorithm Hash digest
SHA256 a8fa5c3b5ced4922fb1bb718ea11ded782c98b898fc4dcab0d5f597f76ad22dc
MD5 0ff0ae537db6aa6990686c0c9db6b726
BLAKE2b-256 1deb44ee8a502d1940bfb71077d450601dbe087aadcfab3870a61744f4303617

See more details on using hashes here.

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

Hashes for sdp_tools-2025.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0d2a45240a3617e87b87a1ca3890fe7beb427d5f731ddb321ab4b57c796c9630
MD5 d1206189cca74174903bd1914ac6a771
BLAKE2b-256 831f3e1f566c5b93c1484863f65e9c399bf46815f177b4f2c148e499c8a64739

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page