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.2.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.2-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asset_model_data_storage-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 88e1807db634f1370e577c0763ca4b9af5a70c16cd50d6fdc7546dad7c4326f2
MD5 6b578bd9c9bbe46378ca78184a6a431c
BLAKE2b-256 238ef23886336de5608aad0e20907ee03952f1a9172aeb2debc8b3355afae253

See more details on using hashes here.

Provenance

The following attestation bundles were made for asset_model_data_storage-1.0.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for asset_model_data_storage-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3eaa4ef221692ff8b01632db8572330725113e10f8550bdf5dbc9ddf461dd752
MD5 cb71414a253bbe929ecc043850567480
BLAKE2b-256 5cb275b60036299285407635a46d4c70a354326627136e2e33f27b911d5346d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for asset_model_data_storage-1.0.2-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