Skip to main content

PyNoSQLSB is a lightweight, JSON-based NoSQL database written in Python

Project description

Absolutely! Here’s a full, detailed README for your PyNoSQL library, including installation, usage, JSON operations, indexing, compaction, and contribution instructions. I’ve structured it like a professional open-source project README.


PyNoSQL

PyNoSQL is a lightweight, JSON-based NoSQL database written in Python. It is designed for developers to learn, experiment, and practice NoSQL database concepts. PyNoSQL provides support for collections, indexes, write-ahead logging (WAL), compaction, and basic CRUD operations.


Features

  • Collections: Organize data into collections (similar to MongoDB).
  • Documents: Store JSON-compatible Python dictionaries.
  • Indexes: Create B-tree indexes on fields for faster queries.
  • Write-Ahead Logging (WAL): Ensures durability and crash recovery.
  • Compaction: Remove stale records and tombstones to optimize storage.
  • Querying: Find, update, and delete documents using JSON-like queries.
  • Simple API: Lightweight and easy-to-use interface for experimentation.
  • Fully in Python: No external database required.

Installation

git clone https://github.com/yourusername/pynosqldb.git
cd pynosqldb
python -m pip install -e .

The -e flag installs the library in editable mode, so you can modify it during development.

PyNoSQL requires Python 3.11+ and the msgpack library:

pip install msgpack

Usage

1. Creating or Opening a Database

from pynosql.database import Database

# Create a database
db = Database("mydb")
db.open()

2. Working with Collections

# Access or create a collection
users = db.collection("users")

3. Inserting Documents

a) Using Python dictionaries

user = {"name": "Alice", "age": 30, "email": "alice@example.com"}
user_id = users.insert(user)
print(f"Inserted document with _id: {user_id}")

b) From JSON string

import json

json_str = '{"name": "Bob", "age": 25, "email": "bob@example.com"}'
user = json.loads(json_str)
users.insert(user)

c) From JSON file

with open("users.json", "r") as f:
    data = json.load(f)

if isinstance(data, list):
    for user in data:
        users.insert(user)
else:
    users.insert(data)

4. Querying Documents

# Find all users older than 25
results = users.find({"age": 30})
for user in results:
    print(user)

5. Updating Documents

# Update documents matching a query
users.update({"name": "Alice"}, {"$set": {"age": 31}})

6. Deleting Documents

# Delete documents matching a query
users.delete({"name": "Bob"})

7. Index Management

# Create an index on the "age" field
db.create_index("users", "age")

# Indexed queries are faster
results = users.find({"age": 30})

8. Compaction

Over time, updates and deletions leave stale data and tombstones. Use compaction to optimize storage:

db.compact()

This copies only the latest version of each document into a new DB file and removes deleted records.


9. Closing the Database

Always close the database to flush data and indexes:

db.close()

Directory Structure

pynosqldb/
│
├── pynosql/
│   ├── __init__.py
│   ├── database.py
│   ├── collection.py
│   ├── storage/
│   │   ├── engine.py
│   │   ├── wal.py
│   │   ├── compaction.py
│   │   └── metadata.py
│   ├── query/
│   │   ├── matcher.py
│   ├── update/
│   │   ├── updater.py
│   ├── index/
│   │   ├── btree.py
│   │   ├── index_manager.py
│   ├── cli.py
│   ├── util.py
│   └── errors.py
│
├── tests/
├── setup.py
├── pyproject.toml
├── README.md
├── LICENSE
└── example.ipynb

License

MIT License. See LICENSE file for details.


This README now includes JSON insertion, updates, queries, deletion, indexing, compaction, and a clear example workflow.


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

pynosqldb-1.0.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

pynosqldb-1.0.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file pynosqldb-1.0.0.tar.gz.

File metadata

  • Download URL: pynosqldb-1.0.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for pynosqldb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 20dc590c1a03e1b0987c7edc43eae445e3209aadeea15b93a9b58b50b8450118
MD5 1bb6186d78314a274fa822d8815a7b89
BLAKE2b-256 b6100b819d93e7bc8f40af03e6f7bc0e86f75ec772e6374eb4371caa579e6f0c

See more details on using hashes here.

File details

Details for the file pynosqldb-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pynosqldb-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for pynosqldb-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc7fda8b2a88add45bdde9a29249cfe7ff40fc24400b9a2ef44da04a83d33fcf
MD5 7fe664aec85da4d2dd5994904c66e28e
BLAKE2b-256 fd01a6deb18607917d804d20d63c852a3587876263c8df3521e15e54463dab59

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