Skip to main content

A Python package for managing storage

Project description

storage-bridge

A Python library providing a typeclass-based abstraction for managing diverse storage backends. Storage Manager simplifies and standardizes interactions with storage systems, enabling seamless access to local files, in-memory storage, and cloud-based resources.

Key Features Unified Interface: Interact with various storage backends using a consistent API. Extensible Framework: Add custom storage backends with minimal implementation effort. Mock-Friendly: Built-in support for testing with mock storage or local solutions. Batch and Transactional Support: Perform bulk operations or enable transactional workflows. Why Use Storage Manager? Modern applications often require integration with multiple storage systems—local, remote, or in-memory. Storage Manager homogenizes these interactions, letting developers focus on application logic rather than backend differences.

Installation

Install via pip:

pip install storage-bridge

Usage

Core API

The Storage typeclass provides the core methods:

save(key, value): Save a value under a key. load(key): Retrieve a value by key. delete(key): Remove a key-value pair. list_keys(): List all keys in the storage. Additional methods like exists, update, save_batch, and backup are derived from these core methods.

Example: File-Based Storage

from storage_bridge.implementation import FileStorage

# Create a file-based storage backend
store = FileStorage(filepath='data.json')

# Save and load data
store.save('user', {'name': 'Alice', 'age': 30})
print(store.load('user'))  # Output: {'name': 'Alice', 'age': 30}

# List keys
print(store.list_keys())  # Output: ['user']

# Delete data
store.delete('user')

Example: In-Memory Storage

from storage_bridge.implementation import MemoryStorage

# Create an in-memory storage backend
memory_store = MemoryStorage()

# Save and retrieve data
memory_store.save('session', {'token': 'abc123'})
print(memory_store.load('session'))  # Output: {'token': 'abc123'}

Testing with Mock Storage

from storage_bridge.implementation import MemoryStorage

def test_storage():
    mock_store = MemoryStorage()
    mock_store.save('test_key', 'test_value')
    assert mock_store.load('test_key') == 'test_value'
    assert 'test_key' in mock_store.list_keys()
    mock_store.delete('test_key')

Extending Storage Manager

To create a custom storage backend, subclass Storage and implement the core methods (save, load, delete, list_keys).

Example: Custom Storage

from storage_bridge.typeclass import Storage

class CustomStorage(Storage):
    def __init__(self):
        self.data = {}

    def save(self, key, value):
        self.data[key] = value

    def load(self, key):
        if key not in self.data:
            raise KeyError(f"Key '{key}' not found.")
        return self.data[key]

    def delete(self, key):
        if key in self.data:
            del self.data[key]
        else:
            raise KeyError(f"Key '{key}' not found.")

    def list_keys(self):
        return list(self.data.keys())

Roadmap

Add cloud storage integrations (AWS S3, Google Cloud Storage, Azure Blob Storage). Introduce advanced features like data versioning and compression. Expand support for transactional and distributed workflows.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your changes.

License

storage-bridge is licensed under the MIT License. See LICENSE for more details.

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

storage_bridge-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

storage_bridge-0.1.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file storage_bridge-0.1.1.tar.gz.

File metadata

  • Download URL: storage_bridge-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for storage_bridge-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dd1c3c10198a130e7bb782516c1a8d87e5c190dbf36475f05dba9baa337d27c0
MD5 db1d71fad6bd467f1a03f7017b847b6d
BLAKE2b-256 97b958efb39cc8bcd5c703e765848edeab93ac61a88838788f5eb3599f9c8926

See more details on using hashes here.

File details

Details for the file storage_bridge-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: storage_bridge-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for storage_bridge-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 54c84e0b2e4513bfdaf49da73a9061a6ebfa9d3c7f29fd7ebcf6645e70e65d81
MD5 61c0d6861c6df1c82e19e1b3dd5527d7
BLAKE2b-256 6cce57995afb1f58a1eae3d7d51931f6265991a15d5fbe27359702de82fa0570

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