Skip to main content

No project description provided

Project description

MemStore

MemStore is a lightweight in-memory database written in Python. It supports key-value storage with integer IDs, single-field indexing, and filtering by field values. It uses dictionaries for data storage and retrieval.


Installation

Since MemStore is a single-class implementation, you can simply include it in your project. No external package installation is required. Alternatively, if packaged:

pip install memstore

Usage Examples

1. Initialize the Database

Create a database with optional indexes:

from memstore import MemStore

# Initialize with indexes on 'name' and 'age'
db = MemStore(indexes=['name', 'age'])

2. Insert Records

Add a single record and get its ID:

# Insert a single record
record_id = db.add({'name': 'Alice', 'age': 25, 'city': 'New York'})
print(f"Inserted record with ID: {record_id}")  # Output: Inserted record with ID: 0

3. Query Records

Retrieve records by ID or filter by field values:

# Get by ID
record = db.get(0)
print(record)  # Output: {'name': 'Alice', 'age': 25, 'city': 'New York'}

# Filter by indexed field
alice_records = db.filter({'name': 'Alice'})
print(alice_records)  # Output: [(0, {'name': 'Alice', 'age': 25, 'city': 'New York'})]

# Filter by non-indexed field
ny_records = db.filter({'city': 'New York'})
print(ny_records)  # Output: [(0, {'name': 'Alice', 'age': 25, 'city': 'New York'})]

# Filter with multiple conditions (mixed indexed and non-indexed)
alice_25_records = db.filter({'name': 'Alice', 'age': 25})
print(alice_25_records)  # Output: [(0, {'name': 'Alice', 'age': 25, 'city': 'New York'})]

4. List All Records

Retrieve all records in the database:

db.add({'name': 'Bob', 'age': 30, 'city': 'Boston'})
all_records = db.all()
for record_id, record in all_records:
    print(f"ID {record_id}: {record}")
# Output:
# ID 0: {'name': 'Alice', 'age': 25, 'city': 'New York'}
# ID 1: {'name': 'Bob', 'age': 30, 'city': 'Boston'}

5. Delete Records

Remove a record by ID:

success = db.delete(0)
print(f"Delete successful: {success}")  # Output: Delete successful: True
print(db.all())  # Output: [(1, {'name': 'Bob', 'age': 30, 'city': 'Boston'})]

6. Manage Indexes

Add or remove indexes dynamically:

# Add a new index
db.add_index('city')
print(db.filter({'city': 'Boston'}))  # Output: [(1, {'name': 'Bob', 'age': 30, 'city': 'Boston'})]

# Drop an index
db.drop_index('name')
print('name' in db._indexes)  # Output: False

Notes

  • Data Structure: Records are stored as dictionaries with integer IDs assigned sequentially.
  • Indexes: Only single-field indexes are supported (e.g., 'name'). Composite indexes are not available.
  • Filtering: The filter method retrieves records matching all specified field-value pairs, using indexes when available for efficiency. It works with both indexed and non-indexed fields.
  • Limitations: No field validation or update methods are provided. Deletion and retrieval are ID-based or filter-based only.
  • Dependencies: Uses only Python standard library modules (collections, functools, itertools, operator, typing).

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

memstore-0.2.3.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

memstore-0.2.3.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file memstore-0.2.3.1.tar.gz.

File metadata

  • Download URL: memstore-0.2.3.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.12 Linux/6.8.0-55-generic

File hashes

Hashes for memstore-0.2.3.1.tar.gz
Algorithm Hash digest
SHA256 7800e556a22e77a5307e6c141207b70dbc6f20b9fbf4db8fcbc198e59fe25c56
MD5 429d31856b03778b1a4de8ca516004fb
BLAKE2b-256 a9b063ac5390dc1c882a5d5048846a0d9b07365f7c7e56edc62924cdf52c5c72

See more details on using hashes here.

File details

Details for the file memstore-0.2.3.1-py3-none-any.whl.

File metadata

  • Download URL: memstore-0.2.3.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.12 Linux/6.8.0-55-generic

File hashes

Hashes for memstore-0.2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 67b820a7b600e930fa415f6aa16b102cafa74f3ff1c9cd66f0c2c1b09b9833d3
MD5 7e3b37c274349a310da2326cdda55eaf
BLAKE2b-256 2cdbde299ff4807926e1664287d44d5f4d393ba6fbf64a149468ed175eaf5141

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