Cloud Shelve
Cloud Shelve (cshelve
)
Section titled βCloud Shelve (cshelve)βCShelve is a Python package that lets you store and retrieve Python objectsβlists, DataFrames, JSON, binary filesβacross local files, cloud storage (AWS S3, Azure Blob), or on-premise via SFTP, all with the same easy dictionary-like interface.
If you know how to use:
mydict['key'] = value
you already know how to use CShelve. No database servers. No complex setup. Just install, configure, and start saving.
We welcome your feedback and contributions! β Star the project on GitHub to support development.
π Installation
Section titled βπ Installationβ# Local storage onlypip install cshelve
# With Azure Blob supportpip install cshelve[azure-blob]
# With AWS S3 supportpip install cshelve[aws-s3]
# With SFTP support (on-premise or self-hosted)pip install cshelve[sftp]
π Local Usage
Section titled βπ Local UsageβUsing CShelve locally is just like Pythonβs built-in shelve
:
import cshelve
db = cshelve.open('local.db') # Create or open a local storage file
db['key'] = 'data' # Storeprint(db['key']) # Retrievedel db['key'] # Delete
print('key' in db) # Check if a key existsprint(list(db.keys())) # List all keys (may be slow for huge datasets)
# Example with mutable objects (without writeback=True)db['numbers'] = [0, 1, 2]temp = db['numbers']temp.append(3)db['numbers'] = temp # Re-store to persist changes
db.close()
π Tip: For more details on how
shelve
works under the hood, see the official Python documentation.
β Cloud Storage Example β Azure Blob
Section titled ββ Cloud Storage Example β Azure Blobβ1οΈβ£ Install provider
pip install cshelve[azure-blob]
2οΈβ£ Create azure-blob.ini
[default]provider = azure-blobaccount_url = https://myaccount.blob.core.windows.netauth_type = passwordlesscontainer_name = mycontainer
3οΈβ£ Use in Python
import cshelve
db = cshelve.open('azure-blob.ini')db['message'] = 'Hello from Azure!'print(db['message'])db.close()
β Cloud Storage Example β AWS S3
Section titled ββ Cloud Storage Example β AWS S3β1οΈβ£ Install provider
pip install cshelve[aws-s3]
2οΈβ£ Create aws-s3.ini
[default]provider = aws-s3bucket_name = mybucketauth_type = access_keykey_id = $AWS_KEY_IDkey_secret = $AWS_KEY_SECRET
3οΈβ£ Set environment variables
export AWS_KEY_ID=your_access_key_idexport AWS_KEY_SECRET=your_secret_access_key
4οΈβ£ Use in Python
import cshelve
db = cshelve.open('aws-s3.ini')db['cloud_key'] = 'Stored in S3!'print(db['cloud_key'])db.close()
π₯ On-Premise / Private Hosting Example β SFTP
Section titled βπ₯ On-Premise / Private Hosting Example β SFTPβ1οΈβ£ Install provider
pip install cshelve[sftp]
2οΈβ£ Create sftp.ini
[default]provider = sftphostname = $SFTP_PASSWORD_HOSTNAMEusername = $SFTP_USERNAMEpassword = $SFTP_PASSWORDauth_type = password
[provider_params]remote_path = myuser
3οΈβ£ Set environment variables
export SFTP_PASSWORD_HOSTNAME=your-sftp-hostexport SFTP_USERNAME=your-usernameexport SFTP_PASSWORD=your-password
4οΈβ£ Use in Python
import cshelve
db = cshelve.open('sftp.ini')db['local_backup'] = 'Stored via SFTP on-prem'print(db['local_backup'])db.close()
π Why Use CShelve?
Section titled βπ Why Use CShelve?β- Familiar β Works like a Python dictionary.
- Cloud-Ready β Switch between local and cloud storage without code changes.
- On-Prem Capable β Use SFTP for private or internal storage.
- Lightweight β No servers or SQL required.
- Flexible β Store any picklable object or raw bytes (JSON, CSV, images, etc.).
- Scalable β Leverage cloud or on-prem solutions for affordable, persistent storage.