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.4.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.4-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nondb-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ed792e566fd4acfd9320275a400a34bef60b64920804b318e6b0e02792d744f7
MD5 0a40c379e9439ac65da6c3c8ca20f134
BLAKE2b-256 c14d0165e4fcc83dbc285c72f4e200b26d388c0d0ffb70770c0259b2a60e8802

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nondb-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 10e60beded5a54bba345ec89ddfaa15b92c74b3acc2e1883423e11dc1058d5ed
MD5 0d646b245546f76a31167ee0b9b0a7d3
BLAKE2b-256 5d8c42d7a244b869e8b46dc77005db9cfb6db1bf609619cfdf397f552aed193a

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