Skip to main content

SimpleDiskDB

A MongoDB-style disk-based database implementation for Python applications. SimpleDiskDB provides a familiar MongoDB-like interface while storing data locally on disk using the diskcache package.

Features

  • MongoDB-like document storage and querying
  • Thread-safe operations
  • Rich query language supporting $and, $or, $gt, $exists, $nin operators
  • Flexible document schema within collections
  • Sorting and pagination support
  • Projection support to retrieve specific fields
  • Data persistence across application restarts

Use Cases

  • Distributed applications that require a database but don't want to deal with the complexity of a full database system. [Application uses network disk for storage, hence distribution comes for free]
  • Serverless, Zero-configuration, Zero-dependency applications that require a database.
  • CI/CD scripts that require containers to store the persistent data.

Installation

# Install the package
pip install simplediskdb

# Load example data (either method works)
simplediskdb example load
# or
python -m simplediskdb example load

# Delete example data (either method works)
simplediskdb example delete
# or
python -m simplediskdb example delete

# Show available commands
simplediskdb --help
# or
python -m simplediskdb --help

Usage

from simplediskdb import DiskDB

# Get a database instance
db = DiskDB()

# Create collections
tasks = db.add_collection('tasks')
users = db.add_collection('users')

# Insert documents
tasks.insert_one({
    "task_id": "T123",
    "status": "pending",
    "priority": 1,
    "assigned_to": "john",
    "files": ["doc1.pdf", "doc2.txt"]
})

# Bulk insert
users.insert_many([
    {"name": "John", "role": "admin"},
    {"name": "Jane", "role": "user"}
])

# Complex query with AND, OR, and comparison operators
results = tasks.find(
    conditions={
        "$and": [
            {"status": "pending"},
            {"$or": [
                {"priority": {"$gt": 0}},
                {"priority": 0}
            ]},
            {"files": {"$exists": True}}
        ]
    },
    sort=[("priority", -1)],
    limit=10
)

# Print results
for doc in results:
    print(doc)

Web Viewer Interface

SimpleDiskDB comes with a built-in web viewer that allows you to browse, query, and manage your database collections through a user-friendly interface.

Starting the Viewer

# Start the viewer on default host (127.0.0.1) and port (5000)
simplediskdb viewer
or
python -m simplediskdb viewer

# Start on a specific host and port
simplediskdb viewer --host 0.0.0.0 --port 8000
or
python -m simplediskdb viewer --host 0.0.0.0 --port 8000

Features

Home Page

Home Page

  • Lists all available collections in your database
  • Shows document count for each collection
  • Quick links to view or query collections

View Documents

View Documents

  • Browse all documents in a collection
  • Documents are displayed in a paginated table
  • JSON view for better readability
  • Copy document content to clipboard

Query Interface

Query Interface

  • Write and execute MongoDB-style queries
  • Support for complex queries using operators ($and, $or, $gt, etc.)
  • Query results shown in real-time
  • Export query results

Delete Documents

Delete Interface

  • Delete documents matching specific query conditions
  • Important Security Note: The default delete secret key is simplediskdb. For production use, you should change this by setting the DELETE_SECRET_KEY environment variable:
    # Windows
    set DELETE_SECRET_KEY=your-secure-key
    
    # Linux/Mac
    export DELETE_SECRET_KEY=your-secure-key
    
  • Confirmation required before deletion
  • Shows count of matching documents before deletion

TODO

  • Add support for more operators ($regex.)
  • Time To Live (TTL) support
  • Indexing support

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

We love your input! We want to make contributing to SimpleDiskDB as easy and transparent as possible, whether it's:

  • Reporting a bug
  • Discussing the current state of the code
  • Submitting a fix
  • Proposing new features
  • Becoming a maintainer

Development Process

  1. Fork the repo https://github.com/anandan-bs/simplediskdb
  2. Clone your fork (git clone https://github.com/anandan-bs/simplediskdb.git)
  3. Create your feature branch (git checkout -b feature/amazing-feature)
  4. Make your changes
  5. Run the tests to ensure nothing is broken
  6. Commit your changes (git commit -m 'Add some amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Pull Request Process

  1. Update the README.md with details of changes if needed
  2. Update the example data or tests if your changes require it
  3. Make sure your code follows the existing style
  4. Include comments in your code where necessary

Any Questions?

Feel free to file an issue on the repository or contact the maintainer:

License

By contributing, you agree that your contributions will be licensed under its MIT License.

Acknowledgments

SimpleDiskDB is built on top of the excellent diskcache package, which provides the core storage functionality. Some key performance highlights from diskcache:

  • Faster than other disk-based cache implementations like SQLite and LevelDB
  • Sequential operations run at ~300 microseconds
  • Bulk operations run at ~100 microseconds per operation
  • Performance is stable with database size due to O(1) record operations

For detailed performance benchmarks and comparisons with other storage solutions, please refer to the diskcache documentation.

Metadata

Release files for simplediskdb 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simplediskdb 1.0.0
File Size Uploaded
simplediskdb-1.0.0.tar.gz 21.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simplediskdb 1.0.0
File Interpreter ABI Platform
simplediskdb-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 44.9 kB

Release files / simplediskdb-1.0.0.tar.gz

Download URL simplediskdb-1.0.0.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e0783edfb6f0574adbc2fc11233578a306b7ffa73dd95bec0e68564ac7ecb1ad
BLAKE2b-256 checksum
How to use checksums
e3c2cf53f1b442a84ac9401e879f9e2a8b85f8dbeae25843e4e61f253e5b5079
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 30, 2025.

Transparency log

Release files / simplediskdb-1.0.0-py3-none-any.whl

Download URL simplediskdb-1.0.0-py3-none-any.whl
Size 23.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ba717b921925ab6e05a404f198d87f57a22e7448d1d8b671d3d91b8efb19f4a
BLAKE2b-256 checksum
How to use checksums
cdf16e9638dea4d65d0ed429ce78e7ee2ba2d91516e81728efe0f663c6f3b908
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 30, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page