Skip to main content

Memory-efficient DataFrame management - auto-offload to disk

Project description

SmartFrame 📊

Memory-Efficient DataFrame Management for Python

SmartFrame automatically manages RAM by keeping only the latest DataFrame in memory, offloading older ones to disk, and providing transparent access with auto-loading.

🎯 Problem

When working with large CSVs in Jupyter notebooks:

df = pd.read_csv('huge.csv')          # 10GB in RAM
df_filtered = df[df["col"]==1]        # +3GB (df still in RAM!)
df_grouped = df_filtered.groupby(...) # +500MB (all 3 in RAM!)
# Total: ~13.5GB sitting in RAM! 😱

✨ Solution

from smartframe import SmartFrame
import pandas as pd

sf = SmartFrame()

sf['raw'] = pd.read_csv('huge.csv')       # raw: 10GB in RAM
sf['filtered'] = sf['raw'].query('x > 0') # raw → disk, filtered: in RAM
sf['result'] = sf['filtered'].sum()       # filtered → disk, result: in RAM

# Access old data? Auto-loads from disk!
print(sf['raw'].head())

# See what's in RAM vs disk
sf.status()

# Cleanup when done
sf.cleanup()

📦 Installation

# From this directory
pip install -e .

# Or just copy the smartframe/ folder to your project

🚀 Quick Start

from smartframe import SmartFrame
import pandas as pd

# Create a SmartFrame (verbose=True shows what's happening)
sf = SmartFrame(verbose=True)

# Store DataFrames like a dict
sf['raw'] = pd.read_csv('data.csv')
sf['clean'] = sf['raw'].dropna()
sf['result'] = sf['clean'].groupby('category').sum()

# Check what's where
sf.status()
# Output:
# Name         Location   Size         Shape
# raw          💾 Disk    1.20 GB      (load to see)
# clean        💾 Disk    890.50 MB    (load to see)
# result       🟢 RAM     256 B        100 × 5

# Access any DataFrame - auto-loads if on disk
print(sf['raw'].head())

# Cleanup all temp files
sf.cleanup()

🔧 Features

Feature Description
Auto-offload Previous DataFrames automatically saved to disk
Lazy-load Old DataFrames loaded only when accessed
Transparent Works like a regular dict - sf['name'] = df
Fast storage Uses Parquet (compressed, columnar)
Status view sf.status() shows RAM vs disk usage
Easy cleanup sf.cleanup() removes all temp files
Pin important data sf.pin('name') keeps data in RAM

📖 API Reference

SmartFrame

SmartFrame(
    storage_dir=None,  # Custom temp directory (default: system temp)
    max_in_ram=1,      # Max DataFrames to keep in RAM
    verbose=False      # Print status messages
)

Methods:

  • sf['name'] = df - Store a DataFrame
  • sf['name'] - Get a DataFrame (auto-loads from disk)
  • del sf['name'] - Delete a DataFrame
  • sf.status() - Show RAM vs disk status
  • sf.pin('name') - Keep a DataFrame in RAM permanently
  • sf.unpin('name') - Allow a pinned DataFrame to be offloaded
  • sf.cleanup() - Delete all temp files
  • sf.keys() - List all DataFrame names

🧪 Running Tests

python -m pytest tests/
# or
python tests/test_smartframe.py

📁 Project Structure

smartframe/
├── __init__.py     # Package exports
├── core.py         # Main SmartFrame class
├── storage.py      # Disk storage backend
└── utils.py        # Utility functions

examples/
└── example_usage.py  # Demo script

tests/
└── test_smartframe.py  # Unit tests

📝 License

MIT License

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

smartframe_df-0.1.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

smartframe_df-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file smartframe_df-0.1.0.tar.gz.

File metadata

  • Download URL: smartframe_df-0.1.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.4

File hashes

Hashes for smartframe_df-0.1.0.tar.gz
Algorithm Hash digest
SHA256 49e35394e2be227e9e9af1fcb4b00220bf351d55bd6ce1cd6790df90f49fe32f
MD5 03cda494b5ba7e7f3dc2d50a5d9f603a
BLAKE2b-256 b46ca4ac65190485c6754d4546749e0ad652df51c842112b64b96f6831799e2a

See more details on using hashes here.

File details

Details for the file smartframe_df-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: smartframe_df-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.4

File hashes

Hashes for smartframe_df-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ecffc27826aa6953caa10b4eca87bcfcc54a31386852555194dc51a007441b83
MD5 f5d60411795bef7c7bbba5ed26946162
BLAKE2b-256 beafac9576f6651ac4313c736ea14aee69a01171b3a86391d9f6ee34702b89fb

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