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

Uploaded Python 3

File details

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

File metadata

  • Download URL: nondb-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 e10e8201dfa6af0094844dc436ac25c687478c16c87be72de920f5c09962e637
MD5 59f932996e9059c4e1ed7765caddcc8a
BLAKE2b-256 d61279ef486ef86bda0489bef7463ca559c4ed7eabc4f880de263db569bc2ccb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nondb-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb507fff0889b137c157838a176b09814e9ae520a733ebc1670f5b1f562f95b5
MD5 1678797552df9d54835cc3dbacc7c26d
BLAKE2b-256 93b2a9d52b01cfcaf344459d2c051231eb9d55d634a5b4f60d707a109a671c2c

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