Skip to main content

A document store for Pydantic models

Project description

Nondb

A simple, filesystem-based document store for Pydantic-modeled JSON data.

Purpose

Nondb is a lightweight document database that uses the filesystem for storage and Pydantic models for data validation and serialization. It provides a simple interface for storing, retrieving, and querying JSON documents while leveraging Pydantic's powerful data validation capabilities.

Perfect for:

  • Small to medium-sized applications that need structured data storage
  • Prototypes and development environments
  • Applications that benefit from human-readable, file-based data storage

Features

  • Pydantic Integration: Automatic JSON serialization/deserialization using Pydantic models
  • Type Safety: Full type checking and validation through Pydantic
  • Filesystem Storage: Human-readable JSON files organized in directories
  • Flexible Keys: Customizable key expressions using JMESPath syntax
  • Secondary Indexing: Create indices on any field for fast lookups
  • Multiple Tables: Support for multiple data models in a single database
  • Simple API: Intuitive interface for CRUD operations

Installation

pip install nondb

Or install from source:

git clone https://github.com/slank/nondb.git
cd nondb
pip install -e .

Usage Examples

Basic Usage

from pydantic import BaseModel
from nondb import NoDB

# Define your data model
class User(BaseModel):
    id: int
    name: str
    email: str
    age: int

# Initialize database
db = NoDB("./my_database")

# Get a table for your model
users = db.table(User, key_expr="id")

# Create and save records
user = User(id=1, name="Alice Smith", email="alice@example.com", age=30)
users.save(user)

# Fetch records
retrieved_user = users.fetch("1")
print(retrieved_user.name)  # Alice Smith

# Get all records
all_users = users.all()

Secondary Indexing

# Create indices (best to do this before adding records)
age_index = users.index("age")

# Add some users (index will be automatically updated)
users.save(User(id=1, name="Alice", email="alice@example.com", age=30))
users.save(User(id=2, name="Bob", email="bob@example.com", age=25))
users.save(User(id=3, name="Carol", email="carol@example.com", age=30))

# Find all users of a specific age
thirty_year_olds = age_index.get("30")

# If you create an index after records exist, rebuild it:
# age_index.rebuild_index()

Contributing Tips

We welcome contributions! Here's how to get started:

Development Setup

  1. Clone the repository:

    git clone https://github.com/slank/nondb.git
    cd nondb
    
  2. Install development dependencies:

    pip install -e ".[dev]"
    
  3. Run tests:

    python -m unittest discover tests/ -v
    

Code Style

  • We use Black for code formatting
  • Type hints are required for all public APIs
  • Follow PEP 8 naming conventions
  • Write docstrings for all public methods

Testing

  • Add tests for all new features
  • Maintain test coverage above 90%
  • Tests are located in the tests/ directory
  • Use descriptive test names and docstrings

Submitting Changes

  1. Create a feature branch:

    git checkout -b feature/your-feature-name
    
  2. Make your changes with tests

  3. Run the test suite:

    python -m unittest discover tests/ -v
    
  4. Format your code:

    black src/ tests/
    
  5. Submit a pull request with:

    • Clear description of changes
    • Tests for new functionality
    • Updated documentation if needed

Areas for Contribution

  • Performance improvements: Optimize file I/O operations
  • Query capabilities: Enhanced filtering and search
  • Documentation: More examples and tutorials
  • Error handling: Better error messages and recovery
  • Concurrent access: Thread-safe operations
  • Data migration: Tools for schema evolution

Reporting Issues

When reporting bugs, please include:

  • Python version
  • Nondb version
  • Minimal reproduction case
  • Error messages and stack traces
  • Expected vs actual behavior

License

MIT License - see LICENSE file for details.

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

nondb-0.1.3.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

nondb-0.1.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file nondb-0.1.3.tar.gz.

File metadata

  • Download URL: nondb-0.1.3.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.18

File hashes

Hashes for nondb-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fb4cb059f8e8e8985154815dd280bb74ae34ac99de9419032255b6bdf8404e67
MD5 148770d2af55c369022ad10f15554e19
BLAKE2b-256 0104b40258527ad30f36345214b08ec5aa21ea7bd4827e5ce7a8c229f9200389

See more details on using hashes here.

File details

Details for the file nondb-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: nondb-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.18

File hashes

Hashes for nondb-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 70e70c36d1703ba688bb62a45de3020ff50ab2db1f06ea25058a8918a25bca44
MD5 8f81d7ef617393db1e8523cc1406914a
BLAKE2b-256 49788a5afde0bed141981755bcfea1112a31bb664f515973a74a92076c9bea9a

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