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 DataFramesf['name']- Get a DataFrame (auto-loads from disk)del sf['name']- Delete a DataFramesf.status()- Show RAM vs disk statussf.pin('name')- Keep a DataFrame in RAM permanentlysf.unpin('name')- Allow a pinned DataFrame to be offloadedsf.cleanup()- Delete all temp filessf.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49e35394e2be227e9e9af1fcb4b00220bf351d55bd6ce1cd6790df90f49fe32f
|
|
| MD5 |
03cda494b5ba7e7f3dc2d50a5d9f603a
|
|
| BLAKE2b-256 |
b46ca4ac65190485c6754d4546749e0ad652df51c842112b64b96f6831799e2a
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecffc27826aa6953caa10b4eca87bcfcc54a31386852555194dc51a007441b83
|
|
| MD5 |
f5d60411795bef7c7bbba5ed26946162
|
|
| BLAKE2b-256 |
beafac9576f6651ac4313c736ea14aee69a01171b3a86391d9f6ee34702b89fb
|