Skip to main content

Data storage library for asset model apps

Project description

Leia em português

Storage Abstraction System

This module provides a flexible storage abstraction that allows the B3 model system to save files to either local file system or AWS S3 based on environment configuration.

Overview

The storage system automatically determines where to save files based on the enviroment environment variable:

  • enviroment=AWS: Files are saved to AWS S3
  • enviroment=SYSTEM or unset: Files are saved to local file system

Architecture

Core Components

  1. DataStorageHandler (Abstract Base Class)

    • Defines the interface for all storage implementations
    • Provides common functionality like path normalization
  2. DataStorageService (Factory/Coordinator)

    • Determines which storage backend to use based on environment
    • Provides a unified interface for the rest of the application
  3. S3DataStorageService (S3 Implementation)

    • Handles file operations with AWS S3
    • Requires AWS credentials and S3 bucket configuration
  4. SystemDataStorageService (Local Implementation)

    • Handles file operations with local file system
    • Default behavior when not using S3

Usage

Basic Usage

from asset_model_data_storage.data_storage_service import DataStorageService

# Initialize storage service (automatically detects environment)
storage_service = DataStorageService()

# Save a file
data = b"Hello, World!"
saved_path = storage_service.save_file("test/file.txt", data, "text/plain")

# Load a file
loaded_data = storage_service.load_file("test/file.txt")

# Check if file exists
exists = storage_service.file_exists("test/file.txt")

# Delete a file
deleted = storage_service.delete_file("test/file.txt")

With Model System

from b3.service.model.model import B3Model

# Model automatically uses the configured storage
model = B3Model()

# Training will save model and plots to the appropriate storage
model.train()

Environment Configuration

For S3 Storage

Set these environment variables:

export enviroment=AWS
export S3_BUCKET_NAME=your-bucket-name
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key
export AWS_REGION=us-east-1  # Optional, defaults to us-east-1

For Local Storage

export enviroment=SYSTEM
# or leave enviroment unset

File Types Supported

The system supports various file types with appropriate MIME type detection:

  • Images: PNG, JPEG, GIF
  • Models: Joblib, Pickle files
  • Data: CSV, JSON, TXT
  • Documents: PDF
  • Generic: Binary files

Integration Points

The storage system is designed to be integrated into any application that needs to abstract file storage, such as model saving, plot generation, or evaluation result storage. You can use the DataStorageService directly in your codebase.

  1. Model Saving Service (model_saving_service.py)

    • Saves trained models using the configured storage
  2. Plotter (plotter.py)

    • Saves generated plots using the configured storage
  3. Model Evaluation Service (model_evaluation_service.py)

    • Saves evaluation visualizations using the configured storage

Error Handling

The system includes comprehensive error handling:

  • S3 Errors: Handles AWS credential issues, bucket access, and network problems
  • Local Storage Errors: Handles file system permissions and disk space issues
  • File Not Found: Consistent error handling across storage types

This will demonstrate the storage system with your current environment configuration.

Dependencies

For S3 Storage

  • boto3: AWS SDK for Python
  • botocore: Low-level AWS service client library (required by boto3)
  • AWS credentials configured (via environment variables, AWS CLI, or IAM roles)

For Local Storage

  • No additional dependencies beyond standard Python libraries

Migration Notes

The storage system is backward compatible. Existing code will continue to work with local storage by default. To enable S3 storage, simply set the enviroment=AWS environment variable and configure AWS credentials.

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

asset_model_data_storage-1.0.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

asset_model_data_storage-1.0.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file asset_model_data_storage-1.0.1.tar.gz.

File metadata

  • Download URL: asset_model_data_storage-1.0.1.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for asset_model_data_storage-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6a52aba9e01d0b0414f09d48eeef20d3650d8d73500018d72a3c77abb2f24013
MD5 9c536b2f408139116bdec3697d85e316
BLAKE2b-256 c85eeef09c73fb72df9b1aa18d048a1a79d4a1f1ef146d467ae284b514f323e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for asset_model_data_storage-1.0.1.tar.gz:

Publisher: python-publish.yml on ManoelSilva/asset-model-data-storage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asset_model_data_storage-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for asset_model_data_storage-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53cb13ebb4826a850d93224b82b414cdcc64f78db6780f79df5121cf8f31a5b1
MD5 4232660325a76ba3fe40a49e7c7e86f6
BLAKE2b-256 c9c0f8389c7207ef6302978ee204af34e093ccdacf41f77625e66446b13dc3c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for asset_model_data_storage-1.0.1-py3-none-any.whl:

Publisher: python-publish.yml on ManoelSilva/asset-model-data-storage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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